如果最小化,我如何还原winapi窗口? [英] How can I restore a winapi window if it's minimized?

查看:1137
本文介绍了如果最小化,我如何还原winapi窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试过许多函数,例如 ShowWindow & IsWindowVisible 至少尝试给出结果,如果窗口被最小化,更不用说恢复它。这些函数不断返回false,无论窗口是否最小化。
我也尝试使用 GetWindowPlacement SetWindowPlacement 没有成功。
我的 HWND 使用 FindWindow(TEXT(Chrome_WidgetWin_1),NULL); ,但我想测试/恢复窗口,如果它被最小化,这些过去10小时没有什么显示它。

I have tried many functions, such as ShowWindow & IsWindowVisible to at least try to give the result if the window is minimized, let alone restore it. These functions constantly return false whether the window is minimized or not. I have also tried using GetWindowPlacementwith SetWindowPlacement with no success. My HWND finds Chrome with FindWindow(TEXT("Chrome_WidgetWin_1"), NULL); which is successful, but I want to test/restore the window if it's minimized and these past 10 hours has nothing to show for it.

推荐答案

Chrome有一个具有相同名称的不可见窗口。不可见的窗口只需要跳过。

Chrome has an invisible window with the same name. The invisible window simply needs to be skipped. It wasn't much of a mystery in hindsight.

void show(HWND hwnd)
{
    //ShowWindow(hwnd, SW_NORMAL);
    //SetForegroundWindow(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;
}

我编辑了一大堆时间。之前的修改位置如下:
http://stackoverflow.com/posts/29837548/revisions

I edited this a whole bunch of time. Previous edits are here: http://stackoverflow.com/posts/29837548/revisions

这篇关于如果最小化,我如何还原winapi窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