桌面上莫名其妙彈出來彈窗,,光關掉可不行,,還得知道是哪個進程搞的鬼。
用C++(Windows API)寫一段小小的代碼,,獲取鼠標所在位置窗口的句柄,,進而得到對應的 PID,代碼很簡單,,就不做解釋了,。
#include <Windows.h>
#include <iostream>
#include <cstdio>
using namespace std;
POINT lastCursorPos;
POINT CursorPos;
HWND hWnd;
char line[100] = '\0';
int len = 0;
DWORD GetPIDFromCursor(POINT &CursorPos)
{
//從鼠標位置獲取當前窗體的句柄
hWnd = WindowFromPoint(CursorPos);
if (NULL == hWnd)
{
// cout << '\nNo window exists at the given point!' << endl;
return 0;
}
//獲取窗體句柄的pid
DWORD dwProcId;
GetWindowThreadProcessId(hWnd, &dwProcId);
return dwProcId;
}
bool equal(const POINT &p1, const POINT &p2)
{
if (p1.x == p2.x && p1.y == p2.y)
return true;
else
return false;
}
void ClearLine()
{
strset(line, ' ');
printf('\r%s\r', line);
}
int main()
{
bool go = true;
int pid;
while (go)
{
GetCursorPos(&CursorPos);
if (!equal(CursorPos, lastCursorPos))
{
pid = GetPIDFromCursor(CursorPos);
//動態(tài)更新一行的內容
ClearLine();
sprintf(line, 'Position=(%d, %d), PID = %d', CursorPos.x, CursorPos.y, pid);
cout << line;
lastCursorPos = CursorPos;
}
}
// CloseWindow(hWnd);
return 0;
}
編譯好運行程序。
效果如下:
|