[Gadgets] switch between desktop applets.

Source: Internet
Author: User

I have been using the gadgets I wrote a year ago and it is very convenient.
For the purpose of being simple and practical, the program does not display any interface after it is started. Instead, it creates another desktop and switches between the two desktops with WIN + 1 and WIN + 2 keys. One desktop is used for work, and one desktop is used for entertainment without interfering with each other.

Download source code and executable files: pharaohsf-top.zip

Delphi source code:


// Create a new desktop.
// By pharaoh.cnblogs.com
Program myDesktop;

Uses
Windows, Messages;
 
// {$ R *. res}
 
Const
SzAppName: PChar = 'mydesktop ';

Var
Wc: WNDCLASS; // main window class
HMainWnd: HWND; // Main Window handle
AMsg: MSG; // message in the Main Window

Hsf-topcurrent: HDESK; // current desktop
HmyDesktop: HDESK; // new desktop

Sa: TSecurityAttributes;

Function WndProc (AWnd: HWND; message: UINT; wp: WPARAM; lp: LPARAM): LRESULT; stdcall;
Begin
Result: = 0;
Case message
WM_DESTROY:
Begin
SwitchDesktop (hsf-topcurrent );
PostQuitMessage (0 );
End;
WM_HOTKEY:
If (7777 = wp) then
Begin
SwitchDesktop (hsf-topcurrent );
PostQuitMessage (0 );
End
Else if (7778 = wp) then
SwitchDesktop (hsf-topcurrent)
Else if (7779 = wp) then
SwitchDesktop (hmyDesktop );
Else
Result: = DefWindowProc (AWnd, message, wp, lp );
End;
End;

Procedure StartMyExplore;
Var
Sui: TStartupInfo;
Pi: TProcessInformation;
Begin
FillChar (sui, sizeof (TStartupInfo), #0 );
Sui. cb: = sizeof (TStartupInfo );
Sui. lpDesktop: = pchar ('pharaoh .cnblogs.com ');
CreateProcess (nil, 'explorer ', nil, nil, true, CREATE_DEFAULT_ERROR_MODE or CREATE_SEPARATE_WOW_VDM,
Nil, nil, sui, pi );

End;

 
Begin
With wc do begin
Style: = CS_VREDRAW or CS_HREDRAW;
LpfnWndProc: = @ WndProc;
CbClsExtra: = 0;
CbWndExtra: = 0;
HIcon: = LoadIcon (0, IDI_APPLICATION );
HCursor: = LoadCursor (0, IDC_ARROW );
HbrBackground: = GetSysColorBrush (COLOR_WINDOW );
HInstance: = HInstance;
LpszMenuName: = nil;
LpszClassName: = szAppName;
End;
RegisterClass (wc );

// Current desktop
Hsf-topcurrent: = GetThreadDesktop (GetCurrentThreadId ());

// Create a new desktop
HmyDesktop: = 0;
HmyDesktop: = OpenDesktop ('pharaoh .cnblogs.com ', 0, false, 0 );
If hmyDesktop <> 0 then
Begin
CloseDesktop (hmyDesktop );
End;

Sa. bInheritHandle: = true;
Sa. nLength: = sizeof (TSecurityAttributes );
Sa. lpSecurityDescriptor: = nil;

HmyDesktop: = CreateDesktop ('pharaoh .cnblogs.com ', nil, nil, 0, MAXIMUM_ALLOWED, nil );

If hmyDesktop = 0 then exit;

If not SetThreadDesktop (hmyDesktop) then
Begin

End;
SwitchDesktop (hmyDesktop );

// Create the Main Window
HMainWnd: = CreateWindow (szAppName,
SzAppName,
WS_OVERLAPPEDWINDOW,
Integer (CW_USEDEFAULT), Integer (CW_USEDEFAULT ),
Integer (CW_USEDEFAULT), Integer (CW_USEDEFAULT ),
HWND_DESKTOP, 0,
HInstance, nil );

// Register the hotkey
If (not RegisterHotKey (HMainWnd, 7777, MOD_WIN, ord ('0') then exit;
If (not RegisterHotKey (HMainWnd, 7778, MOD_WIN, ord ('1') then exit;
If (not RegisterHotKey (HMainWnd, 7779, MOD_WIN, ord ('2') then exit;
// Start caffe on the new desktop
StartMyExplore;
SwitchDesktop (hsf-topcurrent );
While GetMessage (AMsg, 0, 0, 0) do begin
TranslateMessage (AMsg );
DispatchMessage (AMsg );
End;
SwitchDesktop (hsf-topcurrent );
End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.