Pocket PC/Windows Mobile: How to detect smart minimize

核能气质少年 提交于 2019-11-30 13:50:17
Geries Handal

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

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.

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