Array mit hexadezimalen Inhalt

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Array mit hexadezimalen Inhalt

Re: Array mit hexadezimalen Inhalt

Post by just me » 09 Oct 2013, 08:15

Hallo holle,

da ist nichts falsch:
MsgBox wrote:---------------------------
Test.ahk
---------------------------
control = Edit2
Array[zielcontrol] = 0x707b4
hfarben = 0x607a8
---------------------------
OK
---------------------------
In der Variablen control hast Du die ClassNN des Editfeldes, und das hat eine eigene/andere HWND. Genau deshalb musst DU Dir mit GetComboBoxInfo() alle drei HWNDs holen, die den Komponenten der ComboBox zugeordnet sind.

Re: Array mit hexadezimalen Inhalt

Post by Holle » 09 Oct 2013, 07:18

@just me
Ich bekomme das nun auch nicht mehr hin. Habe alle möglichen Varianten probiert die mir eingefallen sind, aber ich kann das Problem nicht mehr rekonstruieren.
Nun habe ich aber vielleicht den Grund gefunden warum das nicht geklappt hatte. Der Grund war anscheinend garnicht dass das hwnd nicht "akzeptiert" wurde, sondern dass es einfach "falsch" war.
Ich habe hier mal ein Beispiel-Script. Mit dem auskommentierten Teil funzt es, wenn ich das "entkommentiere" ist das hwnd für die mittlere CB (farben) falsch.
Kann sein dass dieses der Grund war, warum es nicht funktioniert hat, aber sicher kann ich das auch nicht mehr sagen da ich das Test-Script schon überschrieben habe.
Also, hier ist das "neue" Test-Script:

Code: Select all

Gui, Add, Text, w100 center vZahlen
Gui, add, ComboBox, w90 x20 r5 gStart, Eins|Zwei|Drei|Vier|Fünf
Gui, Add, Text, x10 y+20,-------------------------------------
Gui, Add, Text, w100 center vFarben
Gui, add, ComboBox, w90 x20 r5 gStart, Rot|Grün|Blau|Weiß|Gelb
Gui, Add, Text, x10 y+20 ,-------------------------------------
Gui, Add, Text, w100 center vStaedte
Gui, add, ComboBox, w90 x20 r5 gStart, Berlin|Bonn|München|Hamburg|Bremen
Gui, show, ,test

GuiControlGet, zahlen, Hwnd
GuiControlGet, farben, Hwnd
GuiControlGet, staedte, Hwnd
array := Object("zahlen", zahlen, "farben", farben, "staedte", staedte)

OnMessage(0x201, "start") ; WM_LBUTTONDOWN
return

start()
{
	global array
start:
	ControlGetFocus, control, A
	if !A_GuiControl
		MouseGetPos, , , , control, 1
	if A_GuiControl in Eins,Zwei,Drei,Vier,Fünf
		zielcontrol := "Zahlen"
	else if A_GuiControl in Rot,Grün,Blau,Weiß,Gelb
		zielcontrol := "Farben"	
	else if A_GuiControl in Berlin,Bonn,München,Hamburg,Bremen
		zielcontrol := "Staedte"
	else 
		return
	;~ if (zielcontrol = "farben")
	;~ {
		;~ ControlGet, hfarben, Hwnd,, %control%, A
		;~ MsgBox % "control = " control "`nArray[zielcontrol] = " array[zielcontrol]  "`nhfarben = " hfarben
		;~ GuiControl,, % hfarben, % Array[zielcontrol] " - " A_GuiControl
	;~ }
	;~ else
		GuiControl,, % Array[zielcontrol], % Array[zielcontrol] " - " A_GuiControl
return
}

GuiClose:
ExitApp

Wozu ich es brauch(t)e:
Ich habe es immer noch nicht aufgegeben die Sache mit den DDL/CB wechsel zu realisieren. Nun bin ich das auf verschiedene Wege angegangenund habe dabei festgestellt dass die hwnds mal dezimal und mal hexadezimal waren. Deswegen wollte ich die einheitlich hexadezimal speichern, um sicherzustellen dass die eindeutig zugeordnet werden (und nicht doppelt geführt werden).
Das hat sich zwischenzeitlich aber erledigt, da es kein Problem ist einen Array-Eintrag mit einem hexadezimalen Schlüssel auszulesen, welcher jedoch dezimal gespeichert ist.

Re: Array mit hexadezimalen Inhalt

Post by HotKeyIt » 08 Oct 2013, 13:34

Dafür eignet sich format() aus AutoHotkey v2 am besten:

Code: Select all

MsgBox % format("0x{1:X}",100)

; Modified for AutoHotkey 1.1++ from AutoHotkey v2 alpha

; format(format_string, ...)
;   Equivalent to format_v(format_string, Array(...))
format(f, v*) {
    return format_v(f, v)
}

; format_v(format_string, values)
;   - format_string:
;       String of literal text and placeholders, as described below.
;   - values:
;       Array or map of values to insert into the format string.
;
; Placeholder format: "{" id ":" format "}"
;   - id:
;       Numeric or string literal identifying the value in the parameter
;       list.  For example, {1} is values[1] and {foo} is values["foo"].
;   - format:
;       A format specifier as accepted by printf but excluding the
;       leading "%".  See "Format Specification Fields" at MSDN:
;           http://msdn.microsoft.com/en-us/library/56e442dc.aspx
;       The "*" width specifier is not supported, and there may be other
;       limitations.
;
; Examples:
;   MsgBox % format("0x{1:X}", 4919)
;   MsgBox % format("Computation took {2:.9f} {1}", "seconds", 3.2001e-5)
;   MsgBox % format_v("chmod {mode:o} {file}", {mode: 511, file: "myfile"})
;
format_v(f, v)
{
    VarSetCapacity(arg, 8), j := 1, VarSetCapacity(s, StrLen(f)*1.2)  ; Arbitrary estimate.
    while i := RegExMatch(f, "(.*?)\K\{(\w+)(?::([^`%}]*))?\}", m, j)  ; For each {placeholder}.
    {
        j := i + StrLen(m), out .= m1  ; Calc next search pos; append literal text preceding '{'.
        if !v.HasKey(m2+0="" ? m2 : m2+=0) {  ; m2+=0 to convert to pure integer if m2+0!="".
            out .= m  ; Append original {} string to show the error.
            continue
        }
        if !m3 {
            out .= v[m2]  ; No format specifier, so just output the value.
            continue
        }
        if (type := SubStr(m3,StrLen(m3))) = "s"
            NumPut((p := v.GetAddress(m2)) ? p : &(s := v[m2] ""), arg)
        else if InStr("cdioux", type)  ; Integer types.
            NumPut(v[m2], arg, "int64") ; 64-bit in case of something like {1:I64i}.
        else if InStr("efga", type)  ; Floating-point types.
            NumPut(v[m2], arg, "double")
        else if (type = "p")  ; Pointer type.
            NumPut(v[m2], arg)
        else {  ; Note that this doesn't catch errors like "{1:si}".
            out .= m  ; Output m unaltered to show the error.
            continue
        }
        if (c := DllCall("msvcrt\_vscwprintf", "str", "`%" m3, "ptr", &arg)) >= 0  ; Determine required buffer size.
          && DllCall("msvcrt\_vsnwprintf", "str", buf, "ptr", VarSetCapacity(buf, ++c*2)//2, "str", "`%" m3, "ptr", &arg) >= 0 {  ; Format string into buf.
            out .= buf  ; Append formatted string.
            continue
        }
    }
    out .= SubStr(f, j)  ; Append remainder of format string.
    return out
}

Re: Array mit hexadezimalen Inhalt

Post by just me » 08 Oct 2013, 10:37

Wenn ich einen Hwnd in einen Array speichere und diesen dann aus dem Array heraus aufrufe, dann passiert nichts.
Ich habe das Test-Script leider schon überschrieben, aber soweit ich mich erinnere hatte ich in dem Array die hwnd gespeichert und dann in etwa so aufgerufen ...
Genau das bekomme ich nicht hin:

Code: Select all

#NoEnv
Gui, Margin, 20, 20
Gui, Add, Text, w400 h400 hwndHTX
GuiControl, , %HTX%, %HTX%
MyArray := [HTX + 0]
Gui, Show, , HWND
Sleep, 2000
HTX += 0
GuiControl, , %HTX%, %HTX%
Sleep, 2000
GuiControl, , % MyArray.1, % MyArray.1 . " mit Array"
Sleep, 2000
HTX := MyArray.1
GuiControl, , %HTX%, %HTX% aus array
Return
GuiClose:
ExitApp
Edit: Das geht natürlich knapp am Thema vorbei. Ich weiß jetzt auch wieder, was ich eigentlich fragen wollte: Wofür brauchst Du die Hexadezimaldarstellung?

Re: Array mit hexadezimalen Inhalt

Post by Holle » 08 Oct 2013, 10:21

just me wrote:
Und wenn ich den Wert in "" setze, dann funktioniert z.B. ein hwnd nicht mehr.
Kannst Du das näher beschreiben?
Wenn ich einen Hwnd in einen Array speichere und diesen dann aus dem Array heraus aufrufe, dann passiert nichts.
Ich habe das Test-Script leider schon überschrieben, aber soweit ich mich erinnere hatte ich in dem Array die hwnd gespeichert und dann in etwa so aufgerufen:

Code: Select all

cbhwnd := array[name].CBhwnd
GuiControlGet, Pos, %WindowHwnd%:Pos, %cbhwnd%
Hatte ich die hwnd direkt in das array gespeichert (dann war das dezimal), hat alles geklappt. Wenn ich das vorher auf die oben beschriebene Art (mit "") im hexadezimalen Format ins Array gespeichert hatte, funktionierte der hwnd nicht mehr.
Wie das genau war weiß ich leider nicht mehr.
Ich hatte das anders gelöst und da es bei der "if-prüfung" egal war hatte ich das anders gelöst.
Beispiel:

Code: Select all

wert1 := 12345
Wert2 := "0x3039"
if (wert1 = wert2)
	MsgBox Es ist beides gleich
