java通过pid获取句柄? 5
1个回答
2015-05-20
展开全部
楼主,是想得到窗口的句柄吗,可以使用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;
}
参考 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;
}
追问
JNA 在研究中; 附属的代码 貌似是C/C++ 吧
追答
JNA 是需要参考WIN32 的 C语言API
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询