How to Prevent a Windows from Being Moved

How do you prevent a windows from being moved?

Take a look at this link. You might be interested in option #3. It will require you to wrap some native code, but should work. There's also a comment at the bottom of the link that shows an easier way to do it. Taken from the comment (can't take credit for it, but I'll save you some searching):

protected override void WndProc(ref Message message)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_MOVE = 0xF010;

switch(message.Msg)
{
case WM_SYSCOMMAND:
int command = message.WParam.ToInt32() & 0xfff0;
if (command == SC_MOVE)
return;
break;
}

base.WndProc(ref message);
}

How to prevent program windows from being moved under a desktop toolbar?

I've found the solution. The window manager property _NET_WM_STRUT_PARTIAL reserves space for the toolbars. This space cannot be used by normal windows and so by setting this property other windows cannot be moved over or under the toolbar (Just like the gnome 2 toolbars in redhat).

C#: how to disable form move?

Maximize it. Thanks, JackN. ;-)

c# how can I make a windows form non movable and movable again

Just have a flag:

private bool _preventMove = false;

protected override void WndProc(ref Message message)
{
const int WM_SYSCOMMAND = 0×0112;
const int SC_MOVE = 0xF010;

if(_preventMove)
{
switch(message.Msg)
{
case WM_SYSCOMMAND:
int command = message.WParam.ToInt32() & 0xfff0;
if (command == SC_MOVE)
return;
break;
}
}

base.WndProc(ref message);
}

Set the flag to true/false to disable/enable movement

How to prevent moving of a window without titlebar but with WS_SYSMENU style?

The clue to disabling the SC_MOVE item is in the description of the GetSystemMenu function:

The system automatically grays items on the standard window menu, depending on the situation. The application can perform its own checking or graying by responding to the WM_INITMENU message that is sent before any menu is displayed.

So even though you're disabling the menu item initially, the system is re-enabling it when the menu is displayed. To fix it, you need to handle WM_INITMENU or WM_INITMENUPOPUP yourself and override the system's behaviour. For example,
in your window procedure:

        case WM_INITMENUPOPUP:
if (wParam == reinterpret_cast<WPARAM>(GetSystemMenu(hWnd, FALSE)))
{
// override handling of the system menu
EnableMenuItem(reinterpret_cast<HMENU>(wParam), SC_MOVE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
return 0;
}
// if WM_INITMENUPOPUP isn't for the system menu, fall through to
// default processing
return DefWindowProc(hWnd, uMsg, wParam, lParam);

How do you stop windows from resizing and moving your window?

In Win32 land, you would handle WM_MOVING, WM_SIZING, and WM_WINDOWPOSCHANGING and turn them into a no-op. You would also probably want to handle WM_ENTERSIZEMOVE and WM_EXITSIZEMOVE.

It's actually quite annoying unless you are writing the app for yourself.



Related Topics



Leave a reply



Submit