VB6之切换桌面

Desktop的API,用于切换或者系统桌面环境。扩展起来可以做一个锁屏程序或者多桌面程序。

模块部分:

  1 ‘desktop.bas
  2 ‘too much struct and declare unused, shame~
  3 Public Declare Function GetThreadDesktop Lib "user32" (ByVal dwThread As Long) As Long
  4 Public Declare Function CreateDesktop Lib "user32" Alias "CreateDesktopA" (ByVal lpszDesktop As String, _
  5     ByVal lpszDevice As String, _
  6     pDevmode As Long, _
  7     ByVal dwFlags As Long, _
  8     ByVal dwDesiredAccess As Long, _
  9     lpsa As Long) As Long
 10 Public Declare Function SwitchDesktop Lib "user32" (ByVal hDesktop As Long) As Long
 11 Public Declare Function SetThreadDesktop Lib "user32" (ByVal hDesktop As Long) As Long
 12 Public Declare Function CloseDesktop Lib "user32" (ByVal hDesktop As Long) As Long
 13 Public Declare Function OpenDesktop Lib "user32" Alias "OpenDesktopA" (ByVal lpszDesktop As String, _
 14     ByVal dwFlags As Long, _
 15     ByVal fInherit As Boolean, _
 16     ByVal dwDesiredAccess As Long) As Long
 17 Public Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, _
 18     ByVal id As Long, _
 19     ByVal fsModifiers As Long, _
 20     ByVal vk As Long) As Long
 21 Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, _
 22     ByVal nIndex As Long, _
 23     ByVal dwNewLong As Long) As Long
 24 Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, _
 25     ByVal nIndex As Long) As Long
 26 Public Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, _
 27     ByVal lpCommandLine As String, _
 28     lpProcessAttributes As Long, _
 29     lpThreadAttributes As Long, _
 30     ByVal bInheritHandles As Long, _
 31     ByVal dwCreationFlags As Long, _
 32     lpEnvironment As Any, _
 33     ByVal lpCurrentDriectory As String, _
 34     lpStartupInfo As STARTUPINFO, _
 35     lpProcessInformation As PROCESS_INFORMATION) As Long
 36 Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
 37     ByVal hwnd As Long, _
 38     ByVal Msg As Long, _
 39     ByVal wparam As Long, _
 40     ByVal lparam As Long) As Long
 41
 42 Public Const CCHDEVICENAME = 32
 43 Public Const CCHFORMNAME = 32
 44 Public Const MOD_CONTROL = &H2
 45 Public Const WM_HOTKEY = &H312
 46 Public Const GWL_WNDPROC = -4
 47
 48 Public Type STARTUPINFO
 49        cb As Long
 50       lpReserved As String
 51       lpDesktop As String
 52       lpTitle As String
 53       dwX As Long
 54       dwY As Long
 55       dwXSize As Long
 56       dwYSize As Long
 57       dwXCountChars As Long
 58       dwYCountChars As Long
 59       dwFillAttribute As Long
 60       dwFlags As Long
 61       wShowWindow As Integer
 62       cbReserved2 As Integer
 63       lpReserved2 As Long
 64       hStdInput As Long
 65       hStdOutput As Long
 66       hStdError As Long
 67 End Type
 68
 69 Public Type PROCESS_INFORMATION
 70        hProcess As Long
 71       hThread As Long
 72       dwProcessId As Long
 73       dwThreadId As Long
 74 End Type
 75
 76
 77 Public Type DEVMODE
 78        dmDeviceName As String * CCHDEVICENAME
 79        dmSpecVersion As Integer
 80       dmDriverVersion As Integer
 81       dmSize As Integer
 82       dmDriverExtra As Integer
 83       dmFields As Long
 84       dmOrientation As Integer
 85       dmPaperSize As Integer
 86       dmPaperLength As Integer
 87       dmPaperWidth As Integer
 88       dmScale As Integer
 89       dmCopies As Integer
 90       dmDefaultSource As Integer
 91       dmPrintQuality As Integer
 92       dmColor As Integer
 93       dmDuplex As Integer
 94       dmYResolution As Integer
 95       dmTTOption As Integer
 96       dmCollate As Integer
 97       dmFormName As String * CCHFORMNAME
 98        dmUnusedPadding As Integer
 99       dmBitsPerPel As Long
