我正在编写一个应用程序来监控PC上的应用程序使用情况。
到目前为止,我有这段代码:
do {
char blabla[200];
memset(blabla, 0, sizeof(blabla));
GetWindowText(GetForegroundWindow(), blabla, sizeof(blabla));
std::cout << "Active Window Title: " << blabla << std::endl;
Sleep(500);
} while (1);
给出如下输出:
Active Window Title: How to get the current URL from an active browser tab? - Stack Overflow - Google Chrome
Active Window Title: How to get the current URL from an active browser tab? - Stack Overflow - Google Chrome
Active Window Title: Meta Stack Overflow - Mozilla Firefox
Active Window Title: Meta Stack Overflow - Mozilla Firefox
Active Window Title: Meta Stack Overflow - Mozilla Firefox
Active Window Title: Upatras1.docx - Microsoft Word
Active Window Title: Upatras1.docx - Microsoft Word
Active Window Title: Upatras1.docx - Microsoft Word
Active Window Title: FreeCell
Active Window Title: FreeCell
Active Window Title: FreeCell
我想要实现的是以某种方式从浏览器中读取和捕获地址栏,因此输出将如下所示:
Active Window Title: How to get the current URL from an active browser tab? - Stack Overflow - Google Chrome
URL: http://stackoverflow.com/questions/ask
Active Window Title: How to get the current URL from an active browser tab? - Stack Overflow - Google Chrome
URL: http://stackoverflow.com/questions/ask
Active Window Title: Meta Stack Overflow - Mozilla Firefox
URL: http://meta.stackoverflow.com
Active Window Title: Meta Stack Overflow - Mozilla Firefox
URL: http://meta.stackoverflow.com
Active Window Title: Meta Stack Overflow - Mozilla Firefox
URL: http://meta.stackoverflow.com
Active Window Title: Upatras1.docx - Microsoft Word
Active Window Title: Upatras1.docx - Microsoft Word
Active Window Title: Upatras1.docx - Microsoft Word
Active Window Title: FreeCell
Active Window Title: FreeCell
我尝试使用SendMessage
函数来阅读第一个文本框,如下所示:
memset(blabla, 0, sizeof(blabla));
LONG lResult;
lResult = SendMessage(GetForegroundWindow(), WM_GETTEXT, sizeof(blabla) / sizeof(blabla[0]), (LPARAM)blabla);
printf( "Copied %d characters. Contents: %s\n", lResult, blabla );
...但这也只是返回窗口标题而不是地址。
有人知道从浏览器中提取此信息的方法吗?