Rückgabe eines Werts aus CbAutoComplete() Topic is solved

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

Johnny R
Posts: 348
Joined: 03 Oct 2013, 02:07

Rückgabe eines Werts aus CbAutoComplete()

27 Sep 2020, 12:25

Hi Folks, lacht mich ruhig aus, mit meiner folgenden doofen Frage:

Ich habe aus unserem internationalen Teil – hier – folgende Funktion:

Code: Select all

#SingleInstance Force
;#Include ..\CbAutoComplete.ahk
Loop, Files, C:\Windows\System32\*.*
	List .= A_LoopFileName "|"
Gui, Add, Combobox, W300 gAutoComplete, %List%
Gui, Show,, CbAutoComplete Demo
return

AutoComplete:
CbAutoComplete()
return


;=======================================================================================
;
; Function:      CbAutoComplete
; Description:   Auto-completes typed values in a ComboBox.
;
; Author:        Pulover [Rodolfo U. Batista]
; Usage:         Call the function from the Combobox's gLabel.
;
;=======================================================================================
CbAutoComplete()
{	; CB_GETEDITSEL = 0x0140, CB_SETEDITSEL = 0x0142
	If ((GetKeyState("Delete", "P")) || (GetKeyState("Backspace", "P")))
		return
	GuiControlGet, lHwnd, Hwnd, %A_GuiControl%
	SendMessage, 0x0140, 0, 0,, ahk_id %lHwnd%
	MakeShort(ErrorLevel, Start, End)
	GuiControlGet, CurContent,, %lHwnd%
	GuiControl, ChooseString, %A_GuiControl%, %CurContent%
	If (ErrorLevel)
	{
		ControlSetText,, %CurContent%, ahk_id %lHwnd%
		PostMessage, 0x0142, 0, MakeLong(Start, End),, ahk_id %lHwnd%
		return
	}
	GuiControlGet, CurContent,, %lHwnd%
	PostMessage, 0x0142, 0, MakeLong(Start, StrLen(CurContent)),, ahk_id %lHwnd%
}

MakeLong(LoWord, HiWord)
{
	return (HiWord << 16) | (LoWord & 0xffff)
}

MakeShort(Long, ByRef LoWord, ByRef HiWord)
{
	LoWord := Long & 0xffff
,   HiWord := Long >> 16
}
Wie kann ich in die GUI eine OK-Schaltfläche (ggf. auch einen ESC-Button) hinzufügen, die mir beim Schließen des GUI die getätigte Auswahl in eine Variable speichert, mit der ich dann weiter arbeiten kann? Ja, lacht nur, aber bitte, beantwortet meine doofe Frage...
KHA
Posts: 400
Joined: 21 Aug 2018, 11:11

Re: Rückgabe eines Werts aus CbAutoComplete()  Topic is solved

27 Sep 2020, 13:40

Ich weiß es nicht, ob ich dich richtig verstanden habe.
versuch mal so:

Code: Select all

#SingleInstance Force
;#Include ..\CbAutoComplete.ahk
Loop, Files, C:\Windows\System32\*.*
	List .= A_LoopFileName "|"
Gui, Add, Combobox, W300 gAutoComplete vAutoComplete , %List%
Gui, Add, Button, xm Default gOKButton, OK
Gui, Add, Button, x+ gAbbrechenButton, Abbrechen
Gui, Show,, CbAutoComplete Demo
return

AutoComplete:
CbAutoComplete()
return

OKButton:
GuiControlGet, InhaltComboBox ,,AutoComplete 
MsgBox, % InhaltComboBox 
Return

AbbrechenButton:
GuiClose:
ExitApp

;=======================================================================================
;
; Function:      CbAutoComplete
; Description:   Auto-completes typed values in a ComboBox.
;
; Author:        Pulover [Rodolfo U. Batista]
; Usage:         Call the function from the Combobox's gLabel.
;
;=======================================================================================
CbAutoComplete()
{	; CB_GETEDITSEL = 0x0140, CB_SETEDITSEL = 0x0142
	If ((GetKeyState("Delete", "P")) || (GetKeyState("Backspace", "P")))
		return
	GuiControlGet, lHwnd, Hwnd, %A_GuiControl%
	SendMessage, 0x0140, 0, 0,, ahk_id %lHwnd%
	MakeShort(ErrorLevel, Start, End)
	GuiControlGet, CurContent,, %lHwnd%
	GuiControl, ChooseString, %A_GuiControl%, %CurContent%
	If (ErrorLevel)
	{
		ControlSetText,, %CurContent%, ahk_id %lHwnd%
		PostMessage, 0x0142, 0, MakeLong(Start, End),, ahk_id %lHwnd%
		return
	}
	GuiControlGet, CurContent,, %lHwnd%
	PostMessage, 0x0142, 0, MakeLong(Start, StrLen(CurContent)),, ahk_id %lHwnd%
}

