Sign in to follow this  
fathom88

Grabing Window Handle??

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this