티스토리 뷰

IT/C#

[CS] WM_GETMINMAXINFO WndProc 처리

주인장 진빼이

WM_GETMINMAXINFO WndProc 처리

WM_GETMINMAXINFO 메시지는 창 크기가 초기화될 때, 사용자가 창 크기를 변경하고 있을 때 계속 발생한다.
다음 코드를 사용하면 최소 200x400, 최대 400x400으로 설정할 수 있다.
이를 활용하여 세로나 가로 축을 고정시키고 또 다른 축만 크기를 변경시킬 수 있게 만들 수 있다.
WM_GETMINMAXINFO MSDN

private const int WM_GETMINMAXINFO = 0x0024;

[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
    public int X;
    public int Y;

    public POINT(int x, int y)
    {
        this.X = x;
        this.Y = y;
    }

    public static implicit operator System.Drawing.Point(POINT p)
    {
        return new System.Drawing.Point(p.X, p.Y);
    }

    public static implicit operator POINT(System.Drawing.Point p)
    {
        return new POINT(p.X, p.Y);
    }
}

[StructLayout(LayoutKind.Sequential)]
private struct MINMAXINFO
{
    public POINT ptReserved;
    public POINT ptMaxSize;
    public POINT ptMaxPosition;
    public POINT ptMinTrackSize;
    public POINT ptMaxTrackSize;
}

protected override void WndProc(ref Message m)
{
    switch (m.Msg)
    {
        // The WM_ACTIVATEAPP message occurs when the application
        // becomes the active application or becomes inactive.
        case WM_GETMINMAXINFO:
            MINMAXINFO mmi = new MINMAXINFO();
            mmi.ptMaxTrackSize = new POINT(200, 400);
            mmi.ptMinTrackSize = new POINT(400, 400);
            Marshal.StructureToPtr(mmi, m.LParam, false);
            break;
    }
    base.WndProc(ref m);
}
댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함