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
}
@KHA, vielen Dank! Ich habe jetzt nach InputComboBoxBtnCancel: [i]Gui, Destroy[/i] statt [i]ExitApp[/i] geskriptet. Jetzt läuft das Skript wunderbar. Zur Kontrolle zeige ich mein Skript mit den (aus-)kommentierten Änderungen:
[code]#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
}[/code]