Bowmore Posted September 18, 2009 Posted September 18, 2009 (edited) Whenever the statusbar is hidden by being minimised, moved off the screen or covered by another GUI any icons in the status bar need to be refreshed. By searching the forums and trying quite a few different things I have found the method below that appears to work OK. However I have a gut feeling that I am doing this completly the wrong way, but at the moment I'm at a loss as to how else it might be done. I'd be greateful if someone with more knowledge, of inner workings of GUIs, than myself could have a look at my code and point out the errors of my method. Thanks expandcollapse popup;Add some icons for use in compiled version of script #AutoIt3Wrapper_Res_Icon_Add=C:\AutoIt3Data\Icons\Icons\au3.ico #AutoIt3Wrapper_Res_Icon_Add=C:\AutoIt3Data\Icons\Icons\Autoit_old1.ico #AutoIt3Wrapper_Res_Icon_Add=C:\AutoIt3Data\Icons\Icons\Autoit_old2.ico #AutoIt3Wrapper_Res_Icon_Add=C:\AutoIt3Data\Icons\Icons\Autoit_old3.ico #AutoIt3Wrapper_Res_Icon_Add=C:\AutoIt3Data\Icons\Icons\filetype-blank.ico #AutoIt3Wrapper_Res_Icon_Add=C:\AutoIt3Data\Icons\redsquare.ico #AutoIt3Wrapper_Res_Icon_Add=C:\AutoIt3Data\Icons\greensquare.ico #include <ButtonConstants.au3> #include <GuiConstantsEx.au3> #include <GuiStatusBar.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <Constants.au3> Global $GUI_Statusbar = 0 Global $GUI_Main = 0 Global $g_aStatusbarParts[6] = [75, 150, 225, 300, 375, -1] GUIRegisterMsg($WM_PAINT, "WM_PAINT") ; Create GUI $GUI_Main = GUICreate("(Example 2) StatusBar Set Icon", 400, 300) $GUI_Statusbar = _GUICtrlStatusBar_Create ($GUI_Main) ; Set parts _GUICtrlStatusBar_SetParts ($GUI_Statusbar, $g_aStatusbarParts) _GUICtrlStatusBar_SetText ($GUI_Statusbar, "Part 1") _GUICtrlStatusBar_SetText ($GUI_Statusbar, "Part 2", 1) ; Set icons _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 0, 0, @AutoItExe) _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 1, 2, @AutoItExe) _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 2, 3, @AutoItExe) _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 3, 0, @AutoItExe) _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 4, 2, @AutoItExe) _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 5, 3, @AutoItExe) GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Exit Func WM_PAINT($hWnd, $Msg, $wParam, $lParam) ; Is it neccessary to remove icons before resetting them again? _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 0, -1, @AutoItExe) _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 1, -1, @AutoItExe) _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 2, -1, @AutoItExe) _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 3, -1, @AutoItExe) _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 4, -1, @AutoItExe) _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 5, -1, @AutoItExe) ;Is this the correct method to redraw the icons _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 0, 0, @AutoItExe) _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 1, 2, @AutoItExe) _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 2, 3, @AutoItExe) _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 3, 0, @AutoItExe) _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 4, 2, @AutoItExe) _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 5, 3, @AutoItExe) Return $GUI_RUNDEFMSG EndFunc;==>WM_NCPAINT Edited September 18, 2009 by Bowmore "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook
ProgAndy Posted September 18, 2009 Posted September 18, 2009 You have to preload the icons, then they are not deleted Here is an example. expandcollapse popup;Add some icons for use in compiled version of script #AutoIt3Wrapper_Res_Icon_Add=C:\AutoIt3Data\Icons\Icons\au3.ico #AutoIt3Wrapper_Res_Icon_Add=C:\AutoIt3Data\Icons\Icons\Autoit_old1.ico #AutoIt3Wrapper_Res_Icon_Add=C:\AutoIt3Data\Icons\Icons\Autoit_old2.ico #AutoIt3Wrapper_Res_Icon_Add=C:\AutoIt3Data\Icons\Icons\Autoit_old3.ico #AutoIt3Wrapper_Res_Icon_Add=C:\AutoIt3Data\Icons\Icons\filetype-blank.ico #AutoIt3Wrapper_Res_Icon_Add=C:\AutoIt3Data\Icons\redsquare.ico #AutoIt3Wrapper_Res_Icon_Add=C:\AutoIt3Data\Icons\greensquare.ico #include <ButtonConstants.au3> #include <GuiConstantsEx.au3> #include <GuiStatusBar.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <Constants.au3> Global $GUI_Statusbar = 0 Global $GUI_Main = 0 Global $g_aStatusbarParts[6] = [75, 150, 225, 300, 375, -1] ; Create GUI $GUI_Main = GUICreate("(Example 2) StatusBar Set Icon", 400, 300) $GUI_Statusbar = _GUICtrlStatusBar_Create ($GUI_Main) GUISetState() ; Set parts _GUICtrlStatusBar_SetParts ($GUI_Statusbar, $g_aStatusbarParts) _GUICtrlStatusBar_SetText ($GUI_Statusbar, "Part 1") _GUICtrlStatusBar_SetText ($GUI_Statusbar, "Part 2", 1) ; Load Icons and save icon handles in Array for deletion in OnAutoItExit Global $g_aStatusbarIcons[6] = [ _ _WinAPI_ExtractIcon(@AutoItExe,0), _ _WinAPI_ExtractIcon(@AutoItExe,2), _ _WinAPI_ExtractIcon(@AutoItExe,3), _ _WinAPI_ExtractIcon(@AutoItExe,0), _ _WinAPI_ExtractIcon(@AutoItExe,2), _ _WinAPI_ExtractIcon(@AutoItExe,3) _ ] ; Set icons _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 0, $g_aStatusbarIcons[0]) _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 1, $g_aStatusbarIcons[1]) _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 2, $g_aStatusbarIcons[2]) _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 3, $g_aStatusbarIcons[3]) _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 4, $g_aStatusbarIcons[4]) _GUICtrlStatusBar_SetIcon ($GUI_Statusbar, 5, $g_aStatusbarIcons[5]) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Exit Func OnAutoItExit() For $i = 0 To UBound($g_aStatusbarIcons)-1 _WinAPI_DestroyIcon($g_aStatusbarIcons[$i] Next EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _WinAPI_ExtractIcon ; Description ...: Extracts an Icon from an Exe-File ; Syntax.........: _WinAPI_ExtractIcon($sFile, $iIndex, $iSize=0) ; Parameters ....: $sFile - Icon File ; $iIndex - Icon Index ; $iSize - Large: 1 ; Small: 0 (default) ; Return values .: Success - hIcon handle ; Failure - 0 ; Author ........: Prog@ndy ; Modified.......: ; Remarks .......: ; Related .......: _WinAPI_ExtractIconEx ; Link ..........; ; Example .......; Yes ; =============================================================================================================================== Func _WinAPI_ExtractIcon($sFile, $iIndex, $iSize=0) ; Author: Prog@ndy Local $hIcon = DllStructCreate("ptr"), $result Switch $iSize Case 1 $result = _WinAPI_ExtractIconEx($sFile, $iIndex, DllStructGetPtr($hIcon),0,1) Case 0 $result = _WinAPI_ExtractIconEx($sFile, $iIndex, 0, DllStructGetPtr($hIcon),1) EndSwitch If $result=0 Then Return SetError(1,0,0) Return DllStructGetData($hIcon,1) EndFunc *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
Bowmore Posted September 18, 2009 Author Posted September 18, 2009 (edited) On 9/18/2009 at 5:22 PM, 'ProgAndy said: You have to preload the icons, then they are not deleted Here is an example.Thank you very much for the example. I just knew what I was doing, even though it gave me the end result I was looking for, could not right.It's been a good day for learning new things. I've learned quite a few things trying to get this to work. Edited September 18, 2009 by Bowmore "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook
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