My c# test target winform only have one button , when click it , will display a messageBox . it look like this :
with code :
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("msg");
}
Now I want to use c++ and win-api to findwindows and sendmessage to above form , here is my code , first time I assume button1 in the first level child window of mainform :
#include <windows.h>
void main()
{
HWND windowHandle = FindWindowA(NULL, "Form1"); //Can’t find a proccess
if( windowHandle )
{
HWND hwndChild = FindWindowEx(windowHandle, NULL, NULL, NULL);
while ( hwndChild )
{
SendMessage(hwndChild, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(0, 0));
Sleep(100);
SendMessage(hwndChild, WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(0, 0));
hwndChild = FindWindowEx(windowHandle, hwndChild, NULL, NULL);
}
}
return;
}
but this doed not effect , the c# application 's message do not display .
then , I assume button1 is in the second level of mainform 's child form , here is the code :
#include <windows.h>
void main()
{
HWND windowHandle = FindWindowA(NULL, "Form1"); //Can’t find a proccess
if( windowHandle )
{
HWND hwndChild = FindWindowEx(windowHandle, NULL, NULL, NULL);
while ( hwndChild )
{
HWND hwndChildChild = FindWindowEx(hwndChild, NULL, L"Button", NULL);
if(hwndChildChild)
{
SendMessage(hwndChildChild, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(0, 0));
Sleep(100);
SendMessage(hwndChildChild, WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(0, 0));
break;
}
hwndChild = FindWindowEx(windowHandle, hwndChild, NULL, NULL);
}
}
return;
}
But this time also does not effect , still no messagebox display . My question is : how to determine button1 's hierachy position of mainform , from search I know someone use spy++ , how can I use spy++ to know if button1 is child window of mainform , or child window of a certain child of mainform , and so on .