Solved

Closing a window from an external process

Posted on 2004-10-30
188 Views
Last Modified: 2013-11-20
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
Question by:MugWumpBW
    4 Comments
     
    LVL 48

    Assisted Solution

    by:AlexFM
    Try this:

    ::PostMessage(hWnd, WM_COMMAND, IDOK, 0);
    0
     

    Author Comment

    by:MugWumpBW
    Thanks - that worked.  For some reason neither WM_CLOSE or WM_DESTROY worked.
    0
     
    LVL 4

    Accepted Solution

    by:
    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
     
    LVL 48

    Expert Comment

    by:AlexFM
    My answer os OK (IDOK).
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: JavaScript Coding - Massive 12-Part Bundle

    Regardless of your programming skill level, you'll go from basics to advanced concepts in a vast array of JavaScript subjects including Sammy.js, Agility.js, Ember.js, Node.js, jQuery, AJAX, Extjs, AngularJS, Knockout.js, and JSON.

    Suggested Solutions

    Title # Comments Views Activity
    MFC Dialog 9 45
    Running shell command from Access 3 55
    Error on moodle after upgrade 3 83
    canBalance challenge 34 42
    This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
    Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.

    911 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now