#include <windows.h>
#define TIMER_ID 1
#define TIMER_INTERVAL 60000 // 1 minute in milliseconds
#define MAX_PATH 260
// 窗口过程函数
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_TIMER:
if (wParam == TIMER_ID) {
CaptureAndSaveScreenshot();
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProcW(hwnd, msg, wParam, lParam);
}
return 0;
}
// 主函数
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {
const wchar_t CLASS_NAME[] = L"HiddenWindowClass";
// 注册窗口类
WNDCLASSW wc = { 0 };
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClassW(&wc);
// 创建窗口
HWND hwnd = CreateWindowW(
CLASS_NAME, L"Hidden Window",
WS_VISIBLE, // 先创建可见窗口
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL
);
if (hwnd == NULL) {
return 0;
}
// 隐藏窗口
ShowWindow(hwnd, SW_HIDE);
// 设置定时器
SetTimer(hwnd, TIMER_ID, TIMER_INTERVAL, NULL);
// 消息循环
MSG msg = { 0 };
while (GetMessageW(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
return (int)msg.wParam;
}