开发者

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();
GetW开发者_StackOverflow中文版indowText(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().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