Resizing a gui not just on edges?

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

Resizing a gui not just on edges?

04 May 2020, 17:09

Hello,

This simple gui can be resized when clicking and dragging on any edge:

Code: Select all

F2::
Gui, Tr: +Resize +LastFound +AlwaysOnTop -Caption +ToolWindow +E0x20
Gui, Tr: Add, Picture, x0 y0 w550 h500, Testpic.png ; An image which has transparent background
Gui, Tr: Show, x0 y0 w550 h500 NA, TestGui ; Shows gui with unique name, without activating it
return
However, on a touchscreen device it's pretty difficult to aim at an edge (with a finger).
With a mouse or touchpad it's no problem.

Question:
Is there a way to have some kind of tolerance?
Let's say if I touch up to 10 pixels away from the edge, the gui should be resized as well.
Of course I would always have to touch INSIDE of the gui, that's logical.

Right now, I have no concrete idea how/if this can be realized.

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: 5651
Joined: 21 Dec 2014, 02:44

Re: Resizing a gui not just on edges?

04 May 2020, 21:36

Try this. I made the tolerance region within the border a value of 30 for demonstration purposes, but you can change it. Making it 10 doesn't help that much because some of the actual window size seems to be an invisible area around the edges.

Code: Select all

OnMessage(0x201, "WM_LBUTTONDOWN")

F2::
Gui, Tr: +Resize +LastFound +AlwaysOnTop -Caption +ToolWindow +E0x20
Gui, Tr: Add, Picture, x0 y0 w550 h500, Testpic.png ; An image which has transparent background
Gui, Tr: Show, x0 y0 w550 h500 NA, TestGui ; Shows gui with unique name, without activating it
return

WM_LBUTTONDOWN(wParam, lParam, msg, hwnd)
{
	tol := 30
	CoordMode, Mouse, Window
	MouseGetPos, mx, my
	WinGetPos,,, ww, wh, ahk_id %hwnd%
	if (mx < tol) || (ww - mx < tol) || (my < tol) || (wh - my < tol) {
		; ToolTip, % "mx: " mx "`nmy:" my "`nww - mx: " ww - mx "`nwh - my:" wh - my
		Send, {LButton up}
		if (mx < tol)
			MouseMove, 2, my
		else if (ww - mx < tol)
			MouseMove, ww - 2, my
		else if (my < tol)
			MouseMove, mx, 2
		else
			MouseMove, mx, wh - 2
		Send, {LButton down}
	}
}

Esc::ExitApp
There are ways you could make the cursor change to a resize shape when its hovering over the appropriate regions, but that's more involved and would eat up more processor time as it would constantly be monitoring what the mouse is hovering over rather than just capturing the click event.
User avatar
Scr1pter
Posts: 1195
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Resizing a gui not just on edges?

07 May 2020, 16:42

Thank you (again :) )

Well, it's a clever method but unfortunately it does not work for touch.
I think the problem is that Windows does not accept touch as OnMessage(0x201, "WM_LBUTTONDOWN").

This means I will probably have to work with lbutton.
However, I don't know what parameters to use:

Code: Select all

#if guiMode

~lbutton::
WM_LBUTTONDOWN() ; What parameters to use here?
return

#if

F2::
Gui, Tr: +Resize +LastFound +AlwaysOnTop -Caption +ToolWindow +E0x20
Gui, Tr: Add, Picture, x0 y0 w550 h500, Testpic.png ; An image which has transparent background
Gui, Tr: Show, x0 y0 w550 h500 NA, TestGui ; Shows gui with unique name, without activating it
OnMessage(0x201, "WM_LBUTTONDOWN")
guiMode := 1
return
Cheers!
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

Return to “Ask For Help”

Who is online

Users browsing this forum: anhnha, Chunjee, Google [Bot], littlegandhi1199, RubbeH, sobuj53, VibinonAHk, Xeo786 and 41 guests