Program Control desktop switch[Date: 2006-01-03] [from: resend]
Magic expression
Use the Wizard to create a Win32 program "Hello, world !", Then replace the content of the entire CPP file with the following content.
# Include "stdafx. H"
# Include "resource. H"
# Include "shellapi. H"
Hinstance hinst = NULL;
Hdesk hsf-topcurrent;
Hdesk hsf-topllx;
Long apientry wndproc (
Hwnd,
Uint message, // type of message
Wparam, // Additional information
Lparam) // Additional information
{
Int wmid, wmevent;
Paintstruct pS;
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 (hsf-topcurrent );
}
Else if (7779 = wparam)
{
Switchdesktop (hsf-topllx );
}
Break;
Case wm_quit:
Case wm_destroy:
Switchdesktop (hsf-topcurrent );
Return defwindowproc (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 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;
}
Hsf-topcurrent = NULL;
Hsf-topcurrent = getthreaddesktop (getcurrentthreadid ());
Hsf-topllx = NULL;
Hsf-topllx = opendesktop ("LLX", 0, false, null );
If (hsf-topllx! = NULL)
{
Closedesktop (hsf-topllx );
}
Security_attributes SA;
SA. binherithandle = true;
SA. nlength = sizeof (security_attributes );
SA. lpsecuritydescriptor = NULL;
Hsf-topllx = createdesktop ("LLX", null,
Null, 0, maximum_allowed,
Null );
If (hsf-topllx = NULL)
{
Return 0;
}
If (! Setthreaddesktop (hsf-topllx ))
{
Char szerror [256] = {0 };
Ltoa (long) (getlasterror (), szerror, 10 );
}
Switchdesktop (hsf-topllx );
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 or switch to another 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;
While (getmessage (& MSG, null, 0, 0 ))
{
Translatemessage (& MSG); // translates virtual key codes
Dispatchmessage (& MSG); // dispatches message to window
}
Switchdesktop (hsf-topcurrent );
Return true;
}
//:) Good stuff
Use createdesktop to create a desktop with nothing left, and then run explorer in the new desktop environment, so there is a desktop with the same functions as windows, now you have two desktops. The following is how to use switchdesktop to switch between different desktops.
Programs opened on different desktops are invisible on the taskbar of other desktops, including the system tray, but they are still visible in the task manager, which makes it very convenient to do a lot of things, many... it can also be quickly transferred to a normal state, so that people who scold you, such as the boss, can have nothing to say, because they can't see anything :)
Or you can customize a personalized desktop for your users. You can change the code above to get the desired effect.