Jump to content

Auto Hide Launchbar


RogFleming
 Share

Recommended Posts

I wrote a Launchbar shell which allows a programming to create functions to call and allows them to be accessed from a Autohide launchbar.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <GuiButton.au3>
#include <WINAPI.au3>
#include <sendmessage.au3>
#include <Misc.au3>
#include <Array.au3>

Opt('MustDeclareVars', 1)
Global $msg, $hideBar, $mPos, $maxbar, $minbar, $handle, $logon, $logoff, $mth, $outlook, _
$IE, $epic, $share, $ilink, $service, $pwa, $wksadmin, $drfax, $salt, $caregate, $hGraph_1, _
$lock, $test1, $run, $fav, $config, $stop

Toolbar()


; example 1

Func Toolbar()

$maxbar = GUICreate("maxbar",40,@DesktopHeight,@DesktopWidth-40,0,$WS_POPUP, $WS_EX_LAYERED)
GUISetBkColor(0xABCDEF)
$hGraph_1 = GUICtrlCreateGraphic(0, 0,@DesktopHeight, @DesktopWidth-40)
GUICtrlSetColor(-1, 0xABCDEF)
GUICtrlSetGraphic(-1, $GUI_GR_HINT, 1)
_WinAPI_SetLayeredWindowAttributes($maxbar, 0xABCDEF, 255)
GUISetState($WS_EX_TOPMOST)
$logon = GUICtrlCreateIcon("shell32.dll",45,4,4,32,32)
$logoff = GUICtrlCreateIcon("shell32.dll",240,4,36,32,32)
$mth = GUICtrlCreateIcon("shell32.dll",24,4,72,32,32)
$outlook = GUICtrlCreateIcon("shell32.dll",25,4,108,32,32)
$IE = GUICtrlCreateIcon("shell32.dll",512,4,144,32,32)
$lock = GUICtrlCreateIcon("shell32.dll",48,4,180,32,32)
$test1 = GUICtrlCreateIcon("shell32.dll",142,4,216,32,32)
$run = GUICtrlCreateIcon("shell32.dll",160,4,252,32,32)
$fav = GUICtrlCreateIcon("shell32.dll",173,4,288,32,32)
$config = GUICtrlCreateIcon("shell32.dll",210,4,324,32,32)
$stop = GUICtrlCreateIcon("shell32.dll",329,4,360,32,32)

$minbar = GUICreate("minbar",70,@DesktopHeight-1,@DesktopWidth-1,1,$BS_ICON)
GUISetBkColor(255)
GUISetState(@SW_SHOW, $minbar)
While 1
        sleep(100)
        $mPos = MouseGetPos()
    If $mPos[0] > @DesktopWidth-10 Then
        ShowToolbar()
    EndIf
        
    If $mPos[0] < @DesktopWidth-100 Then
        HideToolbar()
    EndIf
    
    WEnd
EndFunc   ;==>Example1
Func ShowToolbar()
            If WinExists("minbar") Then
            GUISetState(@SW_HIDE,$minbar)
            GUISetState(@SW_SHOW,$maxbar)
            EndIf
EndFunc
Func HideToolbar()
            If WinExists("maxbar") Then
            GUISetState(@SW_HIDE,$maxbar)
            GUISetState(@SW_SHOW,$minbar)
            EndIf
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
    Toolbar()
EndFunc  ;==>_WinAPI_SetLayeredWindowAttributes
Link to comment
Share on other sites

Updated the code to work better:

Corrected function calls from button clicks

Added Text color logic to change the text color based on what color is behind the launchbar

#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>


Opt('MustDeclareVars', 1)
Global $msg, $hideBar, $mPos, $maxbar, $minbar, $handle, $logon, $logoff, $mth, $outlook, _
$IE, $epic, $share, $ilink, $service, $pwa, $wksadmin, $drfax, $salt, $caregate, $hGraph_1, _
$lock, $test1, $run, $fav, $config, $stop, $btn1, $btn2,$Exit, $Logon, $color, $txtcolor
$txtcolor = 0xFFFFFF
Launchbar()

; example 1

