News | Articles | Libraries | Developer Tools | Books | Forum Links | Search   
Sections:
 

Smart Minimize button on Pocket PC 2002

By Vassili Philippov, May 08, 2001.
Print version

Summary

Pocket PC 2002 introduces a new feature - Smart Minimize button. This article describes working with this button - its behavior, button removing and handling.

Background

The Smart Minimize (X) button is shown by default for all windows that do not contain OK button. This button does not close the application but minimizes it (puts behind the desktop/today window). It is not recommended to remove this button or change its behavior.

There are a lot of questions (more than 100 for the last 3 months) in the developer newsgroups about Smart Minimize button. Most people ask:

  • How to handle event when the Smart Minimize button is pressed?
  • How to remove the Smart Minimize button?
  • Why the Smart Minimize button sometimes does not work for dialog-based MFC applications?

Remove the Smart Minimize button

First of all I want to say that it is not recommended to remove the Smart Minimize button except some special cases (wizards, question modal dialogs, etc). Nevertheless if you are sure what you do you can remove the Smart Minimize button by adding WS_NONAVDONEBUTTON to the window's style.

Read more detailed about how to do it in eVC++ in our QA: How to remove smart minimize (X) button from the taskbar?

Here is code for eVB that removes the Smart Minimize button (it adds WS_NONAVDONEBUTTON to the style):

Public Declare Function GetWindowLong Lib "Coredll" _ Alias "GetWindowLongW" _ (ByVal hwnd As Long, ByVal nIndex As Long) _ As Long Public Declare Function SetWindowLong Lib "Coredll" _ Alias "SetWindowLongW" _ (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) _ As Long Private Sub Form_Load() Call SetWindowLong(Me.hwnd, -16, GetWindowLong(Me.hwnd, -16) + 65536) End Sub

Handle event when the the Smart Minimize button is pressed?

As in the previous section first of all I want to say that it is not recommended to change behavior of the Smart Minimize button because users do not expect it. But in contrast to the previous question when it was unrecommended but documented this feature (handling smart minimize button) is undocumented and there is not good way to handle it.

Many Pocket PC developers were confused by What's New for Developers in the Pocket PC 2002 article (it is already removed from MSDN). It was written:

The application gets a notification when the new smart minimize is clicked. The application can then either close or just ignore the click.

It seems that he was wrong. No notification is sent when the Smart Minimize button is pressed and it is not impossible to ignore the click.

Here is the log of messages sent to the main application window when the Smart Minimize button is pressed:

Message sent when the Smart Minimize button is pressed

and the log when just another application is started:

Message sent when another application is started

As you see there is no unique message designed for Smart Minimize button. It can be possible to find a pattern of messages that are sent when the Smart Minimize button is pressed and only in that situation. But all such solutions are tricks and we cannot be 100% sure they will always work.

Here are two known tricks to handle pressing of the Smart Minimize button.

WM_WINDOWPOSCHANGED

It seems that WM_WINDOWPOSCHANGED message with the desktop window (DesktopExplorerWindow class) as a hwndInsertAfter parameter is sent only when the Smart Minimize button is pressed. So you can handle it in your WindowProc like:

case WM_WINDOWPOSCHANGED: WINDOWPOS *pWp = (LPWINDOWPOS) lParam; if (pWp->hwndInsertAfter != NULL) { TCHAR str[101]; ::GetWindowText(pWp->hwndInsertAfter, str, 100); if (wcscmp(str, _T("Desktop"))==0) { //Here we know that the Smart Minimize button is pressed //but our window is already minimized } }

Unfortunately our window is already minimized to the moment we handle this message. It is OK if we want to terminate our application but it is not acceptable if we want to ask a question. Surely we can return our window foreground using SetForeground function but it will flicker in that case.

WM_SIZE:

It seems that WM_SIZE message with SIZE_MINIMIZED parameter is sent only when the Smart Minimize button is pressed. So you can handle it in your WindowProc like:

case WM_SIZE: if (wParam==SIZE_MINIMIZED) { AfxMessageBox(_T("HBless")); }

Unfortunately this message is also sent after the window is already minimized and flickering effect seems to be even more than when handle WM_WINDOWPOSCHANGED message.

Smart Minimize sometimes does not work for dialog-based applications

Some people find that Smart Minimize button does not work for MFC dialog-based application with removed OK button. It looks like you press the Smart Minimize button, it disappears but your dialog-based application is still here.

It is a new appearance of the good know "Today" bug of MFC dialog-based applications. Your dialog is shown instead of Today window. And when your application is just over Today window and you press Smart Minimize button the Today window is shown but because of this bug you see your dialog instead of the Today window. Read how to fix it:
How to create Today-friendly dialog-based application?

Conclusion

First of all do not change default behavior if you are not sure you really need it. But it is possible to remove the Smart Minimize button from your application using WS_NONAVDONEBUTTON style. There is not special message sent to notify application that the Smart Minimize button is pressed. Nevertheless you can catch this event using some tricks.

Related resources:

Discuss

Discuss this article. Here you can write your comments and read comments of other developers.
Rate this article:     Poor Excellent    
 12345 
© 2001-2005 Pocket PC Developer Network, a division of Spb Software House