How to get the "Rect" from a GUI text control?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
pv007
Posts: 93
Joined: 20 Jul 2020, 23:50

How to get the "Rect" from a GUI text control?

13 Jun 2021, 12:44

Code: Select all

VarSetCapacity(RECT, 16, 0)
SendMessage, % LB.GETITEMRECT, %TopIndex%, &RECT, , ahk_id %hWnd%

Txt := ...
TextColor := ...
Len := StrLen(Txt)

DllCall("Gdi32.dll\SetTextColor", "Ptr", LBDC, "UInt", TextColor)
NumPut(NumGet(RECT, 0, "Int") + 3, RECT, 0, "Int")
DllCall("User32.dll\DrawText", "Ptr", LBDC, "Ptr", &Txt, "Int", Len, "Ptr", &RECT, "UInt", 0x0840)
NumPut(NumGet(RECT, 0, "Int") - 3, RECT, 0, "Int")
DllCall("User32.dll\OffsetRect", "Ptr", &RECT, "Int", 0, "Int", This.ItemHeight)
I'm trying to adapt this code to instead get the rect of a listbox, get the rect from a GUI text control, like:

Code: Select all

Gui, Add, Text, hwndhWnd vhWnd, Ask For Help

; ----------------------------
VarSetCapacity(RECT, 16, 0)
SendMessage, ???  ???, &RECT, , ahk_id %hWnd%

How I could get it? It does need to be a Rect to I be able to use it with the following lines of code, that draw a text inside a DC
just me
Posts: 9450
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to get the "Rect" from a GUI text control?

14 Jun 2021, 04:10

Code: Select all

Gui, Add, Text, hwndhWnd vvVar, Ask For Help
; ----------------------------
VarSetCapacity(RECT, 16, 0)
DllCall("GetClientRect", "Ptr", hWnd, "Ptr", &RECT)
This will give you the rectangle as unscaled pixels.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: RussF and 374 guests