我认为这里的方法是处理WM_ACTIVE消息,然后检查 fMinimized 参数是否不为零。您可以在此处找到有关如何在代码中声明此消息的更多信息。
我将尝试弄清楚如何在 C# 中准确编码并证明假设。但是,您可能比我快并弄清楚。
还要检查用于处理消息的函数DefWindowProc和WindowProc 。函数在您的代码中声明如下:
首先有包括:
using System.Runtime.InteropServices;
然后在类中声明这样
[DllImport("coredll.dll")]
static extern IntPtr DefWindowProc(IntPtr hWnd, uint uMsg, UIntPtr wParam,
IntPtr lParam);
您还可以做另一件事,这更像是一种“哲学”解决方法。INMO 智能最小化 X 让用户感到困惑,这就是我不喜欢包含它的原因。相反,我在表单的右下角提供了一个按钮,上面写着“关闭”或“返回”,它使用表单的关闭方法。我以各种形式使用它来保持标准。这对 windows 用户来说不太含糊,因为他们可能会认为 windows mobile 中的 X 与 windows for PC 中的 X 相同。
如果由于某种原因您需要最小化您的应用程序或将其发送到后台,请使用以下代码:
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);
}
}