Func Launchbar()

                $maxbar = GUICreate("maxbar",50,@DesktopHeight-25,@DesktopWidth-50,25,$WS_POPUP, $WS_EX_LAYERED)
                GUISetBkColor(0xABCDEF)
                _WinAPI_SetLayeredWindowAttributes($maxbar, 0xABCDEF, 250)
                
                
                        $btn1 = GUICtrlCreateButton("",4,4,32,32,$BS_ICON)
                        GUICtrlSetImage($btn1,"shell32.dll",45)
                        $Logon = GUICtrlCreateLabel("Login",4,38,32,12,$SS_CENTER)
                        
                        $btn2 = GUICtrlCreateButton("",4,54,32,32,$BS_ICON)
                        GUICtrlSetImage($btn2,"shell32.dll",240)
                        $Exit = GUICtrlCreateLabel("EXIT",4,88,32,12,$SS_CENTER)
                        
                        
                $minbar = GUICreate("minbar",100,@DesktopHeight-25,@DesktopWidth-10,25,$WS_POPUP, $WS_EX_LAYERED)
                GUISetBkColor(0xABCDEF)
                
                GUISetState()

                        While 1
                        sleep(25)
                        $msg = GUIGetMsg()
                        $mPos = MouseGetPos()
                        
                        Select
                            Case $mPos[0] > @DesktopWidth-20
                                ShowToolbar()

                            Case $mPos[0] < @DesktopWidth-60
                                HideToolbar()

                            Case $msg = $btn1
                                MsgBox(0, "Logon button clicked",$btn1,1)

                            Case $msg = $btn2
                                MsgBox(0, "Exit button clicked",$btn2,1)

                        EndSelect
                        WEnd

EndFunc   ;==>Example1
Func ShowToolbar()
            If WinExists("minbar") Then
                
            GUISetState(@SW_HIDE,$minbar)
            GUISetState(@SW_SHOW,$maxbar)
            $color = PixelGetColor(4,100)
            If $color > 40000 Then 
            $txtcolor = 0x000000
            Else
            $txtcolor = 0xFFFFFF
            EndIf
            GUICtrlSetColor($Logon, $txtcolor)
            GUICtrlSetColor($Exit, $txtcolor)
            GUISetState($WS_EX_TOPMOST,$maxbar)
            EndIf
EndFunc
Func HideToolbar()
            If WinExists("maxbar") Then
            GUISetState(@SW_HIDE,$maxbar)
            GUISetState(@SW_SHOW,$minbar)
            EndIf
EndFunc



Func LogonBar()
            $logoff = GUICtrlCreateIcon("shell32.dll",240,4,36,32,32)
            $mth = GUICtrlCreateIcon("shell32.dll",24,4,72,32,32)
            $outlook = GUICtrlCreateIcon("shell32.dll",25,4,108,32,32)
            $IE = GUICtrlCreateIcon("shell32.dll",512,4,144,32,32)
            $lock = GUICtrlCreateIcon("shell32.dll",48,4,180,32,32)
            $test1 = GUICtrlCreateIcon("shell32.dll",142,4,216,32,32)
            $run = GUICtrlCreateIcon("shell32.dll",160,4,252,32,32)
            $fav = GUICtrlCreateIcon("shell32.dll",173,4,288,32,32)
            $config = GUICtrlCreateIcon("shell32.dll",210,4,324,32,32)
            $stop = GUICtrlCreateIcon("shell32.dll",329,4,360,32,32)
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
Link to comment
Share on other sites

Update for 10/8, 2009 17:00 CST

Added a Authentication dialog

Added Notepad and Outlook short cuts to the launchbar

Added some comments to the script to point out important areas for integration

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=c:\temp\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
;$txtcolor = 0xFFFFFF
$userlog = 0
Launchbar()

; example 1

