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

时间:2010-03-03 17:15:24

标签: c# winforms button pinvoke minimize

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

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

当用户最小化最大化窗口时,也会发送WM_WINDOWPOSCHANGING消息。但是我怎么知道用户何时最大化/最小化,移动/调整大小?我试过获取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;
}

任何帮助?

2 个答案:

答案 0 :(得分:2)

当用户点击标题栏中的其中一个按钮时,您获得WM_SYSCOMMANDhttp://msdn.microsoft.com/en-us/library/ms646360(VS.85).aspx

答案 1 :(得分:1)

您可以通过覆盖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
            //..
        }
    }
}
相关问题