Es ist nicht egal, wenn es im ArrayNamen in "" verwendet wird, aber ohne "" ist es egal.
Hier ist ein Beispiel was ich meine:

Code: Select all

array := {}
Array[12345] := 1
Array[0x3039] := 2
MsgBox % "Array[12345] = "Array[12345] " <--- Klappt"

array := {}
Array["12345"] := 1
Array["0x3039"] := 2
MsgBox % "Array[""12345""] = "Array["12345"] " <--- Klappt nicht"

Re: Array mit hexadezimalen Inhalt

Post by hd0202 » 04 Oct 2013, 03:11

Ich würde es so speichern:

Code: Select all

test := {hwnd: Hwnd , hexWert: ""hexWert}
Hubert

Re: Array mit hexadezimalen Inhalt

Post by just me » 04 Oct 2013, 00:24

Guten Morgen,

ich gehe mal davon aus, dass Du die Hexwerte, die nicht von AHK-Anweisungen als Hex-String geliefert werden, selbst aufbaust. Dann sollte es reichen, den Wert als String ("0x12345") und nicht als hexadizimalen Integerwert (0x12345) zu speichern:

Code: Select all

Hwnd := WinExist("A")
hexWert := "0x12345"
MsgBox Vorher:`nhwnd ist ein hexadezimaler Wert --> %hwnd%`nhexWert ist auch ein hexadezimaler Wert --> %hexWert%

test := {hwnd: Hwnd , hexWert: hexWert}
MsgBox % "Nachher`nhwnd ist immer noch hexadezimal --> "test.hwnd "`nhexWert ist nun dezimal --> " test.hexWert " ...doch WARUM?"
MsgBox, % hexWert . " = " . (hexWert + 0)
Und wenn ich den Wert in "" setze, dann funktioniert z.B. ein hwnd nicht mehr.
Kannst Du das näher beschreiben?

Re: Array mit hexadezimalen Inhalt

Post by Holle » 03 Oct 2013, 23:49

Klar, mit SetFormat und "+0" kann ich die Zahlen konvertieren. Ich hatte jedoch die Hoffnung dass es irgendwie anders lösbar ist.
Wenn ich vor dem füllen des Arrays "SetFormat, Integerfast, D" benutze wird der Wert auch hexadezimal gespeichert, aber leider auch alle anderen Werte in dem Array werden somit hexadezimal. Das Array selber kommt mit "Mischformatierung" zurecht, das sieht man im Beispielscript, in dem ein Wert hexadezimal bleibt und der andere Wert ins dezimale konvertiert wird.

Aber OK, wenn man das nicht ändern kann muss ich es so akzeptieren.

Re: Array mit hexadezimalen Inhalt

Post by nnnik » 02 Oct 2013, 05:30

Das hängt mit den Internas von Autohotkey zusammen.
Für näheres müsste ich mich in die nicht ganz einfache variablen verwaltung einlesen.
BTW "0xFFFFF"+0 = Ja richtig eine Zahl.

Re: Array mit hexadezimalen Inhalt

Post by Holle » 02 Oct 2013, 05:22

Vielen Dank, aber das hilft mir leider nicht weiter.
Wenn ich SetFormat nutze werden auch andere Werte in hexadezimale umgewandelt, welche ich in das Array speichere, welche ich jedoch nicht umgewandelt haben will.
Und wenn ich den Wert in "" setze, dann funktioniert z.B. ein hwnd nicht mehr.

...und warum wird "ein Wert" umgewandelt und der "andere" nicht?

Re: Array mit hexadezimalen Inhalt

Post by Seidenweber » 02 Oct 2013, 04:33

General Remarks
If SetFormat is not used in a script, integers default to decimal format, and floating point numbers default to TotalWidth.DecimalPlaces = 0.6. Every newly launched thread (such as a hotkey, custom menu item, or timed subroutine) starts off fresh with these defaults; but the defaults may be changed by using SetFormat in the auto-execute section (top part of the script).
Also entweder das, oder

Code: Select all

hexWert := "0x12345"

Re: Array mit hexadezimalen Inhalt

Post by nnnik » 02 Oct 2013, 02:05

Wenn du willst, dass es Hexadezimal dargestellt wird musst du SetFormat benutzen.
Warum es so ist wie es ist weiß ich auch nicht genau.

Array mit hexadezimalen Inhalt

Post by Holle » 02 Oct 2013, 00:00

Warum wird im Array aus einem hexadezimalen Wert ein dezimaler Wert, während ein anderer hexadezimaler Wert hexadezimal bleibt?

Hier ist ein Test-Script...

Code: Select all

Hwnd := WinExist("A")
hexWert := 0x12345
MsgBox Vorher:`nhwnd ist ein hexadezimaler Wert --> %hwnd%`nhexWert ist auch ein hexadezimaler Wert --> %hexWert%

test := {hwnd: Hwnd , hexWert: hexWert}
MsgBox % "Nachher`nhwnd ist immer noch hexadezimal --> "test.hwnd "`nhexWert ist nun dezimal --> " test.hexWert " ...doch WARUM?"

Top