Func Launchbar()

                $maxbar = GUICreate("maxbar",50,@DesktopHeight,@DesktopWidth-50,0,$WS_POPUP, $WS_EX_LAYERED)
                GUISetBkColor(0xABCDEF)
                _WinAPI_SetLayeredWindowAttributes($maxbar, 0xABCDEF, 250)
                GUISetState(@SW_HIDE,$maxbar)
                
                        $btn1 = GUICtrlCreateButton("",9,4,32,32,$BS_ICON)
                        $btn2 = GUICtrlCreateButton("",9,54,32,32,$BS_ICON)
                                                            
                        
                        GUICtrlSetImage($btn2,"shell32.dll",240)
                        $Exit = GUICtrlCreateLabel("EXIT",9,88,32,12,$SS_CENTER)
                        
                        If $userlog = 1 Then
                        
                        GUICtrlSetImage($btn1,"shell32.dll",329)
                        $Logoff = GUICtrlCreateLabel("Logoff",9,38,32,12,$SS_CENTER)
                        
                        $btn3 = GUICtrlCreateButton("",9,104,32,32,$BS_ICON)    
                        GUICtrlSetImage($btn3,"notepad.exe",2)
                        $Notepad = GUICtrlCreateLabel("Notepad",4,138,40,12,$SS_CENTER)
                        
                        $btn4 = GUICtrlCreateButton("",9,158,32,32,$BS_ICON)    
                        GUICtrlSetImage($btn4,"C:\Program Files\Microsoft Office\Office12\Outlook.exe",1)
                        $Outlook = GUICtrlCreateLabel("Outlook",4,192,40,12,$SS_CENTER)
                        
                        Else
                        
                        GUICtrlSetImage($btn1,"shell32.dll",331)
                        $Logon = GUICtrlCreateLabel("Login",9,38,32,12,$SS_CENTER)
                        
                        EndIf
                                
                        GUISetState()
                        
                        While 1
                            sleep(65)
                            $mPos = MouseGetPos()
                            $msg = GUIGetMsg()
                                
                                    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 = $btn1
                                                        If $userlog = 0 Then 
                                                            LogonDialog()
                                                        Else
                                                            $userlog = 0
                                                            GUIDelete()
                                                            Launchbar()
                                                        EndIf
                                                                                
                                        Case $msg = $btn2
                                                        _exit()
                                        
                                        Case $msg = $btn3 ; executes notepad when the notepad button is pressed
                                                        If $userlog = 1 Then
                                                        run("notepad.exe")
                                                    EndIf
                                        Case $msg = $btn4
                                                        If $userlog = 1 Then
                                                        run("C:\Program Files\Microsoft Office\Office12\outlook.exe")
                                                        EndIf           
                                                
                                    EndSelect
                        WEnd
                    

EndFunc   
Func ShowToolbar()
            Sleep(100)
            GUISetState(@SW_SHOW,$maxbar)
            GUISetState(@SW_ENABLE,$maxbar)
            GUISetState($WS_EX_TOPMOST,$maxbar)
            $color = PixelGetColor(4,100) ;check the background color and based on the color value sets black or white
            If $color > 40000 Then 
            $txtcolor = 0x000000
            Else
            $txtcolor = 0xFFFFFF
            EndIf
            ;Sets the color of the text based on background color of the desktop
            GUICtrlSetColor($Logon, $txtcolor)
            GUICtrlSetColor($Exit, $txtcolor)
            GUICtrlSetColor($Logoff, $txtcolor)
            GUICtrlSetColor($Notepad, $txtcolor)
            GUICtrlSetColor($Outlook, $txtcolor)
            Return          
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
Link to comment
Share on other sites

Hi

I think you want to post this in the examples forum. If you click report on the bottom left of the page, someone will move it for you.

Anyways. I think you did a good job on this. I have solved your blinking problem, see attached. Might want to set up an ini file and reference it. Set your icons from that. That way when compiled you can still tweak.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=c:\temp\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
;$txtcolor = 0xFFFFFF
$userlog = 0
Launchbar()

