1

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

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

有什么帮助吗?

4

2 回答 2

2

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

于 2010-03-03T17:17:16.987 回答
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
            //..
        }
    }
}
于 2010-03-03T18:19:01.683 回答