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#语言 实现 ...
随机推荐
- ssh 无密码登录远程服务器
在讲下文之前,我都默许大家都已经生成了自己的ssh公钥和密钥,在自己的~/.ssh 目录下面,如果没有,请使用 ssh-keygen -t rsa -C "你的邮箱" 命令生成 1 ...
- [Jquery] jQuery.cookie帮助类 (转载)
/** * Cookie plugin * * Copyright (c) [url=http://sufei.cnblogs.com/]http://sufei.cnblogs.com[/url] ...
- Android 读取txt文件并以utf-8格式转换成字符串
博客: 安卓之家 微博: 追风917 CSDN: 蒋朋的家 简书: 追风917 博客园: 追风917 # 使用EncodingUtils 今天用到了城市选择三级联动的库,用的这个:https://gi ...
- 使用graphics2D给图片上画字符
//读取图片BufferedImage frontImage = ImageIO.read(new File(eCardXMLConfigManager.geteCardXMLConfigManage ...
- 一步一步建MVC
http://www.cnblogs.com/yuangang/p/5569518.html
- JPEG 图
多媒体教程 - JPEG 图 JPEG 是在 Web 上使用的主要图像格式之一. 本文讲解 JPEG 图像的概念和特性. 理解图像格式 无论是 HTML 还是 XHTML 都没有规定图像的官方格式.然 ...
- 求最低分最高分---c#(冒泡排序的运用)
// 输入10个人的分数,去掉两个最高两个最低,求平均分 Console.Write("请输入人数:"); int renshu = int.Parse(Console.ReadL ...
- Javascript中bind()方法的使用与实现
对于bind,我愣了下,这个方法常用在jquery中,用于为被选元素添加一个或多个事件处理程序. 查了下手册,发现bind的作用和apply,call类似都是改变函数的execute context, ...
- WampServer修改MySQL密码
WampServer安装后密码是空的,需要设置一下 一般有两种方式: 一是通过phpMyAdmin直接修改: 二是使用WAMP的MySql控制台修改. 第一种: ①在phpMyAdmin界面中点击[用 ...
- 217. Contains Duplicate(C++)
217. Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your ...