Building a Win32 program "Hello, World!" With a wizard, and then replace the entire CPP file content with the following content.
#include "stdafx.h" #include "resource.h"
#include "shellapi.h"
Hinstance hinst = null;
HDESK HDESKTOPCURRENT; HDESK HDESKTOPLLX;
LONG APIENTRY WNDPROC (HWND HWND, UINT Message, // Type of Message WParam WPARAM, // Additional Information LParam Lparam) // Additional Information; PaintStruct PS; HDC HDC;
switch (message) {case WM_COMMAND: wmId = LOWORD (wParam); wmEvent = HIWORD (wParam); // Parse the menu selections: switch (wmId) {case IDM_ABOUT: // DialogBox (hInst, (LPCTSTR) IDD_ABOUTBOX, hWnd, (DLGPROC) About); break; case IDM_EXIT: DestroyWindow (hWnd); break; default: return DefWindowProc (hWnd, message, wParam, lParam);} break; case WM_PAINT: hdc = BeginPaint (hWnd, & ps); // TODO : Add any drawing code here ... Rect RT; getClientRect (hwnd, & rt); // DrawText (HDC, Szhello, Strlen (Szhello), & RT, DT_CENTER; EndPaint (HWND, & PS); Break; / * Case WM_DESTROY : PostQuitMessage (0); break; // * / case WM_LBUTTONDOWN: break; case WM_HOTKEY: if (7777 == wParam) {PostQuitMessage (0);} else if (7778 == wParam) {SwitchDesktop (hDesktopCurrent);} else IF (7779 == wparam) {switchDesktop (HDESKTOPLLX);} Break; Case Wm_quit: Case WM_DESTROY: SWITCHDESKTOP (HDESKTOPCURRENT); RETURN DEFWINDOWP Roc (hwnd, message, wparam, lparam); Default: Return DefWindowProc (HWnd, Message, WPARAM, LPARAM);} Return 0;
void StartMyExplore (void) {STARTUPINFO sui; // Process startup info PROCESS_INFORMATION pi; // info returned from CreateProcess // // Most sui members will be 0 // ZeroMemory ((PVOID) & sui, sizeof (sui)); sui. cb = sizeof (sui); // // Need the lpDesktop member so the new process runs on this desktop // The lpDesktop member was reserved in previous versions of NT // sui.lpDesktop = _T ( "llx"); CreateProcess ( NULL, // image name "explorer", // command line NULL, // process security attributes NULL, // thread security attributes TRUE, // inherit handles CREATE_DEFAULT_ERROR_MODE | CREATE_SEPARATE_WOW_VDM, NULL, // environment block NULL, // current directory & sui, // startupinfo & pi); // process_information}
int CALLBACK WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {WNDCLASS wc; wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc. hInstance = hInstance; wc.hIcon = LoadIcon (NULL, "IDI_SETTHREADDESKTOP"); wc.hCursor = LoadCursor (NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = "lilinxiang"; if (! registerclass (& wc)) {return true;}
HDesktopcurrent = null; hdesktopcurrent = getthreaddesktop (getCurrentThreadID ());
HDESKTOPLLX = NULL; HDESKTOPLLX = OpenDesktop ("LLX", 0, False, Null); if (HDesktopllx! = null) {CloseDesktop (HDESKTOPLLX);
SECURITY_ATTRIBUTES sa; sa.bInheritHandle = TRUE; sa.nLength = sizeof (SECURITY_ATTRIBUTES); sa.lpSecurityDescriptor = NULL; hDesktopLlx = CreateDesktop ( "llx", NULL, NULL, 0, MAXIMUM_ALLOWED, NULL); if (hDesktopLlx == NULL) {RETURN 0;
IF (! setthreadDesktop) {char szerror [256] = {0}; LTOA ((long), szerror, 10);} SwitchDesktop (HDESKTOPLLX);
HWND hWnd = NULL; hWnd = CreateWindow ( "lilinxiang", "! Hello, world", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (NULL == hWnd) {return TRUE; }
// register hotkey for exit this desktop // showwindow (hwnd, sw_show); // updateWindow (hwnd); if (! Registerhotkey (hwnd, 7777, mod_control, 'q')) {// EXIT Process return TRUE;} if (! RegisterHotKey (hWnd, 7778, MOD_CONTROL | MOD_SHIFT, 'Q')) {// switch to new desktop return TRUE;!} if (RegisterHotKey (hWnd, 7779, MOD_CONTROL | MOD_SHIFT, 'W') ) {// switch to Original Desktop return true;} startmyexplore ();
Msg Msg; While (GetMessage (& MSG, NULL, 0, 0)) {TranslateMessage (& MSG); // Translates Virtual Key Codes DispatchMessage (& MSG); // Dispatches Message to Window}
SwitchDesktop (HDESKTOPCurrent); Return True;
//: Good things
Create a desktop with CreateDesktop, how do you have any desktops, and then run Explorer in a new desktop environment, so you have a desktop with Windows, this time you have two desktops, what you have to do is with SwitchDesktop Switch different desktops
The program opened in different desktops includes the taskbar of other desktops including the system tray, but the task manager is still visible, you are very convenient to do a lot, a lot of ... and you can turn very quickly. To normal state, people who will blame you, such as the boss, nothing to say, because they can't see anything:) or you can customize your users to customize a personalized desktop. Changing the above code can get the effect you want.
Good things, don't help me! ! ! ! ! ! ! :)