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()
.
精彩评论