Solved

Detecting closing of a window

Posted on 2001-06-14
7
670 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ODBC Connection Logging, ADO.NET 6 56
java ^ examples 8 62
zeroFront challenge 7 80
Execute multiple curl cmds with sleep and send output to file 10 89
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

867 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

16 Experts available now in Live!

Get 1:1 Help Now