Grabing Window Handle??

Started by
1 comment, last by Sandman 19 years, 6 months ago
I would like to create a service to grab pop up windows and shut them down programatically. For instance, let's say Windows displays a warning message with an Re-try and Cancel button. I want the service to be able to click cancel as if a user were present. I was thinking of using FindWindow(NULL, NULL). I'm not sure if this is the best way because I would need to scan some description string and know it ahead of time. I don't want to close down a 3rd party app by mistake. Another problem is telling the window to close. I send a BN_CLICKED, but does not work. I suspect I need the actual handle to the control and not just the window. Any ideas? Thanks.
Advertisement
You could check out EnumWindows() and EnumChildWindows(). You'll have to sift through a lot of crap to find the windows you want, but it might do what you need.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
Quote:Original post by fathom88
I would like to create a service to grab pop up windows and shut them down programatically. For instance, let's say Windows displays a warning message with an Re-try and Cancel button. I want the service to be able to click cancel as if a user were present. I was thinking of using FindWindow(NULL, NULL). I'm not sure if this is the best way because I would need to scan some description string and know it ahead of time. I don't want to close down a 3rd party app by mistake. Another problem is telling the window to close. I send a BN_CLICKED, but does not work. I suspect I need the actual handle to the control and not just the window. Any ideas? Thanks.


You'd need to send a WM_COMMAND set up like a BN_CLICKED to the parent window, or else fake a mouse click on the button itself. You'd probably be better off using PostMessage() than SendMessage () since the window will be in a different process to your app. Remember that the id of the cancel button is usually IDCANCEL.

As for identifying which windows you want to cancel automatically, you can ensure it's a dialog window by checking the class - use GetClassName() to get the window class, and you the value you're looking for is "#32770" for dialog windows. It may also be worth looking at the options that are available, you can use EnumChildWindows() to determine what buttons and controls are on this dialog, and decide whether it's one you want to handle.

This topic is closed to new replies.

Advertisement