如何替换最小化按钮的命令?

发布于 2024-08-23 11:34:53 字数 914 浏览 5 评论 0原文

首先,抱歉我的英语不好:)
其次,我可以使用以下代码知道表单何时移动/调整大小:

    protected override void WndProc(ref Message m)
    {

        if (m.Msg == WM_WINDOWPOSCHANGING)
        {
            WINDOWPOS winPos = new WINDOWPOS();
            winPos = (WINDOWPOS)Marshal.PtrToStructure(m.LParam, typeof(WINDOWPOS));

            //Here I just need to change the values of the WINDOWPOS structure

            Marshal.StructureToPtr(winPos, m.LParam, true);
        }
    }

当用户最小化最大化 窗户。但是我如何知道用户何时最大化/最小化,而不是移动/调整大小?我尝试获取 WindowState 属性,但没有成功:(
WINDOWPOS结构的代码是:

[StructLayout(LayoutKind.Sequential)]
public struct WINDOWPOS
{
    public IntPtr hwnd;
    public IntPtr hwndInsertAfter;
    public int x;
    public int y;
    public int cx;
    public int cy;
    public int flags;
}

有帮助吗?

First, sorry for my bad english :)
Second, I can know when the form is being moved/resized, using this code:

    protected override void WndProc(ref Message m)
    {

        if (m.Msg == WM_WINDOWPOSCHANGING)
        {
            WINDOWPOS winPos = new WINDOWPOS();
            winPos = (WINDOWPOS)Marshal.PtrToStructure(m.LParam, typeof(WINDOWPOS));

            //Here I just need to change the values of the WINDOWPOS structure

            Marshal.StructureToPtr(winPos, m.LParam, true);
        }
    }

The WM_WINDOWPOSCHANGING message is sent also when the user is minimizing or maximizing the window. But how I can know when the user is maximizing/minimizing, not moving/resizing? I tried get the WindowState property, but it didn't work :(
The code of the WINDOWPOS structure is:

[StructLayout(LayoutKind.Sequential)]
public struct WINDOWPOS
{
    public IntPtr hwnd;
    public IntPtr hwndInsertAfter;
    public int x;
    public int y;
    public int cx;
    public int cy;
    public int flags;
}

Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

美煞众生 2024-08-30 11:34:53

当用户单击标题栏中的按钮之一时,您会收到 WM_SYSCOMMANDhttp://msdn.microsoft.com/en-us/library/ms646360(VS.85).aspx

You get WM_SYSCOMMAND when the user clicks one of the buttons in the title bar: http://msdn.microsoft.com/en-us/library/ms646360(VS.85).aspx

爱你不解释 2024-08-30 11:34:53

您可以通过重写 WndProc() 来捕获 WM_SYSCOMMAND。但也可以通过 Resize 事件的事件处理程序轻松完成:

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
        mPrevState = this.WindowState;

    }
    FormWindowState mPrevState;
    protected override void OnResize(EventArgs e) {
        base.OnResize(e);
        if (mPrevState != this.WindowState) {
            mPrevState = this.WindowState;
            // Do something
            //..
        }
    }
}

You can trap the WM_SYSCOMMAND by overriding WndProc(). But it can easily be done as well with an event handler for the Resize event:

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
        mPrevState = this.WindowState;

    }
    FormWindowState mPrevState;
    protected override void OnResize(EventArgs e) {
        base.OnResize(e);
        if (mPrevState != this.WindowState) {
            mPrevState = this.WindowState;
            // Do something
            //..
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文