0

I want to simulate Aero Snap functionality by my own. And for stick Form to a screen's side I'm using solution from this question. The problem is that after I call:

ShowWindow(Handle, SW_MAXIMIZE);

Form immediately maximizes and after call MoveWindow changes it's size to needed size. And this jump of the Form is visible and annoying. To prevent it I tried to disable handling of messages WM_GETMINMAXINFO, WM_SIZE, WM_MOVE, WM_NCCALCSIZE, WM_WINDOWPOSCHANGING, WM_WINDOWPOSCHANGED in WndProc. It helps but not completely. Is there any analog SuspendLayout()/ResumeLayout() for Form resizing?

melya
  • 578
  • 5
  • 24
  • Could you hide the form first, then resize and then show the form again? – Alex Sanséau Nov 17 '17 at 14:44
  • @AlexSanséau Doesn't help. `WinApi.ShowWindow(Handle, WinApi.SW_MAXIMIZE);` makes `Form` visible. – melya Nov 17 '17 at 14:50
  • Just read the comments on the question and you'll see that this is not actually the solution that the OP used. He used MoveWindow() as I recommended. – Hans Passant Nov 17 '17 at 14:53
  • @HansPassant I can't see this in comments. I see that last update in question is his own answer. Or maybe I'm looking wrong? – melya Nov 17 '17 at 15:01
  • "Did that already combining it with the answer of Nicolas". Use MoveWindow(). – Hans Passant Nov 17 '17 at 15:06
  • @HansPassant, yes, I saw this comment from 19th of August. But also there is his answer from 23th of August where ShowWindow() and MoveWindow() are used. – melya Nov 17 '17 at 15:11

1 Answers1

0

Disabling message handling in WndProc helped me to reduce flickering (all except WM_NCPAINT):

bool ignoreMessages = false;

public void DockWindow()
{
    ignoreMessages = true;
    ShowWindow(handle, SW_MAXIMIZE);
    ignoreMessages = false;
    MoveWindow(handle, 0, 0, Screen.PrimaryScreen.WorkingArea.Width / 2, Screen.PrimaryScreen.WorkingArea.Height, true);
}

protected override void WndProc(ref Message message)
{
    if (ignoreMessages &&
        message.Msg != WM_NCPAINT)
        return;

    base.WndProc(ref message);
}
melya
  • 578
  • 5
  • 24