Keep Window Inactive In Appearance Even When Activated

后端 未结 3 1746
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-15 02:00

Is there a way to keep a window inactive looking, even if it contains focus? I have two forms (A and B). After the user interacts with A, I transfer focus back to B. The

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-15 02:41

    At last, I found the answer!

    WARNING: DO NOT abuse this answer's technique. Doing so will confuse your users and will be harmful to the computing experience in general. The technique described below can be very useful under certain circumstances (e.g implementing IntelliSense-like behavior), but please be judicious in your usage of it.

    The WM_NCACTIVATE message is sent to a window to change the state of its non-client area (i.e. border and titlebar) to inactive or active. The wParam of the message indicates whether the state will be inactive or active. If the wParam is true (a value of 1), the window will look active. If the wParam is false (a value of 0), the window will look inactive. To force a window to stay either inactive or active, override the wParam by setting it to the corresponding value (0 or 1), and you will be all set!

    private const int WM_NCACTIVATE = 0x0086;
    
    protected override void WndProc(ref Message m)
    {
        if (m.Msg == WM_NCACTIVATE)
        {
            // Use this to make it always look inactive:
            m.WParam = (IntPtr)0;
    
            // Alternately, use this to make it always look active:
            m.WParam = (IntPtr)1;
        }
    
        base.WndProc(ref m);
    }
    

提交回复
热议问题