如果 winapi window 已最小化,我该如何恢复它?
How can I restore a winapi window if it's minimized?
我试过很多函数,比如ShowWindow
& IsWindowVisible
至少尝试给出window最小化的结果,更不用说还原了。无论 window 是否被最小化,这些函数总是 return false。
我也尝试过将 GetWindowPlacement
与 SetWindowPlacement
一起使用,但没有成功。
我的 HWND
发现 Chrome 和 FindWindow(TEXT("Chrome_WidgetWin_1"), NULL);
是成功的,但我想 test/restore window 如果它被最小化并且过去 10 小时没有任何显示它。
Chrome 有一个不可见的 window 同名。不可见的 window 只需跳过即可。
void show(HWND hwnd)
{
//We can just call ShowWindow & SetForegroundWindow to bring hwnd to front.
//But that would also take maximized window out of maximized state.
//Using GetWindowPlacement preserves maximized state
WINDOWPLACEMENT place;
memset(&place, 0, sizeof(WINDOWPLACEMENT));
place.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(hwnd, &place);
switch (place.showCmd)
{
case SW_SHOWMAXIMIZED:
ShowWindow(hwnd, SW_SHOWMAXIMIZED);
break;
case SW_SHOWMINIMIZED:
ShowWindow(hwnd, SW_RESTORE);
break;
default:
ShowWindow(hwnd, SW_NORMAL);
break;
}
SetForegroundWindow(hwnd);
}
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE, LPSTR cmdline, int nshow)
{
const wchar_t *classname = L"Chrome_WidgetWin_1";
HWND hwnd = NULL;
for (;;)
{
hwnd = FindWindowEx(0, hwnd, classname, 0);
if (!hwnd) break;
//skip Chrome's invisible winodw
if (IsWindowVisible(hwnd))
{
wchar_t buf[260];
GetWindowText(hwnd, buf, 260);
OutputDebugString(buf);
OutputDebugString(L"\n");
show(hwnd);
break;
}
}
return 0;
}
我试过很多函数,比如ShowWindow
& IsWindowVisible
至少尝试给出window最小化的结果,更不用说还原了。无论 window 是否被最小化,这些函数总是 return false。
我也尝试过将 GetWindowPlacement
与 SetWindowPlacement
一起使用,但没有成功。
我的 HWND
发现 Chrome 和 FindWindow(TEXT("Chrome_WidgetWin_1"), NULL);
是成功的,但我想 test/restore window 如果它被最小化并且过去 10 小时没有任何显示它。
Chrome 有一个不可见的 window 同名。不可见的 window 只需跳过即可。
void show(HWND hwnd)
{
//We can just call ShowWindow & SetForegroundWindow to bring hwnd to front.
//But that would also take maximized window out of maximized state.
//Using GetWindowPlacement preserves maximized state
WINDOWPLACEMENT place;
memset(&place, 0, sizeof(WINDOWPLACEMENT));
place.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(hwnd, &place);
switch (place.showCmd)
{
case SW_SHOWMAXIMIZED:
ShowWindow(hwnd, SW_SHOWMAXIMIZED);
break;
case SW_SHOWMINIMIZED:
ShowWindow(hwnd, SW_RESTORE);
break;
default:
ShowWindow(hwnd, SW_NORMAL);
break;
}
SetForegroundWindow(hwnd);
}
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE, LPSTR cmdline, int nshow)
{
const wchar_t *classname = L"Chrome_WidgetWin_1";
HWND hwnd = NULL;
for (;;)
{
hwnd = FindWindowEx(0, hwnd, classname, 0);
if (!hwnd) break;
//skip Chrome's invisible winodw
if (IsWindowVisible(hwnd))
{
wchar_t buf[260];
GetWindowText(hwnd, buf, 260);
OutputDebugString(buf);
OutputDebugString(L"\n");
show(hwnd);
break;
}
}
return 0;
}