RogFleming Posted October 14, 2009 Posted October 14, 2009 I been working on a Auto Hide Launchbar. I created an ini file to allow for modification without have to hard code the items i will add or delete later. My INI file: [Notepad] Icon=notepad.exe IconValue=2 Handle=NPHandle [Outlook] Icon=C:\Program Files\Microsoft Office\Office12\Outlook.exe IconValue=1 Handle=OLHandle I have a process to create a ARRAY from the file, I having issues where elements in the ARRAY are lost when I use them look at #### Modification Area #### If you remove the code the ARRAY is setup correct, but in the values get replaced with numeric values (11,13,14)?? Question: How to make the elements in the ARRAY more sticky? $getapps = IniReadSectionNames($inifile) For $i=1 to $getapps[0] $sectioninfo=IniReadSection($inifile,$getapps[$i]) $apps[$i][0]=$getapps[$i] $apps[$i][1]=$sectioninfo[1][1] $apps[$i][2]=$sectioninfo[2][1] $apps[$i][3]=$sectioninfo[3][1] ###### If I add this code after the values in the ARRAY are lost ###### $apps[$i][3] = GUICtrlCreateButton("",9,$loc,32,32,$BS_ICON) GUICtrlSetImage($apps[$i][3],$apps[$i][1],$apps[$i][2]) $loc=$loc+34 $apps[$i][0] = GUICtrlCreateLabel($apps[$i][0],4,$loc,40,12,$SS_CENTER) $loc=$loc+16 $color = PixelGetColor(4,100) If $color > 40000 Then $txtcolor = 0x000000 Else $txtcolor = 0xFFFFFF EndIf GUICtrlSetColor($apps[$i][0], $txtcolor) ##### End of Modification ##### Next _ArrayDisplay($apps,"Master Array update is complete.")
RogFleming Posted October 14, 2009 Author Posted October 14, 2009 Another Question how to create incrementing Variables? Here is example of my failed attempt: I cannot seem to create dynamic variables For $i=1 to $getapps[0] $sectioninfo=IniReadSection($inifile,$getapps[$i]) $btn&$i = $sectioninfo[1][1]; Maybe $btn$i? $label&$i = $sectioninfo[2][1] $name&$i = $sectioninfo[3][1] Next
PsaltyDS Posted October 14, 2009 Posted October 14, 2009 I been working on a Auto Hide Launchbar. I created an ini file to allow for modification without have to hard code the items i will add or delete later. My INI file: [Notepad] Icon=notepad.exe IconValue=2 Handle=NPHandle [Outlook] Icon=C:\Program Files\Microsoft Office\Office12\Outlook.exe IconValue=1 Handle=OLHandle I have a process to create a ARRAY from the file, I having issues where elements in the ARRAY are lost when I use them look at #### Modification Area #### If you remove the code the ARRAY is setup correct, but in the values get replaced with numeric values (11,13,14)?? Question: How to make the elements in the ARRAY more sticky? $getapps = IniReadSectionNames($inifile) For $i=1 to $getapps[0] $sectioninfo=IniReadSection($inifile,$getapps[$i]) $apps[$i][0]=$getapps[$i] $apps[$i][1]=$sectioninfo[1][1] $apps[$i][2]=$sectioninfo[2][1] $apps[$i][3]=$sectioninfo[3][1] ###### If I add this code after the values in the ARRAY are lost ###### $apps[$i][3] = GUICtrlCreateButton("",9,$loc,32,32,$BS_ICON) GUICtrlSetImage($apps[$i][3],$apps[$i][1],$apps[$i][2]) $loc=$loc+34 $apps[$i][0] = GUICtrlCreateLabel($apps[$i][0],4,$loc,40,12,$SS_CENTER) $loc=$loc+16 $color = PixelGetColor(4,100) If $color > 40000 Then $txtcolor = 0x000000 Else $txtcolor = 0xFFFFFF EndIf GUICtrlSetColor($apps[$i][0], $txtcolor) ##### End of Modification ##### Next _ArrayDisplay($apps,"Master Array update is complete.") They are control IDs, there because you saved them there: $apps[$i][3] = GUICtrlCreateButton(... $apps[$i][0] = GUICtrlCreateLabel(... If you didn't want to overwrite those values with the control IDs, then why are you doing that? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
PsaltyDS Posted October 14, 2009 Posted October 14, 2009 Another Question how to create incrementing Variables? Here is example of my failed attempt: I cannot seem to create dynamic variables For $i=1 to $getapps[0] $sectioninfo=IniReadSection($inifile,$getapps[$i]) $btn&$i = $sectioninfo[1][1]; Maybe $btn$i? $label&$i = $sectioninfo[2][1] $name&$i = $sectioninfo[3][1] Next You could use Assign() and Eval(), but that usually leads to sloppy, hard to maintain code. Instead of $btn1, $btn2, etc, just create a single array with: Global $btn[ $getapps[0] + 1 ] ; $btn[1] contains the first one Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
RogFleming Posted October 15, 2009 Author Posted October 15, 2009 They are control IDs, there because you saved them there: $apps[$i][3] = GUICtrlCreateButton(... $apps[$i][0] = GUICtrlCreateLabel(... If you didn't want to overwrite those values with the control IDs, then why are you doing that? Yep, I been beating my head around something I should have seen. Glad you pointed it out to me.
RogFleming Posted October 15, 2009 Author Posted October 15, 2009 Like this? $apps = IniReadSectionNames($inifile) If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else ReDim $apps[$apps[0]+1][4] $getapps = IniReadSectionNames($inifile) For $i=1 to $getapps[0] Global $btn[ $getapps[0] + 1 ] ; $btn[1] contains the first one Global $label[ $getapps[0] + 1 ] ; $btn[1] contains the first one $sectioninfo=IniReadSection($inifile,$getapps[$i]) $apps[$i][0]=$getapps[$i] $apps[$i][1]=$sectioninfo[1][1] $apps[$i][2]=$sectioninfo[2][1] $apps[$i][3]=$sectioninfo[3][1] $btn[[ $getapps[0] + 1 ]] = GUICtrlCreateButton("",9,$loc,32,32,$BS_ICON) GUICtrlSetImage($apps[$i][3],$apps[$i][1],$apps[$i][2]) $loc=$loc+34 $label[[ $getapps[0] + 1 ]] = GUICtrlCreateLabel($apps[$i][0],4,$loc,40,12,$SS_CENTER) $loc=$loc+16 $color = PixelGetColor(4,100) If $color > 40000 Then $txtcolor = 0x000000 Else $txtcolor = 0xFFFFFF EndIf GUICtrlSetColor($apps[$i][0], $txtcolor) Next _ArrayDisplay($apps,"Master Array update is complete.") EndIf
RogFleming Posted October 15, 2009 Author Posted October 15, 2009 I getting now, I have built a seperate ARRAY for the label and button controls.
RogFleming Posted October 19, 2009 Author Posted October 19, 2009 It been a little bit to get this working. The purpose of the effort was to have a network ready Launchbar which could be dynamically updated from a installer or storage of the data.ini on a remote server. We will call this Alpha 1.0, basic functions work correctly. expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=..\Icons\120.ico #AutoIt3Wrapper_outfile=c:\Launchbar\Bin\launchbar.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <GuiButton.au3> #include <WINAPI.au3> #include <sendmessage.au3> #include <Misc.au3> #include <Array.au3> #include <StaticConstants.au3> #include <EditConstants.au3> Opt('MustDeclareVars', 1) Global $msg, $hideBar, $mPos, $maxbar, $minbar, $handle, $logon, $logoff, $Outlook, _ $IE, $hGraph_1, $btn1, $btn2,$btn3,$Exit, $Logon, $color, $txtcolor, $passwrd, _ $username, $logondialog, $userlog, $Notepad, $btn4, $inifile, $apps, $i, $var, $btn, _ $v, $loc, $icon, $iconValue, $apps, $icons, $sectioninfo, $getapps, $l,$b,$btn[1],$lbl[1] $userlog = 0 $inifile = "c:\Program Files\Launchbar\Data\Data.ini" Launchbar() Func Launchbar() $maxbar = GUICreate("maxbar",50,@DesktopHeight,@DesktopWidth-50,0,$WS_POPUP, BitOR($WS_EX_LAYERED,$WS_EX_TOOLWINDOW)) GUISetBkColor(0xABCDEF,$maxbar) WinSetOnTop($maxbar,"",1) _WinAPI_SetLayeredWindowAttributes($maxbar, 0xABCDEF, 250) GUISetState(@SW_HIDE,$maxbar) $loc = 104 $b=1 $l=1 _ArrayAdd($btn,$b) _ArrayAdd($lbl,$l) $btn[1] = GUICtrlCreateButton("",9,54,32,32,$BS_ICON) GUICtrlSetImage($btn[1],"shell32.dll",240) $lbl[1] = GUICtrlCreateLabel("EXIT",9,88,32,12,$SS_CENTER) $b=$b+1 $l=$l+1 _ArrayAdd($btn,$b) _ArrayAdd($lbl,$l) $btn[0]=2 $lbl[0]=2 If $userlog = 1 Then $loc = 104 $btn[2] = GUICtrlCreateButton("",9,4,32,32,$BS_ICON) GUICtrlSetImage($btn[2],"shell32.dll",329) $lbl[2] = GUICtrlCreateLabel("Logoff",9,38,32,12,$SS_CENTER) $apps = IniReadSectionNames($inifile) If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else ReDim $apps[$apps[0]+1][4] $getapps = IniReadSectionNames($inifile) For $i=1 to $getapps[0] $b=$b+1 $l=$l+1 _ArrayAdd($btn,$b) _ArrayAdd($lbl,$l) $sectioninfo=IniReadSection($inifile,$getapps[$i]) $apps[$i][0]=$getapps[$i] $apps[$i][1]=$sectioninfo[1][1] $apps[$i][2]=$sectioninfo[2][1] $apps[$i][3]=$sectioninfo[3][1] $btn[0]=$b $lbl[0]=$l $btn[$b] = GUICtrlCreateButton("",9,$loc,32,32,$BS_ICON) GUICtrlSetImage($btn[$b],$apps[$i][1],$apps[$i][2]) $loc=$loc+34 $lbl[$l] = GUICtrlCreateLabel($apps[$i][0],4,$loc,40,12,$SS_CENTER) $loc=$loc+16 $color = PixelGetColor(4,100) If $color > 40000 Then $txtcolor = 0x000000 Else $txtcolor = 0xFFFFFF EndIf GUICtrlSetColor($lbl[1], $txtcolor) GUICtrlSetColor($lbl[2], $txtcolor) GUICtrlSetColor($lbl[3], $txtcolor) GUICtrlSetColor($lbl[$l], $txtcolor) Next ;_ArrayDisplay($apps,"Master Array update is complete.") ;_ArrayDisplay($btn,"Button Array update is complete.") ;_ArrayDisplay($lbl,"Label Array update is complete.") EndIf Else $btn[2] = GUICtrlCreateButton("",9,4,32,32,$BS_ICON) GUICtrlSetImage($btn[2],"shell32.dll",331) $lbl[2] = GUICtrlCreateLabel("Login",9,38,32,12,$SS_CENTER) EndIf GUISetState() While 1 sleep(25) $mPos = MouseGetPos() $msg = GUIGetMsg() If $userlog = 0 Then Select Case $mPos[0] > @DesktopWidth-20 ; based on mouse location the launchbar is visiable or not If $mPos[1] > 25 Then ShowToolbar() Case $mPos[0] < @DesktopWidth-60 HideToolbar() Case $msg = $btn[2] LogonDialog() Case $msg = $btn[1] _exit() EndSelect Else Select Case $mPos[0] > @DesktopWidth-20 ; based on mouse location the launchbar is visiable or not If $mPos[1] > 25 Then ShowToolbar() Case $mPos[0] < @DesktopWidth-60 HideToolbar() Case $msg = $btn[2] MsgBox(1,"Logoff Confirmation"," Are you sure you want to logoff?") $userlog = 0 GUIDelete() Launchbar() Case $msg = $btn[1] _exit() Case $msg >= $btn[3] Switch $msg Case $btn[3] MsgBox(1,"Message from $apps[1]",$apps[1][0],1) Case $btn[4] MsgBox(1,"Message from $apps[2]",$apps[2][0],1) Case $btn[5] MsgBox(1,"Message from $apps[3]",$apps[3][0],1) Case $btn[6] MsgBox(1,"Message from $apps[4]",$apps[4][0],1) Case $btn[7] MsgBox(1,"Message from $apps[5]",$apps[5][0],1) Case $btn[8] MsgBox(1,"Message from $apps[6]",$apps[6][0],1) EndSwitch EndSelect EndIf WEnd EndFunc Func ShowToolbar() GUISetState(@SW_SHOWNOACTIVATE, $maxbar) GUISetState($WS_EX_TOPMOST,$maxbar) $color = PixelGetColor(4,100) If $color > 40000 Then $txtcolor = 0x000000 Else $txtcolor = 0xFFFFFF EndIf If $userlog = 0 Then For $i = 1 to $lbl[0] GUICtrlSetColor($lbl[$i], $txtcolor) Next Else For $i = 1 to $lbl[0] GUICtrlSetColor($lbl[$i], $txtcolor) Next EndIf EndFunc Func HideToolbar() If WinExists("maxbar") Then GUISetState(@SW_HIDE,$maxbar) EndIf EndFunc Func _exit() Exit EndFunc Func LogonDialog() ;this is generic logon dialog which you could use name pipe to verify that the user entered correct AD credentials Local $btnlogon,$btncancel GUISetState(@SW_HIDE,$maxbar) $logondialog = GUICreate("Launchbar Logon",300,100,-1,-1) $username = GUICtrlCreateInput("",120,10,100,20) GUICtrlCreateLabel("Username:",40,10,50,16) $passwrd = GUICtrlCreateInput("",120,30,100,20,$ES_PASSWORD) GUICtrlCreateLabel("Password:",40,30,50,16) $btnlogon = GUICtrlCreateButton("OK",80,70,60,20) $btncancel = GUICtrlCreateButton("Cancel",180,70,60,20) GUISetState(@SW_HIDE,$logondialog) GUISetState($WS_EX_TOPMOST,$logondialog) GUISetState() While $msg <> $GUI_EVENT_CLOSE sleep(25) $msg = GUIGetMsg() Select Case $msg = $btnlogon If GUICtrlRead($username)="" Then MsgBox(1,"Error","You must enter a Username.") EndIf If GUICtrlRead($passwrd)="" Then MsgBox(1,"Error","You must enter a password.") Else LogonProcess() EndIf Case $msg = $btncancel GUIDelete($logondialog) GUIDelete($maxbar) Launchbar() EndSelect WEnd GUIDelete() EndFunc Func LogonProcess() ;basic eye candy which you could provide when do the namepipe check GUIDelete($logondialog) ProgressOn("Logon", "Domain Logon", "0 percent") For $i = 10 to 100 step 10 sleep(100) ProgressSet( $i, $i & " percent") Next ProgressSet(100 , "Done", "Logon Complete") sleep(500) ProgressOff() $userlog = 1 Launchbar() EndFunc Func _WinAPI_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $dwFlages = 0x03, $isColorRef = False) ; ############################################# ; You are NOT ALLOWED to remove the following lines ; Function Name: _WinAPI_SetLayeredWindowAttributes ; Author(s): Prog@ndy ; ############################################# If $dwFlages = Default Or $dwFlages = "" Or $dwFlages < 0 Then $dwFlages = 0x03 If Not $isColorRef Then $i_transcolor = Hex(String($i_transcolor), 6) $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2)) EndIf Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $dwFlages) Select Case @error Return SetError(@error, 0, 0) Case $Ret[0] = 0 Return SetError(4, _WinAPI_GetLastError(), 0) Case Else Return 1 EndSelect Return EndFunc ;==>_WinAPI_SetLayeredWindowAttributes
RogFleming Posted October 19, 2009 Author Posted October 19, 2009 with the provided example a simple ini file will populate the launchbar and execute the commands [Notepad] Icon=notepad.exe IconValue=2 Handle=NPHandle [Outlook] Icon=C:\Program Files\Microsoft Office\Office12\Outlook.exe IconValue=1 Handle=OLHandle [internet] Icon=C:\Program Files\Internet Explorer\iexplore.exe IconValue=1 Handle=IEHandle [Word] Icon=C:\Program Files\Microsoft Office\Office12\winword.exe IconValue=1 Handle=WDHandle [Calc] Icon=calc.exe IconValue=1 Handle=CLHandle and a change to the switch command instead of Message boxes Switch $msg Case $btn[3] Run($apps[1][1]) Case $btn[4] Run($apps[2][1]) Case $btn[5] Run($apps[3][1]) Case $btn[6] Run($apps[4][1]) Case $btn[7] Run($apps[5][1]) Case $btn[8] Run($apps[6][1]) EndSwitch
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now