원하시는 답변이신지 모르겠습니다만,
FindWindow API를 사용하는 방법이 있습니다.
순서는 다음과 같습니다.
- FindWindow를 이용하여 원하는 윈도우를 찾은 다음
- FindWindowEx 를 이용하여 윈도우 안에서 버튼을 찾습니다.
- 그런 다음 SendMessage를 호출하여 해당 버튼에 클릭 이벤트를 보냅니다.
샘플 코드는 아래와 같습니다.
int hwnd=0;
IntPtr hwndChild=IntPtr.Zero;
// myapp 애플리케이션 윈도우의 핸들을 가져옵니다.
hwnd=FindWindow(null,"myapp");
if(hwnd == 0)
{
if(MessageBox.Show("Couldn't find the calculator" +
" application. Do you want to start it?",
"TestWinAPI",
MessageBoxButtons.YesNo)== DialogResult.Yes)
{
System.Diagnostics.Process.Start("Calc");
}
}
else
{
//"mybutton" 버튼의 핸들을 가져옵니다.
hwndChild = FindWindowEx((IntPtr)hwnd,IntPtr.Zero,"Button","mybutton");
//BN_CLICKED 클릭 메시지를 보냅니다.
SendMessage((int)hwndChild,BN_CLICKED,0,IntPtr.Zero);
}
댓글