How to get the notification "the window is about to be minimized"?

Is there a way to get a notification that application Main window is about 
to be minimized?
The case when this window received the WM_SYSCOMMAND with SC_MINIMIZE is 
simple -- just handle WM_SYSCOMMAND message.
But what to do when the window is minimizing through the ::ShowWindow API 
with SW_MINIMIZE / SW_SHOWMINIMIZED parameter?
Or if a user clicks the "Show Desktop" button on the Quick Launch panel of 
the Task Bar?

Thanks in advance,
Victor 


0
Victor
5/24/2007 10:15:22 AM
vc.mfc 33608 articles. 0 followers. Follow

18 Replies
795 Views

Similar Articles

[PageSpeed] 47

On Thu, 24 May 2007 12:15:22 +0200, "Victor" <no_address> wrote:

>Is there a way to get a notification that application Main window is about 
>to be minimized?

Windows sends the WM_SIZE message to the window with wParam =
SIZE_MINIMIZED.

So, in an MFC context, you may override CWnd::OnSize:

afx_msg void OnSize(
   UINT nType,
   int cx,
   int cy 
);

and check if nType == SIZE_MINIMIZED.

MrAsm
0
mrasm (715)
5/24/2007 10:33:55 AM
The issue is the "about to be..." part.  When you get a WM_SIZE message, it tells you that
the window has been minimized. If you don't want it minimized, for example, you have to do
something to counteract that.  Otherwise, just look at the OnSize handler's first
parameter.
				joe
On Thu, 24 May 2007 12:15:22 +0200, "Victor" <no_address> wrote:

>Is there a way to get a notification that application Main window is about 
>to be minimized?
>The case when this window received the WM_SYSCOMMAND with SC_MINIMIZE is 
>simple -- just handle WM_SYSCOMMAND message.
>But what to do when the window is minimizing through the ::ShowWindow API 
>with SW_MINIMIZE / SW_SHOWMINIMIZED parameter?
>Or if a user clicks the "Show Desktop" button on the Quick Launch panel of 
>the Task Bar?
>
>Thanks in advance,
>Victor 
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
5/24/2007 12:29:38 PM
No, the WM_SIZE is in many cases too late - windows has been already 
minimized!
I'd like to do same temporary savings just BEFORE windows will be minimized!

Victor

"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:i61b53pje7j759l6rilveqshfslacusgjk@4ax.com...
> The issue is the "about to be..." part.  When you get a WM_SIZE message, 
> it tells you that
> the window has been minimized. If you don't want it minimized, for 
> example, you have to do
> something to counteract that.  Otherwise, just look at the OnSize 
> handler's first
> parameter.
> joe
> On Thu, 24 May 2007 12:15:22 +0200, "Victor" <no_address> wrote:
>
>>Is there a way to get a notification that application Main window is about
>>to be minimized?
>>The case when this window received the WM_SYSCOMMAND with SC_MINIMIZE is
>>simple -- just handle WM_SYSCOMMAND message.
>>But what to do when the window is minimizing through the ::ShowWindow API
>>with SW_MINIMIZE / SW_SHOWMINIMIZED parameter?
>>Or if a user clicks the "Show Desktop" button on the Quick Launch panel of
>>the Task Bar?
>>
>>Thanks in advance,
>>Victor
>>
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm 


0
Victor
5/24/2007 3:25:34 PM
Well, the key word in the question was "ABOUT" - handling WM_SIZE is in many 
cases too late...

Victor

"MrAsm" <mrasm@usa.com> wrote in message 
news:29qa53pupgt4dkb30ohcg9lh74ucci54ht@4ax.com...
> On Thu, 24 May 2007 12:15:22 +0200, "Victor" <no_address> wrote:
>
>>Is there a way to get a notification that application Main window is about
>>to be minimized?
>
> Windows sends the WM_SIZE message to the window with wParam =
> SIZE_MINIMIZED.
>
> So, in an MFC context, you may override CWnd::OnSize:
>
> afx_msg void OnSize(
>   UINT nType,
>   int cx,
>   int cy
> );
>
> and check if nType == SIZE_MINIMIZED.
>
> MrAsm 


0
Victor
5/24/2007 3:27:25 PM
On Thu, 24 May 2007 17:25:34 +0200, "Victor" <no_address> wrote:

>No, the WM_SIZE is in many cases too late - windows has been already 
>minimized!

OK, I apologize. I missed the "about to be..." part.

What about WM_GETMINMAXINFO and WM_WINDOWPOSCHANGING ?


MrAsm
0
mrasm (715)
5/24/2007 3:48:05 PM
Yes, of course I tried both these messages, but couldn't find any obvious 
sign in the parameters of either message handler pointing to "treatening" 
MINIMIZE state of the window.

Victor.

"MrAsm" <mrasm@usa.com> wrote in message 
news:brcb53hce5s79a5gogsgq1mksmhn91hdmv@4ax.com...
> On Thu, 24 May 2007 17:25:34 +0200, "Victor" <no_address> wrote:
>
>>No, the WM_SIZE is in many cases too late - windows has been already
>>minimized!
>
> OK, I apologize. I missed the "about to be..." part.
>
> What about WM_GETMINMAXINFO and WM_WINDOWPOSCHANGING ?
>
>
> MrAsm 


0
Victor
5/24/2007 5:20:20 PM
Maybe WM_WINDOWPOSCHANGING:
http://msdn2.microsoft.com/en-us/library/ms632653.aspx

Mike

"Victor" <no_address> wrote in message
news:OD$nPfinHHA.3952@TK2MSFTNGP03.phx.gbl...
> Yes, of course I tried both these messages, but couldn't find any obvious
> sign in the parameters of either message handler pointing to "treatening"
> MINIMIZE state of the window.
>
> Victor.
>
> "MrAsm" <mrasm@usa.com> wrote in message
> news:brcb53hce5s79a5gogsgq1mksmhn91hdmv@4ax.com...
> > On Thu, 24 May 2007 17:25:34 +0200, "Victor" <no_address> wrote:
> >
> >>No, the WM_SIZE is in many cases too late - windows has been already
> >>minimized!
> >
> > OK, I apologize. I missed the "about to be..." part.
> >
> > What about WM_GETMINMAXINFO and WM_WINDOWPOSCHANGING ?
> >
> >
> > MrAsm
>
>


0
5/24/2007 6:18:18 PM
"Victor" <no_address> wrote in message 
news:OjJQyxenHHA.716@TK2MSFTNGP05.phx.gbl...
> Is there a way to get a notification that application Main window is about 
> to be minimized?

Handle WM_SHOWWINDOW?

If not, use Spy++ to spy on your window and see what messages it receives 
when it is minimized, then respond to one of those.

-- David 


0
dc2983 (3205)
5/24/2007 7:00:11 PM
What is it you need to do *before* the window is minimized that could not be done *after*
the window was minimized?  (The reason I ask this is that there are several alternative
ways to handle this, but I need to know what you are trying to accomplish)
					joe

On Thu, 24 May 2007 19:20:20 +0200, "Victor" <no_address> wrote:

>Yes, of course I tried both these messages, but couldn't find any obvious 
>sign in the parameters of either message handler pointing to "treatening" 
>MINIMIZE state of the window.
>
>Victor.
>
>"MrAsm" <mrasm@usa.com> wrote in message 
>news:brcb53hce5s79a5gogsgq1mksmhn91hdmv@4ax.com...
>> On Thu, 24 May 2007 17:25:34 +0200, "Victor" <no_address> wrote:
>>
>>>No, the WM_SIZE is in many cases too late - windows has been already
>>>minimized!
>>
>> OK, I apologize. I missed the "about to be..." part.
>>
>> What about WM_GETMINMAXINFO and WM_WINDOWPOSCHANGING ?
>>
>>
>> MrAsm 
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
5/24/2007 10:31:18 PM
Hi, Joe!

I'd like to store the positions of all currently displayed toolbars before 
application will be minimized and restore toolbars in these positions after 
restoring. Otherwise toolbar positions might be changed after restoring, for 
example, the "2-nd" toolbar been initially placed to the right side of the 
"1-st" toolbar moves after minimizing/restoring below the "1-st" toolbar.

