Strange... The code that you (Boiler) just posted works, but when it's with the rest of the code, I get
Error: Too many parameters passed to function.
Specifically: chosenSwitch
065: Loop Parse Switches, "
"
066: dfm.Add(A_Loopfield, chosenSwitch.Bind(A_Loopfield ))
▶ 067: dfm.Show()
068: }
071: {
Here is the code:
Code: Select all
#SingleInstance
#Requires AutoHotkey v2+
;===============================================================================
; Get/Set my default printer
; A tool to allow user to check and/or change default printer.
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=118596&p=526363#p526363
; By Kunkel321 with help from Garry. Partly auto-converted from v1, partly rewritten.
;===============================================================================
+!p:: ; Shift+Alt+P
PrinterTool(*)
{ ; TraySetIcon("shell32.dll","107") ; Icon of a printer with a green checkmark.
guiColor := "F0F8FF" ; "F0F8FF" is light blue
pfontColor := "003366" ; "003366" is dark blue
Global df := ""
; ===== Get default printer name. ======
defaultPrinter := RegRead("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device")
; ==== Get list of installed printers ======
Global printerlist := ""
Loop Reg, "HKCU\Software\Microsoft\Windows NT\CurrentVersion\devices"
printerlist := printerlist . "" . A_loopRegName . "`n"
printerlist := SubStr(printerlist, 1, strlen(printerlist) - 2)
df := Gui()
df.Title := "Default Printer Changer"
df.OnEvent("Close", ButtonCancel)
df.OnEvent("Escape", ButtonCancel)
df.BackColor := guiColor
df.SetFont("s12 bold c" . pFontColor)
df.Add("Text", , "Set A Default Printer ...")
df.SetFont("s11")
Loop Parse, printerlist, "`n"
If InStr(defaultPrinter, A_LoopField)
df.AddRadio("checked vRadio" . a_index, a_loopfield)
Else
df.AddRadio("vRadio" . a_index, a_loopfield)
df.AddButton("default", "Set Printer").OnEvent("Click", ButtonSet)
df.AddButton("x+10", "Print &Queue").OnEvent("Click", ButtonQue)
df.AddButton("x+10", "Control Panel").OnEvent("Click", ButtonCtrlPanel)
df.AddButton("x+10", "Cancel").OnEvent("Click", ButtonCancel)
df.Show()
df.OnEvent("ContextMenu", PrinterToolMenu)
}
PrinterToolMenu(*)
{
Switches := "
(
/e display printing preferences
/ge enum per machine printer connections
/k print test page to specified printer
/o display printer queue view
/p display printer properties
/s display server properties
/y set printer as the default
/Xg get printer settings
/? help this message
)"
dfm := Menu()
Loop Parse, Switches, "`n"
dfm.Add(A_Loopfield, chosenSwitch.Bind(A_Loopfield ))
dfm.Show()
}
chosenSwitch(var)
{ MsgBox var
; Loop Parse, printerlist, "`n"
; { thisRadioVal := df["Radio" . a_index].value
; If thisRadioVal != 0
; newDefault := a_loopfield
; }
; global mySwitch := StrSplit(item, " ")[1]
; RunWait("C:\Windows\System32\RUNDLL32.exe PRINTUI.DLL, PrintUIEntry " mySwitch " /n `"" newDefault "`"") ; sets the printer
}
ButtonSet(*)
{ Loop Parse, printerlist, "`n" {
thisRadioVal := df["Radio" . a_index].value
If thisRadioVal != 0
newDefault := a_loopfield
}
; ==== Set new default printer =====
RunWait("C:\Windows\System32\RUNDLL32.exe PRINTUI.DLL, PrintUIEntry /y /n `"" newDefault "`"") ; sets the printer
df.Destroy()
}
ButtonQue(*)
{ viewThis := ""
Loop Parse, printerlist, "`n" {
thisRadioVal := df["Radio" . a_index].value
If thisRadioVal != 0
viewThis := a_loopfield
}
; ==== View print queue for selected =====
RunWait("rundll32 printui.dll, PrintUIEntry /o /n `"" viewThis "`"") ;- display printer queue view -User Garry
df.Destroy()
}
ButtonCtrlPanel(*)
{ Run("control printers")
df.Destroy()
printerlist := ""
}
ButtonCancel(*)
{ df.Destroy()
printerlist := ""
}
Any idea why it is different, when used with the rest of the code?