c++ - ShowWindow仅在最后一次最小化时才还原窗口

标签 c++ winapi findwindow showwindow

我正在尝试用C++编写一个显示最小化计算器的程序。
如果我将其最小化,它会起作用,但是如果我最小化计算器,然后再使另一个程序(如firefox)最小化,该程序将不再显示计算器。

int main()
{
    hwnd = FindWindow(NULL,TEXT("Calculator"));
    ShowWindow(hwnd, SW_SHOW);
    return 0;
}

最佳答案

如果将计算器最小化(请参阅 IsIconic() ),那么应根据 SW_RESTORE 文档,使用SW_SHOW而不是ShowWindow():

SW_RESTORE
9

Activates 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
5

Activates 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/

相关文章:

c++ - 可以将类名而不是 namespace 添加到::以进行范围解析吗?

c++ - 从 map-C++ 中检索字符串时出现逻辑错误

c++ - 为什么 MFC DoModal 返回 -1 ? -1 是什么意思?

c# - WM_KEYDOWN : how to use it?

c# - 通过 C# 调用 Win32 api 失败!

delphi - 将项目添加到另一个应用程序的模式窗口的最佳方法?

c++ - FindWindow() 通过不完整的名称

c# - 将击键从 C# 应用程序发送到 Java 应用程序 - 奇怪的行为?

java - 在 Java 和 C++ 之间交换对象/类数据

c++ - visual c++ 2010调试问题