Thursday, October 4, 2012

Prevent form to blink when gets activate

In my previous post, I was telling you how to run one instance of the application and how to capture command line parameters from next runs. There were one problem, though - on every run, form was getting activate message and window started to blink. To resolve this, you need to handle WM_NCACTIVATE message to ignore Activate message:


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

No comments:

Post a Comment