; example 1

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)
                        $btn1 = GUICtrlCreateButton("",9,4,32,32,$BS_ICON)
                        $btn2 = GUICtrlCreateButton("",9,54,32,32,$BS_ICON)
                                                            
                        
                        GUICtrlSetImage($btn2,"shell32.dll",240)
                        $Exit = GUICtrlCreateLabel("EXIT",9,88,32,12,$SS_CENTER)
                        
                        If $userlog = 1 Then
                        
                        GUICtrlSetImage($btn1,"shell32.dll",329)
                        $Logoff = GUICtrlCreateLabel("Logoff",9,38,32,12,$SS_CENTER)
                        
                        $btn3 = GUICtrlCreateButton("",9,104,32,32,$BS_ICON)    
                        GUICtrlSetImage($btn3,"notepad.exe",2)
                        $Notepad = GUICtrlCreateLabel("Notepad",4,138,40,12,$SS_CENTER)
                        
                        $btn4 = GUICtrlCreateButton("",9,158,32,32,$BS_ICON)    
                        GUICtrlSetImage($btn4,"C:\Program Files\Microsoft Office\Office12\Outlook.exe",1)
                        $Outlook = GUICtrlCreateLabel("Outlook",4,192,40,12,$SS_CENTER)
                        
                        Else
                        
                        GUICtrlSetImage($btn1,"shell32.dll",331)
                        $Logon = GUICtrlCreateLabel("Login",9,38,32,12,$SS_CENTER)
                        
                        EndIf
                                
                        GUISetState()
                        
                        While 1
                            sleep(65)
                            $mPos = MouseGetPos()
                            $msg = GUIGetMsg()
                                
                                    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 = $btn1
                                                        If $userlog = 0 Then 
                                                            LogonDialog()
                                                        Else
                                                            $userlog = 0
                                                            GUIDelete()
                                                            Launchbar()
                                                        EndIf
                                                                                
                                        Case $msg = $btn2
                                                        _exit()
                                        
                                        Case $msg = $btn3 ; executes notepad when the notepad button is pressed
                                                        If $userlog = 1 Then
                                                        run("notepad.exe")
                                                    EndIf
                                        Case $msg = $btn4
                                                        If $userlog = 1 Then
                                                        run("C:\Program Files\Microsoft Office\Office12\outlook.exe")
                                                        EndIf           
                                                
                                    EndSelect
                        WEnd
                    

EndFunc   
Func ShowToolbar()
            Sleep(100)
          ;  GUISetState(@SW_SHOW,$maxbar)
            GUISetState(@SW_SHOWNOACTIVATE, $maxbar)
            GUISetState($WS_EX_TOPMOST,$maxbar)
            $color = PixelGetColor(4,100) ;check the background color and based on the color value sets black or white
            If $color > 40000 Then 
            $txtcolor = 0x000000
            Else
            $txtcolor = 0xFFFFFF
            EndIf
            ;Sets the color of the text based on background color of the desktop
            GUICtrlSetColor($Logon, $txtcolor)
            GUICtrlSetColor($Exit, $txtcolor)
            GUICtrlSetColor($Logoff, $txtcolor)
            GUICtrlSetColor($Notepad, $txtcolor)
            GUICtrlSetColor($Outlook, $txtcolor)
            Return          
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
Link to comment
Share on other sites

Hi

I think you want to post this in the examples forum. If you click report on the bottom left of the page, someone will move it for you.

Anyways. I think you did a good job on this. I have solved your blinking problem, see attached. Might want to set up an ini file and reference it. Set your icons from that. That way when compiled you can still tweak.

Thanks,

What did you change?, BTW I did report it to have it moved.

Roger

Link to comment
Share on other sites

It's the shownoactivate that makes the difference. The $WS_EX_TOOLWINDOW just removes it from the taskbar.

What your script was doing is changing the focus to your gui when it is shown and reverting to the previous window in the z order when it is hidden. The think that shownoactivate does just as it says and doesn't show that the window is active.

Link to comment
Share on other sites

It's the shownoactivate that makes the difference. The $WS_EX_TOOLWINDOW just removes it from the taskbar.

What your script was doing is changing the focus to your gui when it is shown and reverting to the previous window in the z order when it is hidden. The think that shownoactivate does just as it says and doesn't show that the window is active.

Okay thanks! I added it to the base code: Now I have another issue, based on your suggestion of using a ini file.

Link to comment
Share on other sites

Okay, I now have a new issue: taking the idea of creating a ini file to make the Launchbar use to create icons, and applications I ran into some issues:

