Private Sub Command1_Click()
If g_hDesktopNew <> 0 Then
SwitchDesktop g_hDesktopNew '切换到新桌面
End If
End Sub
Private Sub Command2_Click()
StartMyExplore Text1.Text '在新桌面运行程序
End Sub
Private Sub Form_Load()
g_hDesktopThreadOld = GetThreadDesktop(App.ThreadID) '得到正常的桌面句柄
RegisterHotKey Me.hwnd, 1, MOD_CONTROL, Asc("Q") '注册热键
RegisterHotKey Me.hwnd, 2, MOD_CONTROL, Asc("W") '注册热键
g_hDesktopNameNew = "MyNewDesktop"
g_hDesktopNew = OpenDesktop(g_hDesktopNameNew, 0, False, DESKTOP_ALL) '如果新桌面已经存在,就打开它
If g_hDesktopNew = 0 Then
g_hDesktopNew = CreateDesktop(g_hDesktopNameNew, vbNullString, ByVal 0&, 0, MAXIMUM_ALLOWED, ByVal 0&) '如果不存在,就新建一个
End If
Call SetThreadDesktop(g_hDesktopNew)
lpOldWinProc = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf myWindowProc) '子类化主窗口,接收热键消息
End Sub
Private Sub Form_Unload(Cancel As Integer)
If g_hDesktopNew <> 0 Then
CloseDesktop g_hDesktopNew '关闭新建的桌面句柄
End If
SetWindowLong Me.hwnd, GWL_WNDPROC, lpOldWinProc
End Sub