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;
}
Technical problems and solutions face during the quest of life advancement. Hopefully, this could provide help to someone in need someday.
Thursday, June 20, 2013
C++ code reference - Find process window
Code:
HWND hWnd = FindWindow(NULL, "Calculator");
Syntax Reference : http://msdn.microsoft.com/en-us/library/aa929233.aspx
Example:
#include <windows.h>
int main()
{
HWND hWnd = FindWindow(NULL, "Calculator");
if(hWnd == 0)
{
MessageBox(0, "Error cannot find window.", "Error", MB_OK|MB_ICONERROR);
}
else
{
//Write your code to do somethings here
}
return 0;
}
HWND hWnd = FindWindow(NULL, "Calculator");
Syntax Reference : http://msdn.microsoft.com/en-us/library/aa929233.aspx
Example:
#include <windows.h>
int main()
{
HWND hWnd = FindWindow(NULL, "Calculator");
if(hWnd == 0)
{
MessageBox(0, "Error cannot find window.", "Error", MB_OK|MB_ICONERROR);
}
else
{
//Write your code to do somethings here
}
return 0;
}
Subscribe to:
Posts (Atom)