C # Form display with WS_EX_NOACTIVATE flag

I have a borderless form that is always on top and with a flag WS_EX_NOACTIVATEto prevent it from getting focus.

const int WS_EX_NOACTIVATE = 0x08000000;

protected override CreateParams CreateParams {
    get {
        CreateParams param = base.CreateParams;
        param.ExStyle |= WS_EX_NOACTIVATE;
        return param;
    }
}

The form contains a small frame for moving (as it is borderless):

private void pictureBox4_MouseMove(object sender, MouseEventArgs e) {
    if (e.Button == MouseButtons.Left) {
        ReleaseCapture();
        SendMessage(this.Handle, 0xa1, 0x2, 0);
    }
}

However, when I move the window, it cannot be redrawn / shown, only when I release the mouse button, it moves the form to a new location.

I saw applications that work in a similar way, but they display a window while moving (for example, some virtual keyboards that I saw). I also saw a lot of questions elsewhere about this issue, but without an answer.

-, , , /, (, "" ), , ?

+3
1

, . , - , ( ). , :

[DllImportAttribute("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInstertAfter, int x, int y, int cx, int cy, uint flags);

const int SWP_NOSIZE = 0x0001;
const int SWP_NOZORDER = 0x0004;

private void pictureBox4_MouseMove(object sender, MouseEventArgs e) {
    if (e.Button == MouseButtons.Left) {
        //ReleaseCapture();
        //SendMessage(this.Handle, 0xa1, 0x2, 0);
        SetWindowPos(Handle, IntPtr.Zero, this.Location.X + e.X,
                this.Location.Y + e.Y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
    }
}

, () SetWindowPos(). , , , ...

+2

Source: https://habr.com/ru/post/1748418/


All Articles