Is it possible to lock window position, or I should check the position every XX seconds and if it's not where it's supposed to be, to move it back?
Thanks.
Locking a window
Started by
steliyan
, Sep 13 2007 11:19 AM
1 reply to this topic
#1
-
Posted 13 September 2007 - 11:19 AM
This is based on one of Skan's TipsNTricks: How to Disable ( Grey-out ) the Close Button?
Strangely, removing the Move item doesn't prevent you from moving Console (command prompt / "DOS") windows...
Alternatively, if you're trying to lock your own GUI window, you can use OnMessage() to block WM_SYSCOMMAND (0x112) when wParam is SC_MOVE (0xF010).
My first attempt at disabling move was this:
#F2::DisableMove() #F3::RedrawSysMenu() DisableMove(hWnd="") { If hWnd= hWnd:=WinExist("A") hSysMenu:=DllCall("GetSystemMenu","Int",hWnd,"Int",FALSE) DllCall("RemoveMenu","Int",hSysMenu,"UInt",1,"Uint",0x400) DllCall("DrawMenuBar","Int",hWnd) Return "" } RedrawSysMenu(hWnd="") { If hWnd= hWnd:=WinExist("A") DllCall("GetSystemMenu","Int",hWnd,"Int",TRUE) DllCall("DrawMenuBar","Int",hWnd) Return "" }It removes the "Move" item from the system menu of the active window, which also prevents it from being moved by click-dragging the titlebar. It assumes the Move item is the second item in the menu, so mightn't work with windows that have customized system menus (this isn't common.) Actually, it shouldn't be used with such windows anyway, since RedrawSysMenu() reverts the system menu to defaults - destroying any custom menu items.
Strangely, removing the Move item doesn't prevent you from moving Console (command prompt / "DOS") windows...
Alternatively, if you're trying to lock your own GUI window, you can use OnMessage() to block WM_SYSCOMMAND (0x112) when wParam is SC_MOVE (0xF010).
My first attempt at disabling move was this:
CoordMode, Mouse, Screen ~LButton:: MouseGetPos, x, y, win SendMessage, 0x84,, (x & 0xFFFF) | (y & 0xFFFF) << 16,, ahk_id %win% ; If the mouse is over a titlebar, unclick to prevent move. if ErrorLevel = 2 Click Up returnThis prevents click-drag when the mouse is over the titlebar. You can still move the window with the arrow keys, though, by selecting Move from the window's system menu.
#2
-
Posted 13 September 2007 - 01:05 PM