MakeLong(LoWord, HiWord)
{
	return (HiWord << 16) | (LoWord & 0xffff)
}

MakeShort(Long, ByRef LoWord, ByRef HiWord)
{
	LoWord := Long & 0xffff
,   HiWord := Long >> 16
}
Johnny R
Posts: 348
Joined: 03 Oct 2013, 02:07

Re: Rückgabe eines Werts aus CbAutoComplete()

28 Sep 2020, 03:40

@KHA, das klappt wunderbar. Vielen Dank!
gregster
Posts: 8916
Joined: 30 Sep 2013, 06:48

Re: Rückgabe eines Werts aus CbAutoComplete()

30 Sep 2020, 01:54

Als Alternative: Ich hätt' jetzt eher Gui, Submit verwendet (mit oder ohne NoHide-Option).

Also

Code: Select all

OKButton:
Gui, Submit	; , NoHide
MsgBox, % AutoComplete
Return
(mit KHA's Code-Version: die Variable AutoComplete muss auch hier definiert werden.
Johnny R
Posts: 348
Joined: 03 Oct 2013, 02:07

Re: Rückgabe eines Werts aus CbAutoComplete()

30 Sep 2020, 23:11

Läßt sich aus dem Skript ein Ersatz für InputBox entwickeln, also eine abgewandelte klassische InputBox mit dem gleichen Verhalten einer klassischen InputBox, aber mit den erweiterten Fähigkeiten von CbAutoComplete(), das für die klassische InputBox ja nicht zur Verfügung steht?
Johnny R
Posts: 348
Joined: 03 Oct 2013, 02:07

Re: Rückgabe eines Werts aus CbAutoComplete()

02 Oct 2020, 02:26

@KHA, da gefällt mir deine ursprüngliche Lösung (vom 27.9.2020) viel besser! Was mir zum Glück eben z. B. noch fehlt, ist die Möglichkeit, unsere GUI in eine vielfach verwendbare Funktion zu verkapseln, an die z. B. der Files-String oder andere Strings und Parameter übergeben werden können und die dann den ausgewählten Wert returniert und die GUI schließt. Kann man eine GUI mit allem, was dazu gehört, überhaupt in eine Funktion oder sonst etwas ähnliches verkapseln? Grüße!
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Rückgabe eines Werts aus CbAutoComplete()

02 Oct 2020, 05:34

Moin Johnny,

meinst Du so etwas?

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
   InputComboBoxGuiClose:
   InputComboBoxBtnCancel:
   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
}
Johnny R
Posts: 348
Joined: 03 Oct 2013, 02:07

Re: Rückgabe eines Werts aus CbAutoComplete()

02 Oct 2020, 08:04

@just me, "meinst Du so etwas?" ist die Untertreibung des Jahrhunderts! Genau so hatte ich mir das in meinsten kühnsten Träumen vorgestellt! Deine Funktion InputComboBox() ist echt klasse und ein dringender Kandidat für den KI-Nobelpreis! Deine Funktion kann – zusammen mit Pulovers Arbeit – die klassische Inputbox ersetzen!

Eine ganz klitzekleine Bitte hätte ich noch: Kannst Du bitte noch den Abbruch der GUI mit der ESC-Taste aktivieren? Bisher muß ich immer mit der Maus auf den Button "Abbrechen" drücken. Kannst Du diesen Abbrechen-Button mit der ESC-Taste verbinden?

Ich fasse es immer noch nicht, mit welchem Genius wir es hier bei dir zu tun haben... :o Vielen Dank!
KHA
Posts: 400
Joined: 21 Aug 2018, 11:11

Re: Rückgabe eines Werts aus CbAutoComplete()

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
}
Johnny R
Posts: 348
Joined: 03 Oct 2013, 02:07

Re: Rückgabe eines Werts aus CbAutoComplete()

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
}
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Rückgabe eines Werts aus CbAutoComplete()

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.
Johnny R
Posts: 348
Joined: 03 Oct 2013, 02:07

Re: Rückgabe eines Werts aus CbAutoComplete()

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!
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Rückgabe eines Werts aus CbAutoComplete()

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.
Johnny R
Posts: 348
Joined: 03 Oct 2013, 02:07

Re: Rückgabe eines Werts aus CbAutoComplete()

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
}
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Rückgabe eines Werts aus CbAutoComplete()

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   
---------------------------
Johnny R
Posts: 348
Joined: 03 Oct 2013, 02:07

Re: Rückgabe eines Werts aus CbAutoComplete()

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?
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Rückgabe eines Werts aus CbAutoComplete()

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?
Johnny R
Posts: 348
Joined: 03 Oct 2013, 02:07

Re: Rückgabe eines Werts aus CbAutoComplete()

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
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Rückgabe eines Werts aus CbAutoComplete()

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.

Return to “Ich brauche Hilfe”

Who is online

Users browsing this forum: Noitalommi_2 and 30 guests