Windows多桌面切换(CreateDesktop,SwitchDesktop函数)
unit Unit1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls, Buttons, ExtCtrls,
TrayIconForm, AppEvnts; type
TShareInfo = record
Actived : array [ .. ] of boolean;
end;
PShareInfo = ^TShareInfo; TForm1 = class(TForm)
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N11: TMenuItem;
N21: TMenuItem;
N31: TMenuItem;
N41: TMenuItem;
BitBtn2: TBitBtn;
Panel1: TPanel;
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Label3: TLabel;
Label4: TLabel;
N4: TMenuItem;
PopupMenu1: TPopupMenu;
ApplicationEvents1: TApplicationEvents;
procedure N3Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure N4Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ApplicationEvents1Minimize(Sender: TObject);
procedure N11Click(Sender: TObject);
procedure TrayIcon1DblClick(Sender: TObject);
private
{ Private declarations }
RunningOnDesktop: integer;
Failed : boolean;
procedure OnHotKey(var Msg: TMessage); message WM_HOTKEY;
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm}
{$R UAC.res} procedure SwitchToDesktop(number: integer);
var name: string;
DsktpHandle: HDESK;
SysPath: array[..MAX_PATH] of char;
PPath: PChar;
StrPath: string;
len: integer;
si: STARTUPINFO;
pi: PROCESS_INFORMATION;
begin
if number = then
name := 'Default'
else
name := 'NewDesktop' + inttostr(number); ZeroMemory(@si, sizeof(STARTUPINFO));
si.cb := sizeof(STARTUPINFO);
si.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
si.wShowWindow := SW_SHOW;
si.lpDesktop := PChar(Name); DsktpHandle := OpenDesktop(pchar(Name),
DF_ALLOWOTHERACCOUNTHOOK, true,
DESKTOP_CREATEMENU or DESKTOP_CREATEWINDOW or
DESKTOP_ENUMERATE or DESKTOP_HOOKCONTROL or
DESKTOP_JOURNALPLAYBACK or
DESKTOP_JOURNALRECORD or DESKTOP_READOBJECTS or
DESKTOP_SWITCHDESKTOP or DESKTOP_WRITEOBJECTS);
if DsktpHandle = then
begin
// 桌面不存在,创建桌面
DsktpHandle := CreateDesktop(PChar(Name), nil, nil,
DF_ALLOWOTHERACCOUNTHOOK,
DESKTOP_CREATEMENU or DESKTOP_CREATEWINDOW or
DESKTOP_ENUMERATE or DESKTOP_HOOKCONTROL or
DESKTOP_JOURNALPLAYBACK or
DESKTOP_JOURNALRECORD or DESKTOP_READOBJECTS or
DESKTOP_SWITCHDESKTOP or DESKTOP_WRITEOBJECTS,
nil);
if DsktpHandle = then
begin
ShowMessage('打开桌面失败! ' + SysErrorMessage(GetLastError));
exit;
end; PPath := @SysPath;
len := GetWindowsDirectory(@SysPath, MAX_PATH);
SetString(StrPath, PPath, len);
if (not CreateProcess(PChar(StrPath + '/explorer.exe'), nil, nil, nil, True, , nil, nil, si, pi)) then
begin
ShowMessage('进程创建失败! ' + SysErrorMessage(GetLastError));
CloseDeskTop(DsktpHandle);
exit;
end; end; SwitchDesktop(DsktpHandle);
end; procedure TForm1.N3Click(Sender: TObject);
begin
Close;
end; procedure TForm1.N11Click(Sender: TObject);
begin
if Sender is TMenuItem then
SwitchToDesktop((Sender as TMenuItem).Tag);
end; procedure TForm1.N2Click(Sender: TObject);
begin
Show;
end; procedure TForm1.ApplicationEvents1Minimize(Sender: TObject);
begin
Hide;
end; procedure TForm1.BitBtn2Click(Sender: TObject);
begin
Hide;
end; procedure TForm1.N4Click(Sender: TObject);
begin
TrayForm.Show;
end; procedure TForm1.OnHotKey(var Msg: TMessage);
begin
if Msg.WParam > then
if Msg.WParam <= then
SwitchToDesktop(Msg.WParam); //if Msg.WParam=5 then
// TrayIcon1.Visible := not TrayIcon1.Visible;
end; procedure TForm1.TrayIcon1DblClick(Sender: TObject);
begin
Show;
end; procedure TForm1.FormCreate(Sender: TObject);
begin
RegisterHotKey(Handle, , MOD_CONTROL, VK_F1);
RegisterHotKey(Handle, , MOD_CONTROL, VK_F2);
RegisterHotKey(Handle, , MOD_CONTROL, VK_F3);
RegisterHotKey(Handle, , MOD_CONTROL, VK_F4);
RegisterHotKey(Handle, , MOD_CONTROL, VK_F5);
end; end.
参考:http://www.cnblogs.com/key-ok/p/3417735.html
Windows多桌面切换(CreateDesktop,SwitchDesktop函数)的更多相关文章
- [No0000C7]windows 10桌面切换快捷键,win10
windows 10桌面切换快捷键:Ctrl+Win+←/→ 切换窗口:Alt+Tab(不是新的,但任务切换界面改进)任务视图:Win+Tab(松开键盘界面不会消失)创建新的虚拟桌面:Win+Ctrl ...
- Windows 10 虚拟桌面切换
从Windows 10开始,终于有了和Mac一样的虚拟桌面了.但总感觉用着非常的别扭.在Mac中,切换虚拟桌面的操作可谓方便至极:除了触控板和Magic Mouse原生的支持外,通过罗技M557/55 ...
- Windows虚拟桌面
PROCESS_INFORMATION ProcessInfo; STARTUPINFO StartupInfo; HDESK hDesktop; HDESK hOriginalThread; HDE ...
- windows之桌面程序引导功能
经常使用windows系统的同学可能都会遇到这样一种情况,刚按照完的应用程序,可能会在桌面产生一个提示信息,指示当前快捷方式可以使用了,并给出相应的文字说明,指示该快捷方式的功能.那么大家有没有考虑过 ...
- Windows远程桌面,连接被拒绝,因为没有授权此用户帐户进行远程登录。
Windows 服务器远程连接的时候,出现错误:“连接被拒绝,因为没有授权此用户帐户进行远程登录.”,导致无法远程登录服务器,如下图所示: 问题分析 该错误一般是由于 Windows 远程桌面相关权限 ...
- linux下使用FreeRDP 连接 Windows 远程桌面
linux下使用FreeRDP 连接 Windows 远程桌面 简介 FreeRDP 是一款开源的远程桌面系统,支持多种平台, 在 ubuntu 中使用 FreeRDP 可以很方便的登录到 win ...
- Windows 7桌面显示图标窗口句柄的获取
在windows XP时代,我们获取桌面图标窗口的句柄往往用一下语句: HWND hwndParent = ::FindWindow( "Progman", "Progr ...
- Linux下通过rdesktop连接Windows远程桌面
rdesktop是linux下支持Windows远程桌面连接的客户端程序,在linux系统下可通过它远程访问Windows桌面,支持多种版本.rdesktop是sourceforge下支持GPL协议的 ...
- 基于Tcp穿越的Windows远程桌面(远程桌面管理工具)
基于Tcp穿越的Windows远程桌面(远程桌面管理工具) 1.<C# WinForm 跨线程访问控件(实用简洁写法)> 2.<基于.NET环境,C#语言 实现 ...
随机推荐
- display_errors & error_reporting(php调试安全)
这两个选项对应的值即都可以在php.ini文件中设置,也都可以在php代码中使用相应的函数来设置. 在php.ini文件中的设置如下:
- NDK开发之获得域和方法描述符
在NDK开发之调用方法和NDK开发之访问域两篇博客中,我们在获得域ID和方法ID时都需要一个叫做描述符的参数,那么在实际开发中我们怎么知道我们要调用的域或者方法的描述符呢? 一个简单的方法就是使用Ja ...
- 关于js中return false、event.preventDefault()和event.stopPropagation()
在平时项目中,如果遇到需要阻止浏览器默认行为,大家经常会用return false;和event.preventDefault()来阻止,但对它俩的区别还是有些一知半解,于是看了文档,查了些资料,在此 ...
- JDK7 HashMap源码分析
本文基于JDK1.7.0_79的版本进行分析. 注释比较详细. 若有不明白的地方可以指出, 我再进行细化. public class HashMap<K,V> extends Abstra ...
- centos7安装chrome的历程(fedora同)
安装 首先是下载,地址奉上:http://www.google.cn/chrome/browser/desktop/index.html,选择64 bit .rpm (适用于 Fedora/openS ...
- oracle如何获取上个月的月份
--转载 这个要用到add_months()函数 参数 负数 代表 往前 正数 代表 往后.select to_char(add_months(trunc(sysdate),-1),'yyyymm ...
- 在sql2008的实例 中 编写存储过程 读取 版本为sql2005 的实例 中的某个数据库里的数据
--创建链接服务器 exec sp_addlinkedserver 'ITSV ', ' ', 'SQLOLEDB ', '远程服务器名或ip地址 ' exec sp_addlinkedsrvl ...
- python基础(目录)
1.数据库操作入门 2.网络编程入门 3.编码规范 4.测试
- CSS 背景
CSS 背景属性用于定义HTML元素的背景. CSS 属性定义背影效果: background-color background-image background-repeat background- ...
- ios专题 - 单例模式的实现
[原创]http://www.cnblogs.com/luoguoqiang1985 单例模式是什么? 一个类只有一个实例. ----------------------- 这样做有什么好处? 在我的 ...