Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pocket PC/Windows Mobile: How to detect smart minimize

How do I detect when my Compact Framework application is being smart-minimized (smart minimize is what happens when the user clicks the "X" button in the top-right corner on a Pocket PC)?

The Deactivate event isn't the right way because it occurs in circumstances other than minimization, such as when a message box or another form is shown on top of the main form. And the form's WindowState doesn't help because there is no "Minimized" WindowState on .NET CF.

I heard that by setting MinimizeBox = false, my app will be closed instead of minimized. But I actually don't want my app to close, I just want to know when it has been minimized.

like image 377
Qwertie Avatar asked Dec 13 '08 21:12

Qwertie


1 Answers

I think the way to go here is processing the WM_ACTIVE message and then checking if the fMinimized parameter is not zero. You can find more information on how to declare this messages in your code in here.

I will try figure out how to exactly code this in C# and prove the hypothesis. However you maybe faster than me and figure it out.

Also check the functions DefWindowProc and WindowProc, which are used to process the messages. Functions are declared in your code like this:

First have the include:

using System.Runtime.InteropServices;

then in the class declare like this

[DllImport("coredll.dll")]
static extern IntPtr DefWindowProc(IntPtr hWnd, uint uMsg, UIntPtr wParam,
   IntPtr lParam);

There is another thing you could do, this is more a "philosophical" workaround. INMO the smart minimize X is confusing for users, that is why I don't like to include it. Instead I provide a button at the right lower corner of the form that says "close" or "back", which uses the close method of the form. I used it in all forms to keep a standard. This is less ambiguous for windows users because they may assume that the X in windows mobile is the same X in windows for PC.

If for some reason you need to minimize your app or send it to the background use the following code:

using System.Runtime.InteropServices;
...

public partial class Main : Form
{
   public Main()
    {


        InitializeComponent();
    }

  [DllImport("coredll.dll")]
    static extern int ShowWindow(IntPtr hWnd, int nCmdShow);

  const int SW_MINIMIZED = 6;

  ...
  ...

   public void HideForm()
    {
        ShowWindow(this.Handle, SW_MINIMIZED);
    }
} 
like image 194
2 revs, 2 users 96% Avatar answered Sep 24 '22 01:09

2 revs, 2 users 96%