Can AHK draw a GUI from BottomRight to TopLeft? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
PipeDreams
Posts: 165
Joined: 19 Dec 2015, 00:20

Can AHK draw a GUI from BottomRight to TopLeft?

06 Jul 2019, 13:24

Can AHK draw a GUI from BottomRight to TopLeft?

Can anyone show me how/if this can be done?

I can only figure out how to draw a GUI from TopLeft to BottomRight.

Code: Select all

#SingleInstance Force
RButton::
{	MouseGetPos, Xpos, Ypos
	X1 := (Xpos), Y1 := (Ypos)
	Gui, 1: +Alwaysontop -Caption +E0x20
	Gui, 1: Color, Lime
	Gui, 1: Show, NA x%X1% y%Y1%, Horizontal ;StartPoint
	WinSet, Transparent, 50, Horizontal
	SetTimer, ReSize, 1
		KeyWait, RButton
	SetTimer, ReSize, OFF
	Gui, 1: Destroy
} Return
ReSize:
{	MouseGetPos, Xpos, Ypos
	X2 := (Xpos - X1), Y2 := (Ypos - Y1)
	If ((X2 <= -1) AND !(Y2 <= -1)) ;Down & Left
	{	
		SoundBeep, 200, 10
		Sleep, 5
	}
	If (!(X2 <= -1) AND (Y2 <= -1)) ;Right & Up
	{	
		SoundBeep, 300, 10
		Sleep, 5
	} 
	If ((X2 <= -1) AND (Y2 <= -1)) ;Left & Up
	{	
		SoundBeep, 500, 10
		Sleep, 5
	}
	If ((X2 >= 1) AND (Y2 >= 1)) ;Down & Right
	{	Gui, 1: Show, NA H%Y2% W%X2%, Horizontal ;EndPoint
		SoundBeep, 700, 10
	} ToolTip, X1. %X1% Y1. %Y1% `nX2. %X2% Y2. %Y2%,,
	SetTimer, RemoveToolTip, -100
} Return
RemoveToolTip:
{	ToolTip
} Return
~Esc::ExitApp
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Can AHK draw a GUI from BottomRight to TopLeft?  Topic is solved

06 Jul 2019, 13:44

maybe try this:

Code: Select all

	If ((X2 <= -1) AND (Y2 <= -1)) ;Left & Up
	{   Y2 *= -1, x2 *=-1
        Gui, 1: Show, NA x%Xpos% y%Ypos% H%Y2% W%X2%, Horizontal ;EndPoint
		SoundBeep, 500, 10
		Sleep, 5
	}
I hope that helps.
teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: Can AHK draw a GUI from BottomRight to TopLeft?

06 Jul 2019, 14:38

Another approach:

Code: Select all

SetBatchLines, -1

Gui, Select: New, +Alwaysontop -Caption +LastFound +ToolWindow +E0x20
WinSet, Transparent, 50
Gui, Color, Lime
Return

Esc:: ExitApp

RButton::
   hHook := SetMouseHook()
   KeyWait, RButton
   SetMouseHook(hHook)
   Gui, Select:Show, Hide
   Return
   
SetMouseHook(hHook := "") {
   if hHook
      DllCall("UnhookWindowsHookEx", Ptr, hHook)
   else {
      Return DllCall("SetWindowsHookEx", Int, WH_MOUSE_LL := 14
                                       , Int, RegisterCallback("LowLevelMouseProc", "Fast")
                                       , Ptr, DllCall("GetModuleHandle", UInt, 0, Ptr)
                                       , UInt, 0, Ptr)
   }
}

LowLevelMouseProc(nCode, wParam, lParam) {
   static WM_MOUSEMOVE := 0x200, WM_RBUTTONUP := 0x205
        , mouseX, mouseY, prevMouseX, prevMouseY
        , timer := Func("LowLevelMouseProc").Bind("timer", "", "")
   
   if (nCode = "timer") {
      x := prevMouseX < mouseX ? prevMouseX : mouseX
      y := prevMouseY < mouseY ? prevMouseY : mouseY
      w := Abs(mouseX - prevMouseX)
      h := Abs(mouseY - prevMouseY)
      try Gui, Select: Show, x%x% y%y% w%w% h%h% NA
   }
   else {
      if (wParam = WM_RBUTTONUP)
         prevMouseX := prevMouseY := ""
      if (wParam = WM_MOUSEMOVE)  {
         mouseX := NumGet(lParam + 0, "Int")
         mouseY := NumGet(lParam + 4, "Int")
         if (prevMouseX = "") {
            prevMouseX := mouseX
            prevMouseY := mouseY
         }
         SetTimer, % timer, -10
      }
      Return DllCall("CallNextHookEx", Ptr, 0, Int, nCode, UInt, wParam, Ptr, lParam)
   }
}
User avatar
PipeDreams
Posts: 165
Joined: 19 Dec 2015, 00:20

Re: Can AHK draw a GUI from BottomRight to TopLeft?

06 Jul 2019, 14:55

Thank you Wolf, That did help out! Here's what I was able to do with your suggestion.

Code: Select all

#SingleInstance Force
RButton::
{	MouseGetPos, Xpos, Ypos
	X1 := (Xpos), Y1 := (Ypos)
	Gui, 1: +Alwaysontop -Caption +E0x20
	Gui, 1: Color, Lime
	Gui, 1: Show, NA x%X1% y%Y1%, Gui1 ;StartPoint
	WinSet, Transparent, 50, Gui1
	SetTimer, ReSize, 1
		KeyWait, RButton
	SetTimer, ReSize, OFF
	Gui, 1: Destroy
} Return
ReSize:
{	MouseGetPos, Xpos, Ypos
	X2 := (Xpos - X1), Y2 := (Ypos - Y1)
	If ((X2 <= -1) AND !(Y2 <= -1)) ;Down & Left
	{	X2 := (X2 * -1), Y2 := (Y2 * 1)
		Gui, 1: Show, NA x%Xpos%, Gui1 ;EndPoint
	} If (!(X2 <= -1) AND (Y2 <= -1)) ;Right & Up
	{	X2 := (X2 * 1), Y2 := (Y2 * -1)
		Gui, 1: Show, NA y%Ypos% , Gui1 ;EndPoint
	} If ((X2 <= -1) AND (Y2 <= -1)) ;Left & Up
	{	X2 := (X2 * -1), Y2 := (Y2 * -1)
		Gui, 1: Show, NA x%Xpos% y%Ypos%, Gui1 ;EndPoint
	} If ((X2 >= 1) AND (Y2 >= 1)) ;Down & Right
	{	Gui, 1: Show, NA H%Y2% W%X2%, Gui1 ;EndPoint
	} ToolTip, X1. %X1% Y1. %Y1% `nX2. %X2% Y2. %Y2%,,
	SetTimer, RemoveToolTip, -100
} Return
RemoveToolTip:
{	ToolTip
} Return
~Esc::ExitApp
Thank you TeaDrinker for showing me a different way to accomplish the same thing, I will study it, as it seems so fancy!
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Can AHK draw a GUI from BottomRight to TopLeft?

06 Jul 2019, 20:10

Thank you Wolf, That did help out! Here's what I was able to do with your suggestion.
I'm glad to have been able to nudge you in the right direction, You made a full step out of that. Way to go. :D
But in terms of performance, teadrinker's script is miles ahead and shows us the way!!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: bobstoner289, Google [Bot], peter_ahk and 318 guests