简体   繁体   中英

Unable to get Window Title using GetGUIThreadInfo

I was googling and discovered that the above function is more reliable in retrieving the Window Title Text but it does not work. I get no results; in other words no string of the title is captured.

GUITHREADINFO gui;
gui.cbSize = sizeof(gui);
char pStr[1024];

GetGUIThreadInfo pGetGUIThreadInfo;

HMODULE hinstUser = LoadLibrary((LPCTSTR) "user32.dll"); 
pGetGUIThreadInfo = (GetGUIThreadInfo)GetProcAddress(GetModuleHandle(TEXT("user32.dll")), "GetGUIThreadInfo");
if (pGetGUIThreadInfo(0 , &gui) == 0)
    return NULL;

GetWindowText(gui.hwndFocus, pStr, 1024);

But the above code fails. What does work is using the following code

HWND hwnd = GetForegroundWindow();
GetWindowText(hwnd, pStr, 1024);

I think it will do what you want if you use hwndActive rather than hwndFocus .

That said, I can't see what is wrong with using the window returned by GetForegroundWindow() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM