Disable window movement

Share your favorite FastKeys commands
Post Reply
User avatar
gustms
Posts: 133
Joined: Sep 26th, ’14, 21:32
Location: USA

Post by gustms » Jul 25th, ’15, 02:58

Hello Marko or somebody else who knows AHK, could you please give me a help?

I found this excellent code which prevents the movement of a window. The problem is, it works by, when enabled, use the combinations of Win+f2 to activate, and Win+f3 to deactivate. But I want it to work just like the "Make Window Transparent" and "Windows always on Top +" in a way that, if I press the shortcut, it will activate and disable movement, and if I press again, it will deactivate and enable movement of that window. Is it possible?

Thanks a lot in advance.

Code: Select all

#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 ""
}
Source: http://www.autohotkey.com/board/topic/2 ... -a-window/
User avatar
gustms
Posts: 133
Joined: Sep 26th, ’14, 21:32
Location: USA

Post by gustms » Jul 25th, ’15, 03:33

Update:

I got it! Based on the "Make Window Transparent" and "Windows always on top +" examples. Is it okay this way, or do you think it could be improved?

Thanks in advance.

Code: Select all

WinGetTitle, Name, A
If (SubStr(Name, 1, 1) = "#") {
Name:=Name := SubStr(Name, 3)
RedrawSysMenu()
}
else {
Name:="# " . Name ;chr(134)
DisableMove()
}
WinSetTitle, A, , %Name%
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 ""
}
User avatar
Marko
Posts: 1718
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Jul 25th, ’15, 13:02

Hi Gustms,

This is a good method if you need a frozen window marked with # character. You could make it even simpler by just toggling a dedicated variable on/off - see an example in the first few lines of Show/Hide Clock command.
User avatar
gustms
Posts: 133
Joined: Sep 26th, ’14, 21:32
Location: USA

Post by gustms » Jul 25th, ’15, 15:34

Thank you Marko. I like it marked with a symbol, just like Always on Top, and Transparent (which I added a symbol as well). I think I'm gonna keep it as it is.

If someone is interested, the example from the second post seems to be working just fine on my tests.

Thanks!
theone1
Posts: 1
Joined: May 18th, ’13, 20:51

Post by theone1 » Dec 12th, ’16, 07:00

great scripts guys, thanks!
Post Reply