Disable window movement

Share your favorite FastKeys commands
User avatar
Posts: 79
Joined: Fri Sep 26, 2014 8:32 pm

Disable window movement

PostPosted by gustms » Sat Jul 25, 2015 1:58 am

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
Posts: 79
Joined: Fri Sep 26, 2014 8:32 pm

Re: Disable window movement

PostPosted by gustms » Sat Jul 25, 2015 2:33 am

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 ""
}

Site Admin
User avatar
Posts: 641
Joined: Sat Mar 02, 2013 9:02 pm

Re: Disable window movement

PostPosted by Marko » Sat Jul 25, 2015 12:02 pm

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
Posts: 79
Joined: Fri Sep 26, 2014 8:32 pm

Re: Disable window movement

PostPosted by gustms » Sat Jul 25, 2015 2:34 pm

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

Re: Disable window movement

PostPosted by theone1 » Mon Dec 12, 2016 7:00 am

great scripts guys, thanks!


Last bumped by Anonymous on Mon Dec 12, 2016 7:00 am.

Return to User Commands and Scripts

Who is online

Users browsing this forum: No registered users and 1 guest