Event when a window gets maximized/un-maximized

前端 未结 10 895
失恋的感觉
失恋的感觉 2020-11-27 05:48

Is there an event that is fired when you maximize a Form or un-maximize it?

Before you say Resize or SizeChanged: Those get only fired if t

10条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 06:15

    A complete solution with maximize, minimize, restore and correct remove of the lower bits which are used for internal purposes only.

    protected override void WndProc(ref Message m)
    {
        const int WM_SYSCOMMAND = 0x0112;
        const int SC_MAXIMIZE = 0xF030;
        const int SC_MINIMIZE = 0xF020;
        const int SC_RESTORE = 0xF120;
    
        // dependig on the needs may be called before, after or even never (see below)
        // base.WndProc(ref m);
    
        if (m.Msg == WM_SYSCOMMAND)
        {
            /// 
            /// Quote:
            /// In WM_SYSCOMMAND messages, the four low - order bits of the wParam parameter 
            /// are used internally by the system.To obtain the correct result when testing 
            /// the value of wParam, an application must combine the value 0xFFF0 with the 
            /// wParam value by using the bitwise AND operator.
            int wParam = (m.WParam.ToInt32() & 0xFFF0);
    
            Debug.WriteLine($"Received param: { Convert.ToString(wParam, 16) } ");
    
            if (wParam == SC_MAXIMIZE)
            {
    
            }
    
            if (wParam == SC_MINIMIZE)
            {
    
            }
    
            if (wParam == SC_RESTORE)
            {
    
            }
        }
    
        // don't use when above call is uncommented
        base.WndProc(ref m);
    }
    

提交回复
热议问题