emendelson 7 Posted February 21, 2020 I've been using the superb code found here to display a list of printers so that the user can select a printer name: I'll post my code below, but is there any way to make the GUI more modern, perhaps a list of printer names, with one of the names highlighted (reverse color), so you can move the highlight and then click OK to select that printer? I'm happy to live with this superb code as it is, but it would be nice to give it a more Windows-10-style look. Here's the code fragment that I've been using (extracted from a much longer script): expandcollapse popup#include <Array.au3> #include <GUIConstants.au3> Global $printername Local $ptrselmsg = "Select a printer:" GetPrinter($ptrselmsg) Do Sleep(100) Until $printername ConsoleWrite($printername & @LF) Func GetPrinter($ptrselmsg) Global $printer_list[1] Global $printer_list_ext[1] Global $printer_radio_array[1] Global $gh ; $printer_list = 0 ; $printer_list_ext = 0 ; $printer_radio_array = 0 $regprinters = "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices" $currentprinter = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\", "Device") $defaultprinter = StringLeft($currentprinter, StringInStr($currentprinter, ",") - 1) Dim $i = 1 Dim $erreur_reg = False While Not $erreur_reg $imprimante = RegEnumVal($regprinters, $i) $erreur_reg = @error If Not $erreur_reg Then _ArrayAdd($printer_list, $imprimante) _ArrayAdd($printer_list_ext, $imprimante & "," & RegRead($regprinters, $imprimante)) EndIf $i = $i + 1 WEnd _ArrayDelete($printer_list, 0) _ArrayDelete($printer_list_ext, 0) If UBound($printer_list) >= 2 Then ;if 2 or more printers available, we show the dialog Dim $groupheight = (UBound($printer_list) + 1) * 25 ;30 Dim $guiheight = $groupheight + 50 Dim $buttontop = $groupheight + 20 Opt("GUIOnEventMode", 1) $gh = GUICreate($ptrselmsg, 400, $guiheight) Dim $font = "Verdana" GUISetFont(10, 400, 0, $font) GUISetOnEvent($GUI_EVENT_CLOSE, "CloseClicked") GUISetFont(10, 400, 0, $font) GUICtrlCreateGroup("Available printers:", 10, 10, 380, $groupheight) Dim $position_vertical = 5 ; 0 For $i = 0 To UBound($printer_list) - 1 Step 1 GUISetFont(10, 400, 0, $font) $position_vertical = $position_vertical + 25 ;30 $radio = GUICtrlCreateRadio($printer_list[$i], 20, $position_vertical, 350, 20) _ArrayAdd($printer_radio_array, $radio) If $currentprinter = $printer_list_ext[$i] Then GUICtrlSetState($radio, $GUI_CHECKED) EndIf Next _ArrayDelete($printer_radio_array, 0) GUISetFont(10, 400, 0, $font) $okbutton = GUICtrlCreateButton("OK", 10, $buttontop, 50, 25) GUICtrlSetOnEvent($okbutton, "OKButton") Local $AccelKeys[2][2] = [["{ENTER}", $okbutton], ["^O", $okbutton]] GUISetAccelerators($AccelKeys) GUISetState() EndIf EndFunc ;==>GetPrinter Func OKButton() For $i = 0 To UBound($printer_radio_array) - 1 Step 1 If GUICtrlRead($printer_radio_array[$i]) = 1 Then $printername = StringLeft($printer_list_ext[$i], StringInStr($printer_list_ext[$i], ",") - 1) EndIf Next GUIDelete($gh) ; If Not @Compiled Then ConsoleWrite($printername & @LF) EndFunc ;==>OKButton Func CloseClicked() ;$printername = $defaultprinter GUIDelete($gh) $printername = "nul" ; If Not @Compiled Then ConsoleWrite($printername & @LF) ;Cancelled() ; MsgBox(0, "", $printername) ; Return $printername EndFunc ;==>CloseClicked Share this post Link to post Share on other sites
Zedna 277 Posted February 24, 2020 (edited) You can use 1) GUICtrlCreateList() or 2) GUICtrlCreateListView() with $LVS_NOCOLUMNHEADER + $LVS_SINGLESEL + $LVS_SHOWSELALWAYS ++ $LVS_EX_TRACKSELECT Edited February 24, 2020 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Share this post Link to post Share on other sites
emendelson 7 Posted February 24, 2020 @Zedna Thank you - this is clearly the answer I was looking for. It's not going to be easy for a low-skills scripted like me to do this, but it should certainly be possible. Thank you again.! Share this post Link to post Share on other sites