检查访问了哪个网站

检查访问了哪个网站

本文介绍了检查访问了哪个网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一种方法来检查程序的用户是否正在访问特定网站。如果我想打开一个弹出框告诉我我目前在哪个网站,最好的方法是什么?



我一直在想各种方式,但我永远不能得出一个明确的结论。思考通过浏览进程或检查窗口来检查哪些浏览器是打开的,但我该如何找到它?即使我没有找到确切的网站地址,但只是名称,会很好。



例如,现在窗口打开说检查哪个网站访问 - Stack Overflow - Mozilla Firefox',有没有办法从编程的角度来看?像某种方式检查和阅读什么窗口当前打开。



感谢您的帮助。

解决方案

活动窗口使用以下代码:

  HWND hwnd = GetForegroundWindow 
CString title;
LPTSTR str = title.GetBufferSetLength(GetWindowTextLength(hwnd));
GetWindowText(hwnd,str,title.GetLength()+ 1);
if(title.IsEmpty())title = _T(User Desktop);
...

活动窗口位于title

要获取正在运行的应用程序,请使用以下代码:

  DWORD pid; 
GetWindowThreadProcessId(GetForegroundWindow(),& pid);
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION,FALSE,pid);
if(hProcess!= NULL)
{
TCHAR路径[MAX_PATH] = {0};
TCHAR filename [MAX_PATH] = {0};
GetProcessImageFileName(hProcess,path,MAX_PATH);
_wsplitpath(path,NULL,NULL,filename,NULL);
CloseHandle(hProcess);
...

文件名将保存活动应用程序


I've been having trouble finding a way to check if the user of the program is visiting a specific website. If I wanted to open a pop up box telling me which website I was currently on, what would be the best way to do it?

I've been thinking about various ways but I can never come to a definite conclusion. Thought about checking which browser is open by browsing the processes or checking the window, but how would I find it out? Even if I didn't find out exact website address but just the name, would be fine.

For example, right now the window open says 'Check Which Website is Visited - Stack Overflow - Mozilla Firefox', is there a way to get that from a programming standpoint? Like somehow check and read what windows are currently open.

Thanks for any help.

解决方案

To get the title of the active window use this code:

HWND hwnd = GetForegroundWindow();
CString title;
LPTSTR str = title.GetBufferSetLength(GetWindowTextLength(hwnd));
GetWindowText(hwnd, str, title.GetLength() + 1);
if (title.IsEmpty())title = _T("User Desktop");
...

The active window will be under "title".

To get the active running application use this code:

    DWORD pid;
    GetWindowThreadProcessId(GetForegroundWindow(), &pid);
    HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);
if (hProcess != NULL)
{
    TCHAR path[MAX_PATH] = { 0 };
    TCHAR filename[MAX_PATH] = { 0 };
    GetProcessImageFileName(hProcess, path, MAX_PATH);
    _wsplitpath(path, NULL, NULL, filename, NULL);
    CloseHandle(hProcess);
...

filename will hold the active application

这篇关于检查访问了哪个网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 01:40