100       dmPelsWidth As Long
101       dmPelsHeight As Long
102       dmDisplayFlags As Long
103       dmDisplayFrequency As Long
104 End Type
105
106 Public Type SECURITY_ATTRIBUTES
107        nLength As Long
108       lpSecurityDescriptor As Long
109       bInheritHandle As Long
110 End Type
111
112 Public Const GENERIC_ALL = &H10000000
113 Public Const MAXIMUM_ALLOWED = &H2000000
114 Public Const DESKTOP_SWITCHDESKTOP = &H100
115 Public Const DESKTOP_CREATEMENU = &H4&
116 Public Const DESKTOP_CREATEWINDOW = &H2&
117 Public Const DESKTOP_ENUMERATE = &H40&
118 Public Const DESKTOP_HOOKCONTROL = &H8&
119 Public Const DESKTOP_JOURNALPLAYBACK = &H20&
120 Public Const DESKTOP_JOURNALRECORD = &H10&
121 Public Const DESKTOP_READOBJECTS = &H1&
122 Public Const DESKTOP_WRITEOBJECTS = &H80&
123 Public Const DESKTOP_ALL = 511
124
125 Public HotKeyID1 As Long
126 Public HotKeyID2 As Long
127 Public hwndOldDesktop As Long
128 Public hwndNewDesktop As Long
129 Public NEW_DESKTOP_NAME As String
130 Public OldWndProc As Long
131
132 Public Function CallBackWndProc(ByVal hwnd As Long, _
133     ByVal wMsg As Long, _
134     ByVal wparam As Long, _
135     ByVal lparam As Long) As Long
136
137     If wMsg = WM_HOTKEY Then
138         If wparam = HotKeyID1 And hwndNewDesktop Then
139             ‘Ctrl+W, switch it to new
140             Call SwitchDesktop(hwndNewDesktop)
141             Debug.Print "i am new desktop, u c?"
142         ElseIf wparam = HotKeyID2 Then
143             ‘Ctrl+Q, switch it to old
144             Call SwitchDesktop(hwndOldDesktop)
145             Debug.Print "i am back to old desktop, yeah!"
146         End If
147     End If
148
149     CallBackWndProc = CallWindowProc(OldWndProc, hwnd, wMsg, wparam, lparam)
150 End Function

窗体部分:

 1 ‘code by lichmama from cnblogs.com
 2 Private Sub Form_Load()
 3     HotKeyID1 = 101&
 4     HotKeyID2 = 102&
 5
 6     hwndOldDesktop = GetThreadDesktop(App.ThreadID)
 7     NEW_DESKTOP_NAME = "myNewDesktop-VB6.0"  8     Call RegisterHotKey(Me.hwnd, HotKeyID1, MOD_CONTROL, vbKeyW)
 9     Call RegisterHotKey(Me.hwnd, HotKeyID2, MOD_CONTROL, vbKeyQ)
10     hwndNewDesktop = OpenDesktop(NEW_DESKTOP_NAME, 0&, False, DESKTOP_ALL)
11     If hwndNewDesktoop = 0 Then
12         ‘如果新桌面不存在,则创建一个
13         hwndNewDesktop = CreateDesktop(NEW_DESKTOP_NAME, vbNullString, ByVal 0&, 0&, MAXIMUM_ALLOWED, ByVal 0&)
14     End If
15     If hwndNewDesktop = 0 Then
16         Debug.Print "new desktop create failed"
17     End If
18     OldWndProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
19     Call SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf CallBackWndProc)
20 End Sub

VB6之切换桌面

时间: 2024-10-07 23:45:29

VB6之切换桌面的相关文章

win10系统下自由切换桌面

说明: win10系统下自由切换桌面,确认在win10系统下操作进行. 方法: 1.快捷键:ctrl+win键(开始键)+方向键(左/右) 2.桌面最下面的状态栏,点击红框 原文地址:https://www.cnblogs.com/mengjinxiang/p/12256700.html