BTW, sometimes I see the same behavior with the toolbars of my VS++ 6.0 
application! :(

Regards,
Victor

"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:nf4c53lid2h6bvq1qrltcch6ugg5a44il6@4ax.com...
> What is it you need to do *before* the window is minimized that could not 
> be done *after*
> the window was minimized?  (The reason I ask this is that there are 
> several alternative
> ways to handle this, but I need to know what you are trying to accomplish)
> joe
>
> On Thu, 24 May 2007 19:20:20 +0200, "Victor" <no_address> wrote:
>
>>Yes, of course I tried both these messages, but couldn't find any obvious
>>sign in the parameters of either message handler pointing to "treatening"
>>MINIMIZE state of the window.
>>
>>Victor.
>>
>>"MrAsm" <mrasm@usa.com> wrote in message
>>news:brcb53hce5s79a5gogsgq1mksmhn91hdmv@4ax.com...
>>> On Thu, 24 May 2007 17:25:34 +0200, "Victor" <no_address> wrote:
>>>
>>>>No, the WM_SIZE is in many cases too late - windows has been already
>>>>minimized!
>>>
>>> OK, I apologize. I missed the "about to be..." part.
>>>
>>> What about WM_GETMINMAXINFO and WM_WINDOWPOSCHANGING ?
>>>
>>>
>>> MrAsm
>>
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm 


0
Victor
5/25/2007 3:33:00 PM
 WM_SHOWWINDOW, WM_SIZING, ... do NOT work (either not sent or don*t contain 
any usefull information).

Victor

"David Ching" <dc@remove-this.dcsoft.com> wrote in message 
news:%gl5i.2439$C96.417@newssvr23.news.prodigy.net...
> "Victor" <no_address> wrote in message 
> news:OjJQyxenHHA.716@TK2MSFTNGP05.phx.gbl...
>> Is there a way to get a notification that application Main window is 
>> about to be minimized?
>
> Handle WM_SHOWWINDOW?
>
> If not, use Spy++ to spy on your window and see what messages it receives 
> when it is minimized, then respond to one of those.
>
> -- David
> 


0
Victor
5/25/2007 3:35:09 PM
But you can track the positions of the toolbars when they change.  Let the toolbars track
their own positions.

In addition, the positions of the toolbars should be retrievable even in the OnSize
handler, since their logical positions have not changed.  Did you check this?
					joe

On Fri, 25 May 2007 17:33:00 +0200, "Victor" <no_address> wrote:

>Hi, Joe!
>
>I'd like to store the positions of all currently displayed toolbars before 
>application will be minimized and restore toolbars in these positions after 
>restoring. Otherwise toolbar positions might be changed after restoring, for 
>example, the "2-nd" toolbar been initially placed to the right side of the 
>"1-st" toolbar moves after minimizing/restoring below the "1-st" toolbar.
>
>BTW, sometimes I see the same behavior with the toolbars of my VS++ 6.0 
>application! :(
>
>Regards,
>Victor
>
>"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
>news:nf4c53lid2h6bvq1qrltcch6ugg5a44il6@4ax.com...
>> What is it you need to do *before* the window is minimized that could not 
>> be done *after*
>> the window was minimized?  (The reason I ask this is that there are 
>> several alternative
>> ways to handle this, but I need to know what you are trying to accomplish)
>> joe
>>
>> On Thu, 24 May 2007 19:20:20 +0200, "Victor" <no_address> wrote:
>>
>>>Yes, of course I tried both these messages, but couldn't find any obvious
>>>sign in the parameters of either message handler pointing to "treatening"
>>>MINIMIZE state of the window.
>>>
>>>Victor.
>>>
>>>"MrAsm" <mrasm@usa.com> wrote in message
>>>news:brcb53hce5s79a5gogsgq1mksmhn91hdmv@4ax.com...
>>>> On Thu, 24 May 2007 17:25:34 +0200, "Victor" <no_address> wrote:
>>>>
>>>>>No, the WM_SIZE is in many cases too late - windows has been already
>>>>>minimized!
>>>>
>>>> OK, I apologize. I missed the "about to be..." part.
>>>>
>>>> What about WM_GETMINMAXINFO and WM_WINDOWPOSCHANGING ?
>>>>
>>>>
>>>> MrAsm
>>>
>> Joseph M. Newcomer [MVP]
>> email: newcomer@flounder.com
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm 
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
5/25/2007 3:45:20 PM
"Victor" <no_address> wrote in message 
news:OUK5JJunHHA.716@TK2MSFTNGP05.phx.gbl...
> WM_SHOWWINDOW, WM_SIZING, ... do NOT work (either not sent or don*t 
> contain any usefull information).
>

WM_SHOWWINDOW is definitely sent and tells you whether your window is being 
minimized!  Isn't that what you asked for?

-- David 


0
dc2983 (3205)
5/25/2007 5:14:13 PM
No, it is not! (at least, for CMDIFrameWnd derived class window)

Victor

"David Ching" <dc@remove-this.dcsoft.com> wrote in message 
news:EPE5i.4026$C96.962@newssvr23.news.prodigy.net...
> "Victor" <no_address> wrote in message 
> news:OUK5JJunHHA.716@TK2MSFTNGP05.phx.gbl...
>> WM_SHOWWINDOW, WM_SIZING, ... do NOT work (either not sent or don*t 
>> contain any usefull information).
>>
>
> WM_SHOWWINDOW is definitely sent and tells you whether your window is 
> being minimized!  Isn't that what you asked for?
>
> -- David
> 


0
5/25/2007 8:56:54 PM
Hi Joe!
See below...

"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:mt0e53ppo79584ehbl7o07ao3ppojd2s76@4ax.com...
> But you can track the positions of the toolbars when they change.  Let the 
> toolbars track
> their own positions.
**************************
Well, it seems to be a good idea. I will try it.
***************************
>
> In addition, the positions of the toolbars should be retrievable even in 
> the OnSize
> handler, since their logical positions have not changed.  Did you check 
> this?
***************************
It is too late... :(
Positions had already changed. And the result is toolbar goes "one line" 
down after window restore.

Victor


0
5/25/2007 9:04:19 PM
Are you sure it is "one line down"?  Perhaps instead it is "one caption bar down", which
means that you are geting the window coordinates but setting them as client coordinates.
				joe

On Fri, 25 May 2007 23:04:19 +0200, "Victor" <nijegorodov.otpusk@freenet.de> wrote:

>Hi Joe!
>See below...
>
>"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
>news:mt0e53ppo79584ehbl7o07ao3ppojd2s76@4ax.com...
>> But you can track the positions of the toolbars when they change.  Let the 
>> toolbars track
>> their own positions.
>**************************
>Well, it seems to be a good idea. I will try it.
>***************************
>>
>> In addition, the positions of the toolbars should be retrievable even in 
>> the OnSize
>> handler, since their logical positions have not changed.  Did you check 
>> this?
>***************************
>It is too late... :(
>Positions had already changed. And the result is toolbar goes "one line" 
>down after window restore.
>
>Victor
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
5/25/2007 10:08:30 PM
"Victor" <nijegorodov.otpusk@freenet.de> wrote in message 
news:Ouwf38wnHHA.4900@TK2MSFTNGP05.phx.gbl...
> No, it is not! (at least, for CMDIFrameWnd derived class window)
>

Yes you're right, WM_SHOWWINDOW is sent when the window is hidden with 
ShowWindow(SW_HIDE) but apparently not for ShowWindow(SW_MINIMIZE)....

-- David


0
dc2983 (3205)
5/25/2007 10:41:26 PM
:)
It is "one controlbar" down!

Victor

"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:mhne53lgdiqak1o2c0dep7cd8r4a9ups3a@4ax.com...
> Are you sure it is "one line down"?  Perhaps instead it is "one caption 
> bar down", which
> means that you are geting the window coordinates but setting them as 
> client coordinates.
> joe
>
> On Fri, 25 May 2007 23:04:19 +0200, "Victor" 
> <nijegorodov.otpusk@freenet.de> wrote:
>
>>Hi Joe!
>>See below...
>>
>>"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
>>news:mt0e53ppo79584ehbl7o07ao3ppojd2s76@4ax.com...
>>> But you can track the positions of the toolbars when they change.  Let 
>>> the
>>> toolbars track
>>> their own positions.
>>**************************
>>Well, it seems to be a good idea. I will try it.
>>***************************
>>>
>>> In addition, the positions of the toolbars should be retrievable even in
>>> the OnSize
>>> handler, since their logical positions have not changed.  Did you check
>>> this?
>>***************************
>>It is too late... :(
>>Positions had already changed. And the result is toolbar goes "one line"
>>down after window restore.
>>
>>Victor
>>
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm 


0
5/27/2007 6:29:20 PM
Reply:

Similar Artilces:

How to get the notification "the window is about to be minimized"?
Is there a way to get a notification that application Main window is about to be minimized? The case when this window received the WM_SYSCOMMAND with SC_MINIMIZE is simple -- just handle WM_SYSCOMMAND message. But what to do when the window is minimizing through the ::ShowWindow API with SW_MINIMIZE / SW_SHOWMINIMIZED parameter? Or if a user clicks the "Show Desktop" button on the Quick Launch panel of the Task Bar? Thanks in advance, Victor On Thu, 24 May 2007 12:15:22 +0200, "Victor" <no_address> wrote: >Is there a way to get a notification that applica...