我正在编写一个程序,需要记录哪个程序处于活动状态,以及如果它是浏览器,它正在访问哪个网站。我有代码可以获取IE中地址栏窗口的内容,但是当我在chrome上使用winspy时,它会全部回来作为一个窗口。有没有人知道是否有办法刮掉地址栏的内容?
我为IE工作的代码是:
HWND foreground = GetForegroundWindow();
HWND hwndEdit = FindWindowEx(foreground, NULL, "EDIT", NULL);
HWND handle = FindWindowEx(foreground, NULL, "WorkerW", "Navigation Bar");
if (NULL != handle)
{
handle = FindWindowEx(handle, NULL, "ReBarWindow32", NULL);
if (NULL != handle)
{
handle = FindWindowEx(handle, NULL, "Address Band Root", NULL);
}}
HWND hwndEdit = FindWindowEx(handle, NULL, "Edit", NULL);
const int bufferSize = 5024;
Char textBuffer[bufferSize] = "";
SendMessage(hwndEdit, WM_GETTEXT, (WPARAM)bufferSize, (LPARAM)textBuffer);
string addressbartext = textBuffer;
if(addressbartext == "AutoCompleteProxy")
{addressbartext = "";}
else
{addressbartext = textBuffer;
}
cout << addressbartext;