Solved

Detecting closing of a window

Posted on 2001-06-14
7
674 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
In this post we will learn different types of Android Layout and some basics of an Android App.
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 shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

759 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