Getting a handle to the OK button
On a standard OK MessageBox, how would you get the handle to the OK button? I need to be able to press the OK button programmaitcally (which I can do with dialogs I've made) but I need to be able to get the handle of a MessageBox button. How do I do this?
Regards,
-Tim Manchester
[email protected]
Re: Getting a handle to the OK button
Hi Tim,
I am not very clear about exactly what you want. If you could kindly be more clear I could try my level best to solve the problem
Thanks
Re: Getting a handle to the OK button
I am not quite sure what you want but here are a few attempts at solving your problem.
1. Just call your OnOK() fuction if that is where you want the code to go else
2. if you need all the CButton member functions then just add a variable to you button.
If this is not what you want then please try and explain again so I know exactly what you need to do.
Re: Getting a handle to the OK button
Well, OK buttons always have an ID of 'IDOK', at least the standard dialogs are.
So, if you have the handle to the window, you can call GetDlgItem(hWnd, IDOK) and it will return the HWND of the OK button.
-Safai
Re: Getting a handle to the OK button
Try this:
CDialog* pDlg = (CDialog*)CWnd::FindWindow("32770(Dialog)","Put the Dialog Title Text Here");
CButton* pButOK = (CButton*)pDlg->GetDlgItem(IDOK);
HWND hWnd = pButOK->m_hWnd;
Re: Getting a handle to the OK button
pWnd->GetDlgItem(IDOK);
pWnd->SendMessage(WM_LBUTTONDOWN);
Sleep(100);
pWnd->SendMessage(WM_LBUTTONUP);
That should work, of course 'pWnd' should point to the message box.
I've made a program called dismiss (http://ftp://shellreef.dynip.com/dismiss.zip) which can
automatically dismiss dialog boxes and more. You can download it from the address above
(it's on my comp and I go offline often so get it as soon as possible if you want it..)