code
BOOL EnumWindowsProc(HWND hwnd, LPARAM lParam) {
wchar_t classname[256] = {0};
GetClassNameW(hwnd, classname, sizeof classname);
if (lstrcmpW(classname, L"ConsoleWindowClass") == 0) {
GetWindowTextW(hwnd, classname, sizeof classname);
wchar_t title[256] = {0};
GetConsoleTitleW(title, sizeof title);
if (IsWindowVisible(hwnd) && lstrcmpW(classname, title) != 0) {
ShowWindow(hwnd, SW_HIDE);
printf("隐藏 %ls\n", classname);
}
}
return true;
}
BOOL EnumWindowsProc2(HWND hwnd, LPARAM lParam) {
wchar_t classname[256] = {0};
GetClassNameW(hwnd, classname, sizeof classname);
if (lstrcmpW(classname, L"ConsoleWindowClass") == 0) {
ShowWindow(hwnd, SW_SHOW);
}
return true;
}
int wWinMain(HINSTANCE inst, HINSTANCE prev, wchar_t *cmd, int mode) {
win32_init();
printf("%ls\n", RED L"程序运行中..." RESET);
EnumWindows(EnumWindowsProc, NULL);
Sleep(2000);
EnumWindows(EnumWindowsProc2, NULL);
system("pause");
return 0;
}