Pocket PC/Windows Mobile: How to detect smart minimize

徘徊边缘 提交于 2019-12-18 16:27:22

问题


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.


回答1:


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);
    }
} 



回答2:


What exactly do you mean by smart-minimized? I suppose you mean your app being automatically minimised on no activity for some time? Well, I don't think that there is an event for that.

The author of this blog spot uses the Deactivate event for turning internal process on and off. This is acceptable for animation and other similar processes and the cases of a message box or another form popping up are no problems. If however, your process must not be stopped unless the application closes or 'smart-minimizes', you could try starting a timer on deactivate events. If the form isn't activated back for a specific interval, then it would be safe to stop the internal process.

Of course in designing your solution you need to take Power Management into consideration. Have a look at this and of course also OpenNetCF for power notifications.



来源:https://stackoverflow.com/questions/365773/pocket-pc-windows-mobile-how-to-detect-smart-minimize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!