Solved

Detecting closing of a window

Posted on 2001-06-14
7
668 Views
Last Modified: 2013-11-20
Hi!

I want to get a notification when user clicks on the X box at the upper right corner of the window.  Its a non-modal dialog box and it's not destroyed when the button is clicked, just hidden.

I've tried using ON_WM_SHOWWINDOW and it doesnt seem to work.  It's not WM_CLOSE either.

Any clues?

Thanks!
0
Comment
Question by:asavard
  • 3
  • 3
7 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 6193207
You want the notification in the process that "owns" the window getting clicked or you want it in some other process?

In the first case, your window will receive the WM_SYSCOMMAND message with wParam = SC_CLOSE.  You can handle this message and do whatever you want.

In the second case, you'll need to hook the window procedure of the window you are watching to get access to it's messages.  You'll still be looking for WM_SYSCOMMAND however...
0
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6194103
You need to cathc message handler for WM_CLOSE message. That way is to catch both cases.
0
 

Author Comment

by:asavard
ID: 6195488
From what I've observed, WM_CLOSE isnt sent when you click the X in upper left corner.  It is sent when you do OnOK or OnCancel, or whatever.  But the X isnt sending the message.  I've tried WM_SYSCOMMAND with SC_CLOSE and it didnt work either.  Anyway, I've figured it out.  I had to use :

OnWindowPosChanged()

And then check for the flag SWP_HIDEWINDOW.  Seems like the only way to trap this (in my app at least).

So, how do I award points to myself :)
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 32

Accepted Solution

by:
jhance earned 50 total points
ID: 6195571
>>But the X isnt sending the message.  I've tried WM_SYSCOMMAND with SC_CLOSE and it didnt work either.  


Then you've not coded this correctly:

Add to your MESSAGE MAP:

ON_MESSAGE(WM_SYSCOMMAND, OnSysCommand)

and the handler for the message:

LRESULT CYourDialogClassDlg::OnSysCommand(WPARAM wParam, LPARAM lParam)
{
     if(wParam == SC_CLOSE){
          AfxMessageBox("X CLICKED!!", MB_OK);
     }

     return DefWindowProc(WM_SYSCOMMAND, wParam, lParam);
}


The HIDE WINDOW is NOT what you want here.  
0
 

Author Comment

by:asavard
ID: 6195729
I did what you said bro.  I even tried once more.  For some reason, it is not working.  Now i know your answer seems good, and ill accept to rate it.  But it really isnt working in the present case.  Don't ask me why.  The HIDE_WINDOW trick seems to work fine with me, why would you say it is not what I want?
0
 
LVL 32

Expert Comment

by:jhance
ID: 6195950
>>have been rewarded with a grade of C.

Excuse me for trying to HELP!

{helpful comment deleted....}

Show your code!  (Of course some other expert is going to have to comment on it since I observe a strict policy of NO MORE HELP after getting a "C" grade!!)  In other words, you're on your own on this Q.
0
 

Author Comment

by:asavard
ID: 6196161
In some ways you had a good answer, but the problem is I found a solution by myself.  That leaves me with the choice of not accepting your question at all, or accepting it despite the fact that this is not what I was looking for.  So my decision was to rate it with a lower grade to keep things on balance.

Sorry if I offend you with a lower grade.  I'm trying to put up the best of both worlds here.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 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

11 Experts available now in Live!

Get 1:1 Help Now