Moveable Gui with NoActivate Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Scr1pter
Posts: 1214
Joined: 06 Aug 2017, 08:21
Location: Germany

Moveable Gui with NoActivate

03 Apr 2020, 08:51

Hello,

I found this NoActivate GuiClass, which can be used for an On-Screen keyboard (as example):
https://www.autohotkey.com/boards/viewtopic.php?t=7611

I'm trying to add the possibility to move the Gui by using:

Code: Select all

OnMessage(0x201, "WM_LBUTTONDOWN")
WM_LBUTTONDOWN()
{
	PostMessage, 0xA1, 2
}
My aim is to have an additional button which toggles the ability of being movable.
If it's moveable, it cannot be "noActivated" anymore, and that's why I'm trying re-enable it somehow.

In this case, as soon as I press the 4th button, there is no way to make the Gui noActivated.
How to write it?

Code: Select all

;ClickableOnScreenKeyboard
#include Clickable_Gui_No_Activate.ahk

Gui, -Caption +AlwaysOnTop +HwndhGui
Gui, Add, Button,    w150 gSendChr, a ; Sends an A
Gui, Add, Button, ys wp   gSendChr, h ; Sends an H
Gui, Add, Button, ys wp   gSendChr, k ; Sends a K
Gui, Add, Button, ys wp   gMoveGui, Move this Gui ; When clicking, the gui can be moved
Gui, Show, NA, On Screen Keyboard Demo ; Shows gui with unique name
Gui_NoActivate(hGui) ; Implements Clickable_Gui_No_Activate class
return

SendChr:
k := GetKeyState("CapsLock", "T") ? Format("{:U}", A_GuiControl) : A_GuiControl
SendInput, % "{" k "}"
return

MoveGui:
toggle := !toggle ; Either true or false
if (toggle) ; If true:
{
  OnMessage(0x201, "WM_LBUTTONDOWN") ; If lbutton down: Activate function for mouse down
}
else ; If false:
{
  OnMessage(0x201, "WM_LBUTTONUP") ; When lbutton down: Activate function for mouse up -> Disable mouse down
}
return

WM_LBUTTONDOWN() ; OnMessage function for mouse down
{
	PostMessage, 0xA1, 2
}
WM_LBUTTONUP() ; OnMessage function for mouse up
{
  PostMessage, 0xA2, 2
}

I guess the 2nd OnMessage function isn't correct.
Thanks for any help and best regards
Please use [code][/code] when posting code!
Keyboard: Logitech G15 FE - Mice: Logitech G9 FE, G502 FE, G602, Jelly Comb Touchpad - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.32.00
User avatar
boiler
Posts: 6594
Joined: 21 Dec 2014, 02:44

Re: Moveable Gui with NoActivate  Topic is solved

03 Apr 2020, 09:45

0x201 is the value for message WM_LBUTTONDOWN, so when you put the following:

Code: Select all

 OnMessage(0x201, "WM_LBUTTONUP")
...it's just changing the function that gets called when the left mouse button is pressed to the one you labeled WM_LBUTTONUP. The value for message WM_LBUTTONUP is 0x202, so to actually register the message WM_LBUTTONUP (which monitors when the left mouse button is released), your line would be:

Code: Select all

 OnMessage(0x202, "WM_LBUTTONUP")
However, your comment seems that you are not really trying to do that, but that you are actually trying to "Disable mouse down". Do you mean you want to the script to no longer monitor the WM_LBUTTONDOWN message? If so, that would be:

Code: Select all

 OnMessage(0x201, "")
User avatar
Scr1pter
Posts: 1214
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Moveable Gui with NoActivate

03 Apr 2020, 15:36

Thanks for your help.

Yeah, OnMessage(0x201, "") is actually a good start!
I did some tests and the current version works well.

Maybe there's a better way than re-loading the whole gui, I don't know:

Code: Select all

;ClickableOnScreenKeyboard
#SingleInstance, force
#include Clickable_Gui_No_Activate.ahk
global xPos := 0, yPos := 0 ; Initialize with zeroes

F1::
Gui_Funktion() ; Load gui
return

SendChr:
k := GetKeyState("CapsLock", "T") ? Format("{:U}", A_GuiControl) : A_GuiControl
SendInput, % "{" k "}"
return

MoveGui:
moveToggle := !moveToggle ; Either true or false
if (moveToggle) ; If true:
{
  OnMessage(0x201, "WM_LBUTTONDOWN") ; If lbutton down: Activates function for mouse down
  GuiControl,, MoveGuiText, Move and click to save ; Changes text of button
}
else ; If false:
{
  OnMessage(0x201, "") ; Disables OnMessage for lbutton down
  WinGetPos, xPos, yPos, , , A  ; "A", um die Position des aktiven Fensters zu bekommen. 
  Gui_Funktion() ; Re-load gui
}
return

ExitGui:
moveToggle := false ; Reset toggle
OnMessage(0x201, "") ; Disable OnMessage for lbutton down
Gui, PS: Destroy ; Destroy gui
return