Installion code and functions which create the Data.ini file

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=c:\launchbar\installer.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#Include <File.au3>
ProgressOn("Product Installation", "Installing Launchbar", "0 percent")
InstallerProcess(10)
$err = IniWrite("C:\Launchbar\Data\Data.ini", "Notepad", "Icon","notepad.exe")
If $err = 0 Then 
_FileWriteLog("C:\Program Files\Launchbar\Log\Launchbar.log", "Ini write Error line 7"&":"&@error)
EndIf
InstallerProcess(20)
$err = IniWrite("C:\Launchbar\Data\Data.ini", "Notepad", "IconValue","2")
If $err = 0 Then 
_FileWriteLog("C:\Program Files\Launchbar\Log\Launchbar.log", "Ini write Error line 12"&":"&@error)
EndIf

InstallerProcess(30)
$err = IniWrite("C:\Launchbar\Data\Data.ini", "Outlook", "Icon","C:\Program Files\Microsoft Office\Office12\Outlook.exe")
If $err = 0 Then 
_FileWriteLog("C:\Program Files\Launchbar\Log\Launchbar.log", "Ini write Error line 18"&":"&@error)
EndIf
InstallerProcess(40)
$err = IniWrite("C:\Launchbar\Data\Data.ini", "Outlook", "IconValue","1")
If $err = 0 Then 
_FileWriteLog("C:\Program Files\Launchbar\Log\Launchbar.log", "Ini write Error line 23"&":"&@error)
EndIf
InstallerProcess(50)
$installed = FileExists("C:\Program Files\Launchbar\Launchbar.exe")
If $installed = 0 Then
InstallerProcess(60)
$err = FileCopy( "C:\launchbar\Bin\launchbar.exe", "C:\Program Files\Launchbar\Bin" & "\",1+8 )
If $err = 0 Then 
_FileWriteLog("C:\Program Files\Launchbar\Log\Launchbar.log", "File copy error line 31"&":"&@error)
EndIf
InstallerProcess(75)
$err = FileCopy("C:\Launchbar\Data\Data.ini","C:\Program Files\Launchbar\Data" & "\",1+8)
If $err = 0 Then 
_FileWriteLog("C:\Program Files\Launchbar\Log\Launchbar.log", "File copy error line 36"&":"&@error)
EndIf
$err = FileCopy("C:\Launchbar\Log\Launchbar.log","C:\Program Files\Launchbar\Log" & "\",1+8)
If $err = 0 Then 
_FileWriteLog("C:\Program Files\Launchbar\Log\Launchbar.log", "File copy error line 40"&":"&@error)
EndIf
InstallerProcess(100)
EndIf
InstallerProcess(100)
Func InstallerProcess($i)
                        
            ProgressSet( $i, $i & " percent")
            Sleep(100)
            If $i = 100 Then
            ProgressSet(100 , "Done", "Installation Complete")
            sleep(1000)
            ProgressOff()
            EndIf
            
EndFunc

The installer works as it should, my problem has been how to dig through the file and dynamically create the icons and the such with an Array function which I think I should use.

Here some code I was working on but having issues: (I think I need a Array with the following data stored)

[Notepad]

Icon=notepad.exe

IconValue=2

[Outlook]

Icon=C:\Program Files\Microsoft Office\Office12\Outlook.exe

IconValue=1

_ArrayDisplay($AppArray, "$avArray BEFORE _ArrayAdd()"); Just FYI
$apps = IniReadSectionNames($inifile)
If @error Then 
MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
For $i = 1 To $apps[0]
    _ArrayAdd($AppArray, $apps[$i])
    $icons = IniReadSection ($inifile, $apps[$i] )
           For $s = 1 To $icons[0][0]
               _ArrayAdd($AppArray, $icons[$s][0])
               _ArrayAdd($AppArray, $icons[$s][1])
                        
           Next
Next

_ArrayDisplay($AppArray, "$avArray AFTER _ArrayAdd()"); Just FYI            

EndIf

Source

Goal, but must be useable and unique when these values are used again, seem array would resolve, but my example seems to flat. I think I need a 3 column Array. I hope this makes sense?

$apps[$i] = GUICtrlCreateButton("",9,104,32,32,$BS_ICON)

GUICtrlSetImage($apps[$i],$icons[$s][0],$icons[$s][1])

$apps[$i] = GUICtrlCreateLabel($apps[$i],4,138,40,12,$SS_CENTER)

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#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, $s, $btn, _
$v, $loc, $icon, $iconValue, $AppArray, $icons

$userlog = 0
$inifile = "c:\Program Files\Launchbar\Data\Data.ini"
Launchbar()

; example 1

Func Launchbar()
                Local $AppArray[1]
                $AppArray[0] = ""

                $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)
                        
                        
                        $btn1 = GUICtrlCreateButton("",9,4,32,32,$BS_ICON)
                        $btn2 = GUICtrlCreateButton("",9,54,32,32,$BS_ICON)
                                            
                        
                        GUICtrlSetImage($btn2,"shell32.dll",240)
                        $Exit = GUICtrlCreateLabel("EXIT",9,88,32,12,$SS_CENTER)
                        
                        If $userlog = 1 Then
                    
                            $loc = 104  
                            
                            GUICtrlSetImage($btn1,"shell32.dll",329)
                            $Logoff = GUICtrlCreateLabel("Logoff",9,38,32,12,$SS_CENTER)
                            _ArrayDisplay($AppArray, "$avArray BEFORE _ArrayAdd()")
                            $apps = IniReadSectionNames($inifile)
                            If @error Then 
                                MsgBox(4096, "", "Error occurred, probably no INI file.")
                            Else
                                For $i = 1 To $apps[0]
                                _ArrayAdd($AppArray, $apps[$i])
                                $icons = IniReadSection ($inifile, $apps[$i] )
                                    For $s = 1 To $icons[0][0]
                                    _ArrayAdd($AppArray, $icons[$s][0])
                                    _ArrayAdd($AppArray, $icons[$s][1])
                                    
                                    Next
                                Next
                            _ArrayDisplay($AppArray, "$avArray AFTER _ArrayAdd()")          
                            EndIf
                     
                        Else
                        
                        GUICtrlSetImage($btn1,"shell32.dll",331)
                        $Logon = GUICtrlCreateLabel("Login",9,38,32,12,$SS_CENTER)
                        
                        EndIf
                                
                        GUISetState()
                        
                        While 1
                            sleep(10)
                            $mPos = MouseGetPos()
                            $msg = GUIGetMsg()
                                
                                    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 = $btn1
                                                        If $userlog = 0 Then 
                                                            LogonDialog()
                                                        Else
                                                            $userlog = 0
                                                            GUIDelete()
                                                            Launchbar()
                                                        EndIf
                                                                                
                                        Case $msg = $btn2
                                                        _exit()
                                        
                                        Case $msg = $btn3 ; executes notepad when the notepad button is pressed
                                                        If $userlog = 1 Then
                                                        ;run("notepad.exe")
                                                    EndIf
                                        Case $msg = $btn4
                                                        If $userlog = 1 Then
                                                        ;run("C:\Program Files\Microsoft Office\Office12\outlook.exe")
                                                        EndIf           
                                                
                                    EndSelect
                        WEnd
                    

EndFunc   

Func ShowToolbar()
            Sleep(25)
            GUISetState(@SW_SHOWNOACTIVATE, $maxbar)
            GUISetState($WS_EX_TOPMOST,$maxbar)
            $color = PixelGetColor(4,100) ;check the background color and based on the color value sets black or white
            If $color > 40000 Then 
            $txtcolor = 0x000000
            Else
            $txtcolor = 0xFFFFFF
            EndIf
            GUICtrlSetDefColor ($txtcolor)
            Return $txtcolor          
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
Link to comment
Share on other sites

Hi again,

You're most of the way there.

If I were to do it I would make a 4 wide array and include the buttonhandle as the 4th entry. The below code is untested but demonstrates how I would go about it. Probably could be combined into 1 for loop but for simplicity I leave as two.

Good luck.

;set up the array
                    $iconnames=IniReadSectionNames("launchbar.ini")
                    redim $iconnames[$iconnames[0]][4]
                    for $i=1 to $iconnames[0][0]
                        $sectioninfo=IniReadSection("launchbar.ini",$iconnames[$i][0]
                        $iconnames[$i][1]=$sectioninfo[1][1]
                        $iconnames[$i][2]=$sectioninfo[2][1]
                    Next
                ;set up the buttons
                    $down=4
                    for $i=1 to $iconnames[0][0]
                        $iconnames[$i][4] = GUICtrlCreateButton("",9,$down,32,32,$BS_ICON)
                        GUICtrlSetImage($iconnames[$i][4],$iconnames[$i][1],$iconnames[$i][2])
                        $down=$down+50
                    Next
Link to comment
Share on other sites

Here is were I am

ini file

[Notepad]

Icon=notepad.exe

IconValue=2

Handle=NPHandle

[Outlook]

Icon=C:\Program Files\Microsoft Office\Office12\Outlook.exe

IconValue=1

Handle=OLHandle

$apps = IniReadSectionNames($inifile)
    If @error Then 
    MsgBox(4096, "", "Error occurred, probably no INI file.")
    Else
    ReDim $apps[$apps[0]][4]
    $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] <-- Line 61
    Next
        _ArrayDisplay($apps,"$apps values have been imported")
    EndIf

the issue I have is when all the sections are parsed I get an Array exceeded error

C:\Launchbar\Launchbar.au3 (61) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

yet it does load notepad and outllok correct, it tries one more time and fails. I used _ARRAYDISPLAY to confirm the proper addition, it the blank one that fails

Link to comment
Share on other sites

hmmm. array was dimmed large enough

try changing the redim to this.

ReDim $apps[$apps[0]+1][4]

----------------------------

Correction: I responded to quickly I know the problem.

there is no 3rd dimension of $sectioninfo[3][1]

$sectioninfo is a 2 dimensional array

Edited by picea892
Link to comment
Share on other sites

hmmm. array was dimmed large enough

try changing the redim to this.

ReDim $apps[$apps[0]+1][4]

----------------------------

Correction: I responded to quickly I know the problem.

there is no 3rd dimension of $sectioninfo[3][1]

$sectioninfo is a 2 dimensional array

For $i=1 to $getapps[0]

$sectioninfo=IniReadSection($inifile,$getapps[$i])

$apps[$i][0]=$getapps[$i][0] <-- is now a problem

$apps[$i][1]=$sectioninfo[1][1]

$apps[$i][2]=$sectioninfo[2][1]

;$apps[$i][3]=$sectioninfo[3][1] <--to get this value how would you?

Next

Qu:

I was trying to use the Section Name as a variable, maybe I should not?

My thought was to create Array like this

AppName,IconName,IconValue,BtnHandle

Ex. Notepad, notepad.exe, 2, NPHandle

Should I create a Key for the application name

[Notepad]

Application=NotePad

IconName=notepad.exe

IconHandle=2

Handle=NPHandle

Or create a Generic Section

[Programs]

Application = Notepad

IconName=notepad.exe

IconHandle=2

Handle=NPHandle

Edited by RogFleming
Link to comment
Share on other sites

Solution Maybe? I think there is an issue with the Apps Array not having room for the new data. So I added addition Section [END] and add a -1 to the For Next Loop. It works now!

INI file

[Notepad]

Icon=notepad.exe

IconValue=2

Handle=NPHandle

[Outlook]

Icon=C:\Program Files\Microsoft Office\Office12\Outlook.exe

IconValue=1

Handle=OLHandle

[END]

Logic

$apps = IniReadSectionNames($inifile)
    If @error Then 
        MsgBox(4096, "", "Error occurred, probably no INI file.")
    Else
        ReDim $apps[$apps[0]][4]
        
        $getapps = IniReadSectionNames($inifile)
        
        For $i=1 to $getapps[0]-1 Step 1
                
                $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]
        Next
        _ArrayDisplay($apps,"Master Array update is complete.")
    EndIf
Link to comment
Share on other sites

$apps = IniReadSectionNames($inifile)

If @error Then

MsgBox(4096, "", "Error occurred, probably no INI file.")

Else

ReDim $apps[$apps[0]+1][4] <--- Corrected the issue

$getapps = IniReadSectionNames($inifile)

For $i=1 to $getapps[0]-1 Step 1

$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]

Next

_ArrayDisplay($apps,"Master Array update is complete.")

EndIf

Else

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...