• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • 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.
0
MugWumpBW
Asked:
MugWumpBW
  • 2
2 Solutions
 
AlexFMCommented:
Try this:

::PostMessage(hWnd, WM_COMMAND, IDOK, 0);
0
 
MugWumpBWAuthor Commented:
Thanks - that worked.  For some reason neither WM_CLOSE or WM_DESTROY worked.
0
 
SkonenCommented:
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.
0
 
AlexFMCommented:
My answer os OK (IDOK).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

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