[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

Closing a window from an external process

I am writing a VC++ 6.0 monitor program which monitors the graphics of a third party application window.  This application periodically pops up advertising dialog boxes which mess up the graphics monitoring and I would like to automatically close those dialogs.  I can enumerate the windows on the screen and get the handle to the dialog window, but when I send a WM_CLOSE message to that window nothing happens.  Is there another message or window method I could use to cause the dialog to go away?

If I can't close this window directly, then I have thought I could get the window handle for the OK button and send that button a mouse click event to simulate the user closing the dialog manually.

Any suggestions would be appreciated.
  • 2
2 Solutions
Try this:

::PostMessage(hWnd, WM_COMMAND, IDOK, 0);
MugWumpBWAuthor Commented:
Thanks - that worked.  For some reason neither WM_CLOSE or WM_DESTROY worked.
IDOK isn't the safest way to do this, as a lot of windows applications do not include a handler for IDOK. It is a safer bet to send a system message to close the window:

::PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE);

This is equal to clicking the "X" (Close symbol) for a window.
My answer os OK (IDOK).

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now