Rückgabe eines Werts aus CbAutoComplete()

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: Rückgabe eines Werts aus CbAutoComplete()

Re: Rückgabe eines Werts aus CbAutoComplete()

Post by Johnny R » 06 Oct 2020, 08:56

Re: Rückgabe eines Werts aus CbAutoComplete()

Post by just me » 06 Oct 2020, 07:53

Hi Johnny,

ich bin davon überzeugt, dass es vergleichbare Funktionen zumindest im 'großen' Forum schon gibt. Ich habe nicht danach gesucht.

Owner ist eigentlich eine Option für den Ersatz von Gui, +OwnDialogs. Wenn ein Fenster übergeben wird, könnte man folgendes machen:

Code: Select all

	...
	If (Owner <> "")
		Gui, %Owner%:+Disabled
	Gui, InputComboBox: Show, , % (Titel = "" ? A_ScriptName : Titel)
	...
	If (Owner <> "")
		Gui, %Owner%:-Disabled
	Gui, InputComboBox: Destroy
(Nicht getestet!)

Re: Rückgabe eines Werts aus CbAutoComplete()

Post by Johnny R » 06 Oct 2020, 07:37

@just me, wenn du dein brillantes Tool nicht selbst veröffentlichst, tu ich es für dich! Dazu müßte ich allerdings noch wissen, was es mit dem Parameter "Owner" auf sich hat.

Re: Rückgabe eines Werts aus CbAutoComplete()

Post by Johnny R » 06 Oct 2020, 07:25

@just me, ich habe den Eindruck, dass dein Tool sogar schneller ist als eine InputBox. Brillant!

Re: Rückgabe eines Werts aus CbAutoComplete()

Post by just me » 05 Oct 2020, 11:13

MakeLong() und MakeShort() sind nur ein Ersatz für von Microsoft bereitgestellte Makros zur Behandlung von zwei in einem 4-Byte Wert gespeicherten 2-Byte Werten. Man kann das - wie gezeigt - auch händisch erledigen.

Re: Rückgabe eines Werts aus CbAutoComplete()

Post by Johnny R » 05 Oct 2020, 11:06

@Just me, wunderbar! Hervorragend! Jetzt läuft es auch mit der Ansi-Version von AHK! Wie hast du das gemacht? Die urprünglich vorhandenen Funktionen makelong() und makeshort() fehlen auch. Kann man darauf verzichten? Wie oben schon einmal gesagt: Du bist ein Genie. Viele Grüße und vielen Dank!

Re: Rückgabe eines Werts aus CbAutoComplete()

Post by just me » 05 Oct 2020, 10:02

Danke, ich konnte das jetzt nachvollziehen. Aus mir unklaren Gründen liefert EM_GETEDITSEL in der ANSI-Version andere Werte. Das führt dazu, dass das zuletzt eingegebene Zeichen ausgewählt und deshalb mit dem nächsten Zeichen überschrieben wird. Mit folgender Änderung in CbAutoComplete() scheint es in beiden Versionen zu laufen:

Code: Select all