WM_LBUTTONDOWN() ; OnMessage function for mouse down
{
	PostMessage, 0xA1, 2
}
Gui_Funktion()
{
  global MoveGuiText ; To prevent AHK from shouting at me
  Gui, PS: Destroy ; Destroys gui (if it already exists)
  Gui, PS: -Caption +AlwaysOnTop +HwndhGui +ToolWindow
  Gui, PS: Add, Button, w150 gSendChr, a ; Sends an A
  Gui, PS: Add, Button, ys wp   gSendChr, h ; Sends an H
  Gui, PS: Add, Button, ys wp   gSendChr, k ; Sends a K
  Gui, PS: Add, Button, ys wp  vMoveGuiText gMoveGui, Click to enable movement ; After being clicked,, the gui can be moved
  Gui, PS: Add, Button, ys wp  gExitGui, Close gui ; Closes gui and resets MoveGui toggle
  Gui, PS: Show, x%xPos% y%yPos% NA, On Screen Keyboard Demo ; Shows gui with unique name
  Gui_NoActivate(hGui) ; Implements Clickable_Gui_No_Activate class
}
When I try it just with PostMessage, 0xA1, 2, it doesn't work.
If I try it without it (inside of the else statement of the toggle), it won't work either.

After combining our ideas, it works :)

Best regards
Please use [code][/code] when posting code!
Keyboard: Logitech G15 FE - Mice: Logitech G9 FE, G502 FE, G602, Jelly Comb Touchpad - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.32.00
lblb
Posts: 150
Joined: 30 Sep 2013, 11:31

Re: Moveable Gui with NoActivate

04 Apr 2020, 20:21

Does this work for what you need, without the use of a toggle? I haven't optimized it, so when you launch it just activate any other window, and then the Gui should be movable without being activated,

Code: Select all

#SingleInstance, force
SetBatchLines -1

Gui, Main: Margin, 0, 0
Gui, Main: +LastFound -Resize +HwndhGuiMain +AlwaysOnTop -Caption -dpiscale +ToolWindow +E0x08000000
Gui, Main: Add, Button, x50 y50 w50 h50 gSendw, W
Gui, Main: Add, Button, x50 y150 w50 h50 gSendh, H

; Drag Gui
OnMessage(0x201, "WM_LBUTTONDOWN")

Gui, Main: Show, w300 h300
Return 

Sendw:
Send, w
Return 

Sendh:
Send, h
Return 

; Move Gui when dragged
WM_LBUTTONDOWN()
	{
	Global
	MouseGetPos, , , id, control,
	MouseGetPos, , , id, control_name, 2
	GuiControlGet, Name_Var, Name, %control_name%
	If InStr(control, "AutoHotKeyGUI") or (control = "") or If InStr(Name_Var, "Title")
		DragNotActivate(id)
	}


DragNotActivate(hwnd,WhileKeyDown="LButton") 
	{
	CoordMode, Mouse, Screen
	MouseGetPos, mx,my
	WinGetPos, wx,wy,,, ahk_id %hwnd%
	offsetX := mx-wx, offsetY := my-wy
	owd := A_WinDelay
	SetWinDelay, -1
	While (GetKeyState(WhileKeyDown,"p")) {
		Sleep, 20
		MouseGetPos, x,y
		WinMove, ahk_id %hwnd%,, x-offsetX,y-offsetY
	}
	SetWinDelay, %owd%
	}

User avatar
Scr1pter
Posts: 1214
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Moveable Gui with NoActivate

05 Apr 2020, 04:39

Well, when I compare your solution to mine, I can only say:
lblb wins!
Flawless Victory!
Fatality!


Bravo :bravo:

Thank you and best regards !
Please use [code][/code] when posting code!
Keyboard: Logitech G15 FE - Mice: Logitech G9 FE, G502 FE, G602, Jelly Comb Touchpad - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.32.00
lblb
Posts: 150
Joined: 30 Sep 2013, 11:31

Re: Moveable Gui with NoActivate

05 Apr 2020, 04:56

Cool, I'm glad it works for what you need. I put that tester together a long time ago and actually didn't really look at it before posting it here but there may be some extra stuff that is not necessary in what I posted. Sorry, I don't have time to check, this end of the world thing is keeping me busy. In any case, it mostly comes from here:

Use of +E0x08000000 to make the Gui non-activatable as shown by Wicked:
http://www.autohotkey.com/board/topic/57707-noactivate-but-clickable/

Function to Drag and Not Activate developed by Learning one:
http://www.autohotkey.com/board/topic/67566-solved-postmessage-drag-window-without-activating-it/?p=429015
just me
Posts: 7404
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Moveable Gui with NoActivate

05 Apr 2020, 06:10

Using a Move button to move the window:

Code: Select all

#NoEnv
Gui, +AlwaysOnTop +Border -Caption +HwndhGui +ToolWindow +E0x08000000
Gui, Margin, 20, 20
Gui, Add, Button,          w150 gSendChr, a
Gui, Add, Button,       ym wp   gSendChr, h
Gui, Add, Button,       ym wp   gSendChr, k
Gui, Add, Button, xm       wp   vMove, Move
Gui, Add, Button, x+190 yp wp   gGuiClose, Exit
Gui, Show, NA, On Screen Keyboard Demo
OnMessage(0x0201, "WM_LBUTTONDOWN")
Return

GuiClose:
ExitApp

SendChr:
	k := GetKeyState("CapsLock", "T") ? Format("{:U}", A_GuiControl) : A_GuiControl
	SendInput, % "{" k "}"
Return

WM_LBUTTONDOWN() {
   If (A_GuiControl = "Move") {
      PostMessage, 0xA1, 2
      Return 0
   }
}

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, anv, BeSu, Google [Bot], Lee James, mikeyww, Odlanir, TXShooter and 53 guests