Clicking a windowless button programatically
-
Hey everybody I have a YES/NO dialog, which the buttons are windowless controls. I want to click YES or NO buttons programmaticly. Does does anyone have any idea how to do that? btw, I don't mean sending VK_RETURN message... Thanks a lot in advance! p.s. If you want to see what I mean, open a "print" dialog in your office and use spy++ to check out the controls. You'll notice most controls don't have HWND. Thanks again! :-)
-
Hey everybody I have a YES/NO dialog, which the buttons are windowless controls. I want to click YES or NO buttons programmaticly. Does does anyone have any idea how to do that? btw, I don't mean sending VK_RETURN message... Thanks a lot in advance! p.s. If you want to see what I mean, open a "print" dialog in your office and use spy++ to check out the controls. You'll notice most controls don't have HWND. Thanks again! :-)
Hello, Use SendMessage() Win32 API. This will solve your problem. Happy Programming.
-
Hey everybody I have a YES/NO dialog, which the buttons are windowless controls. I want to click YES or NO buttons programmaticly. Does does anyone have any idea how to do that? btw, I don't mean sending VK_RETURN message... Thanks a lot in advance! p.s. If you want to see what I mean, open a "print" dialog in your office and use spy++ to check out the controls. You'll notice most controls don't have HWND. Thanks again! :-)
When you spy on a button, for instance the Print button on a print dialog, you will see a field called Window Handle. This will have a value. But when doing it programmatically, we usually use the Control ID field. Here is what you can do to send a click on a button -
PostMessage(WM_COMMAND, MAKELONG(ID_BUTTON, BN_CLICKED), reinterpret_cast<LPARAM>(GetDlgItem(ID_BUTTON)->m_hWnd));
I'm assuming ID_BUTTON to be the button id. Replace that with the actual ID of the button. I'm assuming you're using MFC.
«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
When you spy on a button, for instance the Print button on a print dialog, you will see a field called Window Handle. This will have a value. But when doing it programmatically, we usually use the Control ID field. Here is what you can do to send a click on a button -
PostMessage(WM_COMMAND, MAKELONG(ID_BUTTON, BN_CLICKED), reinterpret_cast<LPARAM>(GetDlgItem(ID_BUTTON)->m_hWnd));
I'm assuming ID_BUTTON to be the button id. Replace that with the actual ID of the button. I'm assuming you're using MFC.
«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)Hey, Thanks for you help! :-) But the thing is that the control DOES NOT have a dialog item ID. If it had a dialog item ID, than it would have an HWND (which I could get using GetDlgItem()). About the Spy, if you use Spy++ on the print dialog in office, you will see that the buttons (or the combobox) will not have an HWND at all (only the RichEditBoxes have HWNDs in that dialog).
-
Hey, Thanks for you help! :-) But the thing is that the control DOES NOT have a dialog item ID. If it had a dialog item ID, than it would have an HWND (which I could get using GetDlgItem()). About the Spy, if you use Spy++ on the print dialog in office, you will see that the buttons (or the combobox) will not have an HWND at all (only the RichEditBoxes have HWNDs in that dialog).
Try if
IDOK
works for the OK button.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
Try if
IDOK
works for the OK button.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)Doesn't work... I'll try to expand the problem even a little bit more, what if I want to know what is written inside the button, or the combobox (in the print dialog). I am not sure it is even possible...
-
Doesn't work... I'll try to expand the problem even a little bit more, what if I want to know what is written inside the button, or the combobox (in the print dialog). I am not sure it is even possible...
You can't do this. "Windowless" means it's not a windows control so it doesn't have a window handle so you can't use APIs to interact with it. It's been created by code within the application to look and function as a button but it's not a Windows button.
-
You can't do this. "Windowless" means it's not a windows control so it doesn't have a window handle so you can't use APIs to interact with it. It's been created by code within the application to look and function as a button but it's not a Windows button.
Hey, Thanks ! Yeah, I knew all that, but I was hoping someone will come up with a technique I didn't think of. :) Currently I am using the x,y of the window OR using spy++ to see if there is another message being sent because of my click (some kind of WM_COMMAND or WM_USER+k). Anyway, thanks again.