;=======================================================================================
;
; Function:      CbAutoComplete
; Description:   Auto-completes typed values in a ComboBox.
;
; Author:        Pulover [Rodolfo U. Batista]   (modified by just me 202010029
; Usage:         Call the function from the Combobox's gLabel.
;
;=======================================================================================
CbAutoComplete(HCBB) {
   ; CB_GETEDITSEL = 0x0140, CB_SETEDITSEL = 0x0142
   Local
   If ((GetKeyState("Delete", "P")) || (GetKeyState("Backspace", "P")))
      Return
   ; GuiControlGet, lHwnd, Hwnd, %A_GuiControl%
   SendMessage, 0x0140, 0, 0, , ahk_id %HCBB%
   Start := ErrorLevel & 0xFFFF
   GuiControlGet, CurContent, , %HCBB%, Text
   GuiControl, ChooseString, %HCBB%, %CurContent%
   If (ErrorLevel)
      GuiControl, Text, %HCBB%, %CurContent%
   Else
      GuiControlGet, CurContent, , %HCBB%
   Sel := Start | (StrLen(CurContent) << 16)
   PostMessage, 0x0142, 0, Sel, , ahk_id %HCBB%
}

Re: Rückgabe eines Werts aus CbAutoComplete()

Post by Johnny R » 05 Oct 2020, 07:07

@Just me, Jetzt habe ich den Wurm entdeckt: Das Tool funktioniert nicht mit der Ansi-Version, sondern nur mit der AHK-Unicode-Version, warum auch immer! Ich habe jetzt mal die Unicode-Version von AHK_H installiert und warte gespannt ab, wo ggf. Probleme ggü. meiner früheren Ansi-Version auftreten. Am besten wäre natürlich, wenn dein Tool auch unter der Ansi-Version liefe...

Ich danke vielmals für deine große und erfolgreiche Mühe! Willst Du dein Tool nicht in der internationalen Script-Abteilung unterbringen?

Re: Rückgabe eines Werts aus CbAutoComplete()

Post by Johnny R » 05 Oct 2020, 06:42

@Just me, auch das bringt leider kein Änderung, bzw. Besserung, vgl. A_AhkVersion:

Code: Select all

---------------------------
Ver.ahk
---------------------------
1.1.33.02
---------------------------
OK   
---------------------------

Re: Rückgabe eines Werts aus CbAutoComplete()

Post by just me » 05 Oct 2020, 03:03

Johnny R wrote:
04 Oct 2020, 11:50
... Ich benutze AHK_H v1.1.32.0, Ansi 32-bit, vom 2.5.2020, 16:25 Uhr
Dann lass es doch einmal mit AHK_L laufen. Wenn es damit auch bei Dir funktioniert, musst Du Dich wohl an @HotKeyIt wenden.

Re: Rückgabe eines Werts aus CbAutoComplete()

Post by Johnny R » 04 Oct 2020, 11:50

Ich habe jetzt alles geschlossen, was mit AHK zu tun hat. Keine Änderung! Ich benutze AHK_H v1.1.32.0, Ansi 32-bit, vom 2.5.2020, 16:25 Uhr

Re: Rückgabe eines Werts aus CbAutoComplete()

Post by just me » 04 Oct 2020, 11:41

Das weiß ich noch nicht. Z.Zt. verstehe ich noch nicht, was da bei Dir abläuft. Ist das wirklich dein komplettes Sript oder hast Du noch irgendwo irgendwelche OnMessage() Funktionen?

Re: Rückgabe eines Werts aus CbAutoComplete()

Post by Johnny R » 04 Oct 2020, 11:24

Das verstehe, wer will, ich nicht! Bei mir tut sich folgendes, wobei jeweils immer nur der zuletzt eingegebene Buchstabe stehen bleibt und die ersteren gelöscht werden:
Spoiler
Kannst du da schlau werden?

Re: Rückgabe eines Werts aus CbAutoComplete()

Post by just me » 04 Oct 2020, 11:06

:roll:

Wenn ich Dein Skript starte, dann Lila in das Editfeld der Combobox tippe und dann den Ok Button auslöse, sehe ich:

Code: Select all

---------------------------
Ergebnis
---------------------------
Auswahl: Lila
ErrorLevel: 0
---------------------------
OK   
---------------------------

Re: Rückgabe eines Werts aus CbAutoComplete()

Post by Johnny R » 04 Oct 2020, 10:58

@Just me, bei mir klappt das leider nicht, z. B. wenn ich in deine Farbenliste die Farbe "Lila" eingeben will. Hier ist mein Code:

Code: Select all

#NoEnv
#SingleInstance Force
;Suchmuster := "D:\AutoHotkey\AHK_L\*.ahk"
;Suchmuster := "C:\Windows\System32\*.*"
Dateien := ""
;Loop, Files, %Suchmuster%
;   Dateien .= A_LoopFileName . "|"
Dateien := "Blau||Braun|Gelb|Grau|Grün|Rot|Schwarz|Weiß"
Dateien := RTrim(Dateien, "|")

Auswahl := InputComboBox(Dateien)
MsgBox, 0, Ergebnis, Auswahl: %Auswahl%`nErrorLevel: %ErrorLevel%
Return ; Statt ExitApp

InputComboBox(AuswahlListe, Hinweis := "Bitte wählen:", Titel := "", Owner := "") {
   Local
      Selection := ""
      Cancelled := 0
      Gui, InputComboBox: +hwndHGUI -MinimizeBox +Owner%Owner%
      Gui, InputComboBox: Margin, 10, 10
      Gui, InputComboBox: Add, Text, w300, %Hinweis%
      Gui, InputComboBox: Add, Combobox, xm y+5 w300 gCbAutoComplete hwndHCBB, %AuswahlListe%
      Gui, InputComboBox: Add, Button, xm Default hwndHBT1 gInputComboBoxBtnOK, OK
      GuiControlGet, P1, Pos, %HBT1%
      Gui, InputComboBox: Add, Button, x+m hwndHBT2 gInputComboBoxBtnCancel, Abbrechen
      GuiControlGet, P2, Pos, %HBT2%
      GuiControl, Move, %HBT1%, % "w" . P2W
      GuiControl, Move, %HBT2%, % "x" . (310 - P2W)
      Gui, InputComboBox: Show, , % (Titel = "" ? A_ScriptName : Titel)
      WinWaitClose, ahk_id %HGUI%
      ErrorLevel := Cancelled
   Return ErrorLevel>0 ?: Selection ; Bei "Abbrechen" wird ein Leerstring returniert.
   ;Return Selection

   InputComboBoxGuiEscape:
   InputComboBoxGuiClose:
   InputComboBoxBtnCancel:
   Gui, Destroy
   ;ExitApp
   Return

   InputComboBoxBtnOK:
      GuiControlGet, Selection, , %HCBB%
      Gui, Destroy
      Cancelled := (A_ThisLabel = "InputComboBoxBtnOK" ? 0 : 1)
  Return
}
;=======================================================================================
;
; Function:      CbAutoComplete
; Description:   Auto-completes typed values in a ComboBox.
;
; Author:        Pulover [Rodolfo U. Batista]   (modified by just me 202010029
; Usage:         Call the function from the Combobox's gLabel.
;
;=======================================================================================
CbAutoComplete(HCBB) {
   ; CB_GETEDITSEL = 0x0140, CB_SETEDITSEL = 0x0142
   Local
   If ((GetKeyState("Delete", "P")) || (GetKeyState("Backspace", "P")))
      Return
   ; GuiControlGet, lHwnd, Hwnd, %A_GuiControl%
   SendMessage, 0x0140, 0, 0, , ahk_id %HCBB%
   MakeShort(ErrorLevel, Start, End)
   GuiControlGet, CurContent, , %HCBB%
   GuiControl, ChooseString, %HCBB%, %CurContent%
   If (ErrorLevel) {
      GuiControl, Text, %HCBB%, %CurContent%
      PostMessage, 0x0142, 0, MakeLong(Start, End), , ahk_id %HCBB%
   }
   Else {
      GuiControlGet, CurContent, , %HCBB%
      PostMessage, 0x0142, 0, MakeLong(Start, StrLen(CurContent)), , ahk_id %HCBB%
   }
}
;---------------------------------------------------------------------------------------
MakeLong(LoWord, HiWord) {
	return (HiWord << 16) | (LoWord & 0xffff)
}
;---------------------------------------------------------------------------------------
MakeShort(Long, ByRef LoWord, ByRef HiWord) {
	LoWord := Long & 0xffff
,   HiWord := Long >> 16
}

Re: Rückgabe eines Werts aus CbAutoComplete()

Post by just me » 04 Oct 2020, 03:06

Hallo Johnny,

ich habe mit einer solchen Auswahlliste

Code: Select all

AuswahlListe := "Blau||Braun|Gelb|Grau|Grün|Rot|Schwarz|Weiß"
und der Eingabe von nicht in der Liste enthaltenen Zeichenketten kein Problem. Wenn das bei Dir so ist, stell bitte mal Deinen aktuellen Code ein.

Re: Rückgabe eines Werts aus CbAutoComplete()

Post by Johnny R » 03 Oct 2020, 08:30

Hallo just me, ich glaube, ich glaube, ich bleibe lieber bei deiner ursprünglichen Lösung incl. Cancelled.

Jetzt stelle ich beim weiteren Testen aber fest, dass das Tool an einer Stelle nicht so funktioniert, wie ich das gerne hätte. Der Pipe-getrennte String sollte dem Anwender nur Vorschläge für die Eingabe liefern, aber nicht zwingen, einen dieser Vorschläge auszuwählen. Daneben sollte es möglich sein, die Vorschläge mit einem völlig willkürlichen, x-beliebigen, String zu überschreiben, der nicht in der Pipe-Liste enthalten ist, also z. B. mit "Hallo Welt" oder "Tag der deutschen Einheit" etc. Ich fürchte, dass das Pulovers Funktion nicht zuläßt, stimmts? Viele Grüße!

Re: Rückgabe eines Werts aus CbAutoComplete()

Post by just me » 03 Oct 2020, 05:02

Moin Johnny,

auch wenn es Dich sehr enttäuschen sollte, ich bin keine KI. Ich muss auf die gute alte Art meine grauen Zellen auspressen, wenn ich programmiere. ;)

Code: Select all

   InputComboBoxGuiClose:
   InputComboBoxBtnCancel:
   InputComboBoxBtnOK:
      GuiControlGet, Selection, , %HCBB%
      Gui, Destroy
      Cancelled := (A_ThisLabel = "InputComboBoxBtnOK" ? 0 : 1)
  Return
Diese Codesequenz habe ich gewählt, um das Verhalten einer InputBox zu imitieren:
Fehlerbehandlung

[v1.1.04+]: Dieser Befehl ist in der Lage, bei Misserfolg eine Ausnahme auszulösen. Weitere Informationen finden Sie unter Laufzeitfehler.

ErrorLevel wird auf 1 gesetzt, wenn der Benutzer die CANCEL-Schaltfläche gedrückt hat, auf 0, wenn der Benutzer OK gedrückt hat, oder auf 2, wenn das Dialogfenster die Zeit überschritten hat. In allen drei Fällen wird AusgabeVar auf den eingegebenen Wert gesetzt. Auf diese Weise kann die CANCEL-Schaltfläche neben Abbrechen noch andere Funktionen ausführen, falls der Skript-Entwickler das wünscht.

Wenn Du nur bei Klick auf OK etwas zurückgeben willst, würde ich das so machen:

Code: Select all

   InputComboBoxBtnOK:
      GuiControlGet, Selection, , %HCBB%
   InputComboBoxBtnCancel:
   InputComboBoxGuiClose:
   InputComboBoxGuiEscape:
      Gui, Destroy
  Return
Die Variable Cancelled wird dann nicht mehr benötigt und die Zeilen, in denen sie angesprochen wird, können entfernt werden.

Re: Rückgabe eines Werts aus CbAutoComplete()

Post by Johnny R » 02 Oct 2020, 11:58

@KHA, vielen Dank! Ich habe jetzt nach InputComboBoxBtnCancel: Gui, Destroy statt ExitApp geskriptet. Jetzt läuft das Skript wunderbar. Zur Kontrolle zeige ich mein Skript mit den (aus-)kommentierten Änderungen:

Code: Select all

#NoEnv
#SingleInstance Force
;Suchmuster := "D:\AutoHotkey\AHK_L\*.ahk"
Suchmuster := "C:\Windows\System32\*.*"
Dateien := ""
Loop, Files, %Suchmuster%
   Dateien .= A_LoopFileName . "|"
Dateien := RTrim(Dateien, "|")

Auswahl := InputComboBox(Dateien)
MsgBox, 0, Ergebnis, Auswahl: %Auswahl%`nErrorLevel: %ErrorLevel%
Return ; Statt ExitApp

InputComboBox(AuswahlListe, Hinweis := "Bitte wählen:", Titel := "", Owner := "") {
   Local
      Selection := ""
      Cancelled := 0
      Gui, InputComboBox: +hwndHGUI -MinimizeBox +Owner%Owner%
      Gui, InputComboBox: Margin, 10, 10
      Gui, InputComboBox: Add, Text, w300, %Hinweis%
      Gui, InputComboBox: Add, Combobox, xm y+5 w300 gCbAutoComplete hwndHCBB, %AuswahlListe%
      Gui, InputComboBox: Add, Button, xm Default hwndHBT1 gInputComboBoxBtnOK, OK
      GuiControlGet, P1, Pos, %HBT1%
      Gui, InputComboBox: Add, Button, x+m hwndHBT2 gInputComboBoxBtnCancel, Abbrechen
      GuiControlGet, P2, Pos, %HBT2%
      GuiControl, Move, %HBT1%, % "w" . P2W
      GuiControl, Move, %HBT2%, % "x" . (310 - P2W)
      Gui, InputComboBox: Show, , % (Titel = "" ? A_ScriptName : Titel)
      WinWaitClose, ahk_id %HGUI%
      ErrorLevel := Cancelled
   Return ErrorLevel>0 ?: Selection ; Bei "Abbrechen" wird ein Leerstring returniert.
   ;Return Selection

   InputComboBoxGuiEscape:
   InputComboBoxGuiClose:
   InputComboBoxBtnCancel:
   Gui, Destroy
   ;ExitApp
   Return

   InputComboBoxBtnOK:
      GuiControlGet, Selection, , %HCBB%
      Gui, Destroy
      Cancelled := (A_ThisLabel = "InputComboBoxBtnOK" ? 0 : 1)
  Return
}
;=======================================================================================
;
; Function:      CbAutoComplete
; Description:   Auto-completes typed values in a ComboBox.
;
; Author:        Pulover [Rodolfo U. Batista]   (modified by just me 202010029
; Usage:         Call the function from the Combobox's gLabel.
;
;=======================================================================================
CbAutoComplete(HCBB) {
   ; CB_GETEDITSEL = 0x0140, CB_SETEDITSEL = 0x0142
   Local
   If ((GetKeyState("Delete", "P")) || (GetKeyState("Backspace", "P")))
      Return
   ; GuiControlGet, lHwnd, Hwnd, %A_GuiControl%
   SendMessage, 0x0140, 0, 0, , ahk_id %HCBB%
   MakeShort(ErrorLevel, Start, End)
   GuiControlGet, CurContent, , %HCBB%
   GuiControl, ChooseString, %HCBB%, %CurContent%
   If (ErrorLevel) {
      GuiControl, Text, %HCBB%, %CurContent%
      PostMessage, 0x0142, 0, MakeLong(Start, End), , ahk_id %HCBB%
   }
   Else {
      GuiControlGet, CurContent, , %HCBB%
      PostMessage, 0x0142, 0, MakeLong(Start, StrLen(CurContent)), , ahk_id %HCBB%
   }
}
;---------------------------------------------------------------------------------------
MakeLong(LoWord, HiWord) {
	return (HiWord << 16) | (LoWord & 0xffff)
}
;---------------------------------------------------------------------------------------
MakeShort(Long, ByRef LoWord, ByRef HiWord) {
	LoWord := Long & 0xffff
,   HiWord := Long >> 16
}

Re: Rückgabe eines Werts aus CbAutoComplete()

Post by KHA » 02 Oct 2020, 11:23

Escape oder klick auf Abbrechen Button oder Fenster schließen, beenden den Script

Code: Select all

#NoEnv
#SingleInstance Force
Suchmuster := "D:\AutoHotkey\AHK_L\*.ahk"
Dateien := ""
Loop, Files, %Suchmuster%
   Dateien .= A_LoopFileName . "|"
Dateien := RTrim(Dateien, "|")

Auswahl := InputComboBox(Dateien)
MsgBox, 0, Ergebnis, Auswahl: %Auswahl%`nErrorLevel: %ErrorLevel%
ExitApp

InputComboBox(AuswahlListe, Hinweis := "Bitte wählen:", Titel := "", Owner := "") {
   Local
      Selection := ""
      Cancelled := 0
      Gui, InputComboBox: +hwndHGUI -MinimizeBox +Owner%Owner%
      Gui, InputComboBox: Margin, 10, 10
      Gui, InputComboBox: Add, Text, w300, %Hinweis%
      Gui, InputComboBox: Add, Combobox, xm y+5 w300 gCbAutoComplete hwndHCBB, %AuswahlListe%
      Gui, InputComboBox: Add, Button, xm Default hwndHBT1 gInputComboBoxBtnOK, OK
      GuiControlGet, P1, Pos, %HBT1%
      Gui, InputComboBox: Add, Button, x+m hwndHBT2 gInputComboBoxBtnCancel, Abbrechen
      GuiControlGet, P2, Pos, %HBT2%
      GuiControl, Move, %HBT1%, % "w" . P2W
      GuiControl, Move, %HBT2%, % "x" . (310 - P2W)
      Gui, InputComboBox: Show, , % (Titel = "" ? A_ScriptName : Titel)
      WinWaitClose, ahk_id %HGUI%
      ErrorLevel := Cancelled
   Return Selection

   InputComboBoxGuiEscape:
   InputComboBoxGuiClose:
   InputComboBoxBtnCancel:
   ExitApp
   Return

   InputComboBoxBtnOK:
      GuiControlGet, Selection, , %HCBB%
      Gui, Destroy
      Cancelled := (A_ThisLabel = "InputComboBoxBtnOK" ? 0 : 1)
  Return
}
;=======================================================================================
;
; Function:      CbAutoComplete
; Description:   Auto-completes typed values in a ComboBox.
;
; Author:        Pulover [Rodolfo U. Batista]   (modified by just me 202010029
; Usage:         Call the function from the Combobox's gLabel.
;
;=======================================================================================
CbAutoComplete(HCBB) {
   ; CB_GETEDITSEL = 0x0140, CB_SETEDITSEL = 0x0142
   Local
   If ((GetKeyState("Delete", "P")) || (GetKeyState("Backspace", "P")))
      Return
   ; GuiControlGet, lHwnd, Hwnd, %A_GuiControl%
   SendMessage, 0x0140, 0, 0, , ahk_id %HCBB%
   MakeShort(ErrorLevel, Start, End)
   GuiControlGet, CurContent, , %HCBB%
   GuiControl, ChooseString, %HCBB%, %CurContent%
   If (ErrorLevel) {
      GuiControl, Text, %HCBB%, %CurContent%
      PostMessage, 0x0142, 0, MakeLong(Start, End), , ahk_id %HCBB%
   }
   Else {
      GuiControlGet, CurContent, , %HCBB%
      PostMessage, 0x0142, 0, MakeLong(Start, StrLen(CurContent)), , ahk_id %HCBB%
   }
}
;---------------------------------------------------------------------------------------
MakeLong(LoWord, HiWord) {
	return (HiWord << 16) | (LoWord & 0xffff)
}
;---------------------------------------------------------------------------------------
MakeShort(Long, ByRef LoWord, ByRef HiWord) {
	LoWord := Long & 0xffff
,   HiWord := Long >> 16
}

Top