Code:
GetWindowThreadProcessId(hWnd,&pid);
HANDLE pHandle = OpenProcess(PROCESS_ALL_ACCESS,0,pid);
Syntax Reference :
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633522(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms684320(v=vs.85).aspx/html
Example:
#include <windows.h>
int main()
{
DWORD pid;
HWND hWnd = FindWindow(NULL, "Calculator");
if(hWnd == 0)
{
MessageBox(0, "Error cannot find window.", "Error", MB_OK|MB_ICONERROR);
}
else
{
GetWindowThreadProcessId(hWnd,&pid);
HANDLE pHandle = OpenProcess(PROCESS_ALL_ACCESS,0,pid);
if(!pHandle)
{
MessageBox(0, "Could not get handle!\n", "Error", MB_OK|MB_ICONERROR);
}
else
{
//Write some code here
}
}
return 0;
}
No comments:
Post a Comment