我正在尝试用C++编写一个显示最小化计算器的程序。
如果我将其最小化,它会起作用,但是如果我最小化计算器,然后再使另一个程序(如firefox)最小化,该程序将不再显示计算器。
int main()
{
hwnd = FindWindow(NULL,TEXT("Calculator"));
ShowWindow(hwnd, SW_SHOW);
return 0;
}
最佳答案
如果将计算器最小化(请参阅 IsIconic()
),那么应根据 SW_RESTORE
文档,使用SW_SHOW
而不是ShowWindow()
:
SW_RESTORE
9Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.
SW_SHOW
5Activates the window and displays it in its current size and position.
试试这个:
int main()
{
HWND hwnd = FindWindow(NULL, TEXT("Calculator"));
if (hwnd)
{
if (IsIconic(hwnd))
ShowWindow(hwnd, SW_RESTORE);
else
ShowWindow(hwnd, SW_SHOW);
}
return 0;
}
关于c++ - ShowWindow仅在最后一次最小化时才还原窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63411450/