Jump to content

trayitem reset how?


Vaner
 Share

Recommended Posts

i have a trayitemmenu build from a array item list

one of the item will be get the Tray_Check state set.

my issue is i cannot preset the size of the array like iam use to do , i have no idea the number it will have before .

if i do $item = TrayCreateItem it will build every item i need , but later on, i need to do a trayitemgettext

if i use the $item it always return the last value created , so instead i use @tray_id get my handle .

but i need to change the stat of the previous check item to uncheck it.

since i cannot use $item or $item[$i] to build the menu , so i just build it ,

but how do i extract the handle of the last check item in the menu list . i can build array of itemtext/itemhandle and search tru it , but i dont think it the best way to do it , im looking for way to refresh the list same way i can reset data of a drop down menu in guictrl .

iam pretty sure it me missing a little dump thing ,on how to reset a trayitemlist , or build random variable for my item.

so it look like this , for this menu :

#include <array.au3>

Global $Array[1]

#Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",3); Default tray menu items (Script Paused/Exit) will not be shown.
Opt("TrayOnEventMode",1)

$settingsitem = TrayCreateMenu("tool")

$displayitem = TrayCreateItem("Network", $settingsitem,-1,-1)
;TrayItemSetOnEvent(-1,"net")

$printeritem = TrayCreateMenu("Printer", $settingsitem ,-1)
printer()

$exititem = TrayCreateItem("Exit",-1,1)
TrayItemSetOnEvent(-1,"end")

TraySetState()

While 1
$msg = TrayGetMsg()
Select
Case $msg = 0
ContinueLoop

Case $msg = $exititem
ExitLoop
EndSelect
sleep(10)
WEnd

Exit



func dprinter()

;$Dprinter = "HP LaserJet 4100 Series PS"
$Dprinter = TrayItemGetText(@TRAY_ID)
$Printdll = ("RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n")
$SetDPcmd = ($Printdll & ' "' & $Dprinter & '"')
run($SetDPcmd)
;printer();;;;;;;;;;;;;;;;;;;;;;;trying to reset printer item menu 
TrayitemSetState(@TRAY_ID,$TRAY_CHECKED)
EndFunc


func printer()

$objWMIService = objget("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

$colSettings = $objWMIService.ExecQuery("Select * from Win32_printer")

$printerstring = ""

For $objOperatingSystem in $colSettings 

$PcInfo = $objOperatingSystem.name 
$tmpPreset = $objOperatingSystem.default
_Arrayadd($Array,$pcinfo)
if $tmpPreset = -1 then 
$dfprinter = $pcinfo 
EndIf
Next
;_ArrayDisplay($Array)
for $i = 1 to UBound($Array) -1
$printerstring = $array[$i]
if $printerstring = $dfprinter then
TrayCreateItem ($printerstring,$printeritem , -1,-1)
TrayItemSetOnEvent(-1,"dprinter")
TrayitemSetState(-1,$TRAY_CHECKED)
Else
TrayCreateItem ($printerstring,$printeritem , -1,-1)
TrayItemSetOnEvent(-1,"dprinter")
endif

;MsgBox(48,"s",$printerstrin)
next


EndFunc

Func end()
Exit
EndFunc



; $tmpPreset = $objOperatingSystem.default
; if $tmpPreset = -1 then 
; MsgBox(48,"t",$tmpPreset)
; $printerlist = TrayCreateItem($pcinfo, $printeritem, -1,-1)

; EndIf
;MsgBox(48,"PCinfo",$pcinfo)
; MsgBox(48, "PCinfo", $tmpPreset)
; $printerlist = TrayCreateItem($pcinfo, $printeritem, -1,-1)
;TrayItemSetOnEvent(-1,"Dprinter")

Any idea what i should be looking for ?

Link to comment
Share on other sites

i have a trayitemmenu build from a array item list

one of the item will be get the Tray_Check state set.

my issue is i cannot preset the size of the array like iam use to do , i have no idea the number it will have before .

if i do $item = TrayCreateItem it will build every item i need , but later on, i need to do a trayitemgettext

if i use the $item it always return the last value created , so instead i use @tray_id get my handle .

but i need to change the stat of the previous check item to uncheck it.

since i cannot use $item or $item[$i] to build the menu , so i just build it ,

but how do i extract the handle of the last check item in the menu list . i can build array of itemtext/itemhandle and search tru it , but i dont think it the best way to do it , im looking for way to refresh the list same way i can reset data of a drop down menu in guictrl .

iam pretty sure it me missing a little dump thing ,on how to reset a trayitemlist , or build random variable for my item.

so it look like this , for this menu :

... (code clipped for space)

Any idea what i should be looking for ?

I added the $TrayPrinters array (in the printer func) and then in the dprinter func, I set a flush of all possible checkboxes before it assigns the checkbox to the newly assigned default printer.

Give this a shot:

#include <array.au3>

Global $Array[1],$TrayPrinters[1]

#Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode", 3); Default tray menu items (Script Paused/Exit) will not be shown.
Opt("TrayOnEventMode", 1)

$settingsitem = TrayCreateMenu("tool")

$displayitem = TrayCreateItem("Network", $settingsitem, -1, -1)
;TrayItemSetOnEvent(-1,"net")

$printeritem = TrayCreateMenu("Printer", $settingsitem, -1)
printer()

$exititem = TrayCreateItem("Exit", -1, 1)
TrayItemSetOnEvent(-1, "end")

TraySetState()

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop

        Case $msg = $exititem
            ExitLoop
    EndSelect
    Sleep(10)
WEnd

Exit



Func dprinter()

    ;$Dprinter = "HP LaserJet 4100 Series PS"
    $Dprinter = TrayItemGetText(@TRAY_ID)
    $Printdll = ("RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n")
    $SetDPcmd = ($Printdll & ' "' & $Dprinter & '"')
    Run($SetDPcmd)
    ;printer();;;;;;;;;;;;;;;;;;;;;;;trying to reset printer item menu
    For $i = 1 to UBound($TrayPrinters) -1
        TrayItemSetState($TrayPrinters[$i],$TRAY_UNCHECKED)
    Next
    TrayItemSetState(@TRAY_ID, $TRAY_CHECKED)
EndFunc   ;==>dprinter

Func printer()

    $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

    $colSettings = $objWMIService.ExecQuery ("Select * from Win32_printer")

    $printerstring = ""

    For $objOperatingSystem In $colSettings

        $PcInfo = $objOperatingSystem.name
        $tmpPreset = $objOperatingSystem.Default
        _ArrayAdd($Array, $PcInfo)
        If $tmpPreset = -1 Then
            $dfprinter = $PcInfo
        EndIf
    Next
    ;_ArrayDisplay($Array)
    ReDim $TrayPrinters[UBound($Array) ]
    For $i = 1 To UBound($Array) - 1
        $printerstring = $Array[$i]
        If $printerstring = $dfprinter Then
            $TrayPrinters[$i] = TrayCreateItem($printerstring, $printeritem, -1, -1)
            TrayItemSetOnEvent(-1, "dprinter")
            TrayItemSetState(-1, $TRAY_CHECKED)
        Else
            $TrayPrinters[$i] = TrayCreateItem($printerstring, $printeritem, -1, -1)
            TrayItemSetOnEvent(-1, "dprinter")
        EndIf

        ;MsgBox(48,"s",$printerstrin)
    Next


EndFunc   ;==>printer

Func end()
    Exit
EndFunc   ;==>end

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...