【问题标题】:Qt - get all opened windows titleQt - 获取所有打开的窗口标题
【发布时间】:2011-10-31 07:57:24
【问题描述】:

如何检查特定窗口是否打开。我只得到了窗口名称的一部分。我想在 QT 控制台应用程序中使用 EnumWindows() 但我收到一些错误,说明“main.obj:-1: error: unresolved external symbol imp__GetWindowTextW@12 referenced in function "int __stdcall EnumWindowsProc(struct HWND *,long)" (?EnumWindowsProc@@YGHPAUHWND__@@J@Z)"

下面是我的示例代码

BOOL CALLBACK EnumWindowsProc(HWND hWnd, long lParam) {
    char buff[255];

    if (IsWindowVisible(hWnd)) {
       GetWindowText(hWnd, (LPWSTR) buff, 254);
    }
    return TRUE;
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    EnumWindows(EnumWindowsProc, 0);

    return 0;
}

【问题讨论】:

标签: windows winapi qt


【解决方案1】:

这是一个链接器错误而不是编译错误。

您已正确包含windows.h,但您还需要将导入库添加到您的链接器选项中。您的示例代码中的所有三个 Win32 函数都要求您链接 user32.lib

【讨论】:

    【解决方案2】:

    EnumWindowsProc 不是来自 Qt,它是一个 windows API 函数,需要包含 windows.h

    我没有使用Qt,代码可以通过complie,但输出似乎不对。无论如何,这是我的代码

    #include <conio.h>
    #include <iostream>
    #include <windows.h>
    using namespace std;
    char buff[255];
    BOOL CALLBACK EnumWindowsProc(HWND hWnd, long lParam)
    {
        if (IsWindowVisible(hWnd))
        {
           GetWindowText(hWnd, (LPWSTR) buff, 254);
        }
        return TRUE;
    }
    
    
    int main()
    {
        EnumWindows(EnumWindowsProc, 0);
        for(int i = 0; i != 254; ++i)
            cout << buff[i];
        getch();
        return 0;
    }
    

    【讨论】:

    • @Lynnooi 您的代码在我的应用程序中工作...尽量不要使用 Qt,使用本机 C++ 代码。
    【解决方案3】:

    你可以使用:

    Application.OpenForms["FormName"]
    

    检查表单是否打开。

    【讨论】:

    • 我想获取所有打开的应用程序窗口,包括那些不是 QT 应用程序的窗口
    猜你喜欢
    • 2011-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-20
    • 1970-01-01
    • 2014-08-27
    • 1970-01-01
    • 2013-08-29
    相关资源
    最近更新 更多