请教JAVA中用JNA获得窗口句柄后,如何捕获该窗口是否弹出了窗口(类似MessageBox)

2025-01-05 17:28:23
推荐回答(1个)
回答(1):

楼主,是想得到窗口的句柄吗,可以使用JNA

参考 WIN32 API

typedef struct
{
HWND hWnd;
DWORD dwPid;
}WNDINFO;

BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
{
WNDINFO* pInfo = (WNDINFO*)lParam;
DWORD dwProcessId = 0;
GetWindowThreadProcessId(hWnd, &dwProcessId);

if(dwProcessId == pInfo->dwPid)
{
pInfo->hWnd = hWnd;
return FALSE;
}
return TRUE;
}

HWND GetHwndByProcessId(DWORD dwProcessId)
{
WNDINFO info = {0};
info.hWnd = NULL;
info.dwPid = dwProcessId;
EnumWindows(EnumWindowsProc, (LPARAM)&info);
return info.hWnd;
}