I need to simulate a click on the OK button of a messagebox of another program. I managed to find the handle of the OK button. Next, I called SetCapture with the handle of OK button followed by sending Message WM_LBUTTONDOWN and then WM_LBUTTONUP. But the OK Button didnt click. Though I found another way for doing this, I'm curious to know why the previousone didnt work. THe new method i used is this.
I found handle of the Messagebox as well. I sent Message WM_COMMAND to the messagebox window with wParam the Control ID of the OK button. it was 2. and lParam the handle of the OK button. This worked. Please someone help.
I found handle of the Messagebox as well. I sent Message WM_COMMAND to the messagebox window with wParam the Control ID of the OK button. it was 2. and lParam the handle of the OK button. This worked. Please someone help.
Why SetCapture? Maybe that's what's messing it up. I'd say a normal SendMessage(hButton,WM_LBUTTONDOWN,0,0) followed by an SendMessage(hButton,WM_LBUTTONUP,0,0) should do. At least that's how I always did it.
Cheers,
JC
Cheers,
JC
I think you can send a BM_CLICK message to the OK button of a messagebox of another program.
I tried both of them. WM_LBUTTONDOWN followed by WM_LBUTTONUP and BM_CLICK. Both dont work. the button just doesnt get clicked! I think button of messagebox behaves differently.
Maybe you ould try the vk_return instead?
Just a wild guess.
Just a wild guess.
hey fornix,
i did exactly the same as you want to do - just to click the "ok"-button of a message-box. here's how i did it:
maybe it's just the resource-ID you reqire to send too (as usually the programs check the resource-ID of the message to determine which button has been clicked)
greets, hartyl
i did exactly the same as you want to do - just to click the "ok"-button of a message-box. here's how i did it:
//a proc for enumerating the child-windows of the message-box
BOOL CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam) {
char buffer[1024];
GetWindowText(hwnd,buffer,sizeof(buffer)); //get child-window-label
if(!strcmp(buffer,"OK")) { //is it the "OK"-button?
hwndButton=hwnd; //copy the handle
return false; //end enumeration
}
return true; //continue enumeration
}
//---------------------------
hWnd=FindWindow(NULL,"title of your messagebox"); //find the window-handle of the messagebox
EnumChildWindows(hWnd,&EnumChildProc,0); //find the handle
if(hwndButton) { //have we got the window?
dwButtonId=GetWindowLong(hwndButton,GWL_ID); //also get the resource-ID of the button
PostMessage(hWnd,WM_COMMAND,(BN_CLICKED<<16)|(dwButtonId&0xFFFF),(LPARAM)hwndButton); //simulate a click on the button
}
maybe it's just the resource-ID you reqire to send too (as usually the programs check the resource-ID of the message to determine which button has been clicked)
greets, hartyl
Thanx hartyl. THe method you told was the one i had to employ at last.