|
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT ("SunBear") ; MSG msg ; SetStartup(hInstance); hVirtualDesk = CreateDesktop( "Virtual", NULL, NULL, DF_ALLOWOTHERACCOUNTHOOK, GENERIC_ALL, NULL); hCurrent = GetThreadDesktop(GetCurrentThreadId()); MyRegisterClass(hInstance); if (!InitInstance (hInstance, iCmdShow)) { return FALSE; } StartExplorer(); //启动Explorer进程 if(!RegisterHotKey(hwnd, 0x0001,MOD_ALT ,'Q')) { //处理切换虚拟桌面 return TRUE; } if(!RegisterHotKey(hwnd, 0x0002, 0,VK_F8)) { //处理退出进程 return TRUE; } while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return 0; } LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc ; PAINTSTRUCT ps ; static HDESK hNow = hCurrent; switch (message) { case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: //在关闭虚拟桌面前要切换回当前桌面 SwitchDesktop(hCurrent); PostQuitMessage (0) ; return 0 ; case WM_HOTKEY: if(0x0001 == wParam) { if(hNow == hCurrent) { SwitchDesktop(hVirtualDesk); hNow = hVirtualDesk; } else { SwitchDesktop(hCurrent); hNow = hCurrent; } } if(0x0002 == wParam) { //用TerminateProcess终止explorer进程的时候,如果传递第二个参数为1 //那么操作系统不会在终止后自动唤醒explorer,如果为0,会重新启动 //explorer TerminateProcess(piExplor.hProcess,1); //关闭虚拟桌面 CloseDesktop(hVirtualDesk); SendMessage(hwnd,WM_CLOSE,0,0); } return 0; } return DefWindowProc (hwnd, message, wParam, lParam) ; }
共2页: 上一页 [1] 2 下一页
| |