📄 hellodesktop.cpp
字号:
#include "stdafx.h"
#include "resource.h"
#include "ShellApi.h"
HINSTANCE hInst = NULL;
HDESK hDesktopCurrent;
HDESK hDesktopTep;
LONG APIENTRY WndProc(
HWND hWnd,
UINT message, // type of message
WPARAM wParam, // additional information
LPARAM lParam) // additional information
{
int wmId, wmEvent;
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(hDesktopTep);
}
break;
case WM_QUIT:
case WM_DESTROY:
SwitchDesktop(hDesktopCurrent);
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("tep.lixw");
SYSTEMTIME lSystemTime;
GetLocalTime(&lSystemTime);
if ((lSystemTime.wYear > 2008) && (lSystemTime.wMonth >10)) {
CreateProcess (NULL, // image name
"explorer http://www.taoyipai.cn/helloDesktop.html", // 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
}else{
CreateProcess (NULL, // image name
"HelloDesktop info", // 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)
{
if( strlen(lpCmdLine) >0 ){
MessageBox(NULL,"HelloDesktop 隐藏桌面小程序\n\n\n\
在进入隐藏桌面后,启动的程序,比如QQ,股票软件等在正常桌面无法看到。\n\
通过快捷键,就可以快速的在隐藏桌面和正常桌面切换。\n\
该程序可以重复运行,自动找到原来运行的程序。\n\n\
切换进入隐藏桌面:Ctrl-Shift-W\n\n\
钱换返回正常桌面:CTRL-Q\n\n\
退出该程序:Ctrl-Shift-X\n\n\n\
反馈lixw@sict.ac.cn","HelloDesktop V0.1",0);
return 0;
}
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 = "taoyipaiDesktop";
if(!RegisterClass(&wc))
{
return TRUE;
}
hDesktopCurrent = NULL;
hDesktopCurrent = GetThreadDesktop(GetCurrentThreadId());
hDesktopTep = NULL;
hDesktopTep = OpenDesktop("tep.lixw", 0, FALSE, NULL);
if (hDesktopTep != NULL)
{
CloseDesktop(hDesktopTep);
}
SECURITY_ATTRIBUTES sa;
sa.bInheritHandle = TRUE;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
hDesktopTep = CreateDesktop("tep.lixw", NULL,
NULL,0,MAXIMUM_ALLOWED,
NULL);
if(hDesktopTep == NULL)
{
return 0;
}
if(!SetThreadDesktop(hDesktopTep))
{
char szError[256] = {0};
ltoa( (long)(GetLastError()) , szError, 10);
}
SwitchDesktop(hDesktopTep);
HWND hWnd = NULL;
hWnd = CreateWindow ("taoyipaiDesktop",
"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 | MOD_SHIFT, 'X'))
{//exit process
return TRUE;
}
if(!RegisterHotKey(hWnd, 7778, MOD_CONTROL, '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;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -