Hexadecimal Strings Topic is solved

Discuss the future of the AutoHotkey language
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Hexadecimal Strings  Topic is solved

29 Jul 2014, 05:10

[Update by Lexikos: v2.0-a050 changes functions to return HWNDs and styles as pure integers rather than as hexadecimal strings.]

Some of the Gui, Win, and Control commands are returning hexadicimal values as strings and the receiving variables are typed as "String" too, e.g.

Code: Select all

GuiColor := 0xFF0000 ; red
Gui, +LastFound
Gui, Color, % Color2Hex(GuiColor)
; Gui, Color, %GuiColor% ; doesn't work properly with v2
Gui, Font, s10
Gui, Add, Edit, w600 r10 hwndHEDT
Gui, Show, , V2 Test - %A_AhkVersion%
HGUI := WinExist()
WinGetStyle, Styles
Send, % 'Type of HGUI is "' Type(HGUI) '" and the value is ' HGUI ".`n`n"
Send, % 'Type of HEDT is "' Type(HEDT) '" and the value is ' HEDT ".`n`n"
Send, % 'Type of Styles is "' Type(Styles) '" and the value is ' Styles ".`n`n"
Send, % "Styles & 0xC00000 = 0xC00000 is " ((Styles & 0xC00000) = 0xC00000 ? 'True' : 'False') '.`n`n'
Send, % 'Type of GuiColor is "' Type(GuiColor) '" and the value is ' GuiColor '.'
Sleep, 1000
Gui, Font, cMaroon
GuiControl, Font, % (HEDT + 0)
Return
GuiClose:
GuiEscape:
ExitApp

Color2Hex(C) { ; v2
   If (Type(C) = "Integer") {
      VarSetCapacity(Hex, 7 << !!A_IsUnicode, 0)
      If (DllCall("Shlwapi.dll\wnsprintf", "Str", Hex, "Int", 7, "Str", "`%06I32X", "UInt", C & 0xFFFFFF, "Int") = 6)
         Return Hex
   }
   Return ""
}
AFAIK, hexadecimal strings are only needed for some color settings. All other cases are splendidly working with decimal integer values. If you want to use a returned hexadecimal value as a key in an associative array, you have to convert the numeric string into an integer in very most cases (e.g. Array[HEDT + 0]); otherwise you have to convert all handles returned by API calls into hexadecimal strings to match the keys.

Could this be changed, so that (at least) handles are returned as integers?
Last edited by lexikos on 19 Jun 2020, 18:48, edited 1 time in total.
Reason: update
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Hexadecimal Strings

29 Jul 2014, 08:51

At first I was gonna ask why not just use the hex string as the object key, instead of the integer for the array key. But then I realized that your problem is because of mix and matching using dllcalls which return ints and AHk's hwnds which are hex. I usually use a DecToHex() function to convert when I'm working with a win32api dllcall that is giving me a decimal hwnd instead of AHK's normal hex values. Its only a little inconvenient

just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Hexadecimal Strings

29 Jul 2014, 10:58

Hi,

you don't need to convert the integers returned by DllCalls if you want to use them as ahk_id or ControlID. The only thing that needs conversions is the use as a key in an associative array.
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Hexadecimal Strings

01 Aug 2014, 20:28

I'll consider it.

FYI, I think this is all of the affected functions/commands:
WinExist/Active
A_ScriptHwnd
ControlGet List
ControlGet Hwnd
Gui +HwndVar
GuiControlGet Hwnd
Gui Add, Type, +HwndVar
WinGet ID/IDLast
WinGet List
MouseGetPos (parent window, control with mode 2)
; Gui, Color, %GuiColor% ; doesn't work properly with v2
FYI, this is because the hexadecimal prefix is optional for colours. You should use "FF0000", not 0xFF0000.
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Hexadecimal Strings

02 Aug 2014, 03:52

SetFormat, hwnd, D
SetFormat, hwnd, H
?

just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Hexadecimal Strings

02 Aug 2014, 05:51

@guest3456: SetFormat does not exist in v2.

@lexikos: ; doesn't work properly with v2 should be read as: does work in 1.1 because the hex string is stored in the string buffer of the variable.
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Hexadecimal Strings

03 Aug 2014, 03:35

Tell me something I didn't know?
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Hexadecimal Strings

03 Aug 2014, 07:04

FYI, this is because the hexadecimal prefix is optional for colours. You should use "FF0000", not 0xFF0000.
;)

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: No registered users and 53 guests