CentOS切换桌面模式和命令行模式

CentOS系统中命令行模式的快捷键是[Ctrl]+[Alt]+[F1]~[F6],桌面模式的快捷键为[Ctrl]+[Alt]+[F7] 转自: http://blog.sciencenet.cn/blog-442719-737532.html

信息化教育为何需要智能桌面虚拟化?

信息化教育为何需要智能桌面虚拟化? ·        论桌面虚拟化的必要性 随着IT服务业的逐渐完善,IT服务已经进入到社会的各行各业.不仅仅是电信.银行.保险和证券等行业,教育机构也急需一套成熟的IT服务来支撑.随着信息化建设的不断深入,IT服务带来了巨大的信息化教育改革,无论是高等学校还是中小学都部署了各式各样的学生自主实验室.图书馆.多媒体教室.公共机房.教学机房等.正是这些完善的硬件设施,使得教育机构的教学.科研.管理.技术服务以及生活服务质量大大提升,学生们能够有更加丰富的信息化体验与

追影windows7 虚拟4桌面

名称 在用了windows10之后 ,发现多桌面真的让自己的工作环境干净了很多.而且使用起来也很有效率,只是windows 7还不支持这种功能.于是在网上一翻冲浪,找到了一款软件,叫追影桌面.它成了我的神器. 介绍 这个桌面分配了4个桌面给用户,使用Ctrl+ up Ctrl+down Ctrl+left Ctrl+right来切换桌面,快捷键不能修改,但是这个快捷键也很好用的.Ctrl+L打开软件配置界面,可以设置默认桌面.每一个桌面打开的应用,它的图标不会在其他桌面和系统栏显示,你的老板甚至

win10虚拟桌面使用方法-提高工作效率

任务栏右键 => 显示任务视图按钮 然后坐下角出现的任务视图按钮可以添加虚拟桌面 快捷键: win + ctrl + 左/右 切换桌面 win + tab 打开任务视图 win + ctrl + d 创建新桌面 win + ctrl + f4 删除当前桌面 原文地址:https://www.cnblogs.com/yummylucky/p/10594276.html

Linux -- Ubuntu 命令

一.文件目录类 1.建立目录:mkdir 目录名 2.删除空目录:rmdir 目录名 3.无条件删除子目录: rm -rf 目录名 4.改变当前目录:cd 目录名 (进入用户home目录:cd ~:进入上一级目录:cd -) 5.查看自己所在目录:pwd 6.查看当前目录大小:du 7.显示目录文件列表:ls -l (-a:增加显示隐含目录) 其中:蓝:目录:绿:可执行文件:红:压缩文件:浅蓝:链接文件:灰:其他文件:红底白字:错误的链接文件 8.浏览文件:more 文件名.txt:less 文

【转】《windows核心编程》读书笔记

这篇笔记是我在读<Windows核心编程>第5版时做的记录和总结(部分章节是第4版的书),没有摘抄原句,包含了很多我个人的思考和对实现的推断,因此不少条款和Windows实际机制可能有出入,但应该是合理的.开头几章由于我追求简洁,往往是很多单独的字句,后面的内容更为连贯. 海量细节. 第1章    错误处理 1.         GetLastError返回的是最后的错误码,即更早的错误码可能被覆盖. 2.         GetLastError可能用于描述成功的原因(CreatEvent)

linux技能点

linux技能点:系统管理,网络管理,文件操作,用户管理,文件权限,软件管理,其他命令. 系统管理(运行状态,开关机,目录) 运行状态:0 halt 关机 1 single user mode   单用户 2 multuser   无网的多用户 3 full  能上网的多用户 4 unused  未用的 5 xll 桌面环境 6 reboot 重启 id:3:initdefault            意思是3的运行状态,改变数值可以改变运行状态,0和6不能用. 开关机: 关机   重启 关机

windows系统中常用的快捷键

开发中,一些常用的键盘技巧: (1)快速切换桌面(alt+tab)或者是(window+tab) (2)迅速关闭当前页面 (3)迅速收起所有页面 (4)直接回到桌面页面 (5)锁定你的屏幕