Jump to content
Sign in to follow this  
MadBoy

Possible bug but wanted to confirm before reporting

Recommended Posts

MadBoy

Below is example 2 from _GUICtrlStatusBar_SetText in Help File.

#include <GuiConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

$Debug_SB = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

Global $iMemo

Example2()

Func Example2()

    Local $hGUI, $hStatus
    Local $aParts[4] = [75, 150, 300, 400]

    ; Create GUI
    $hGUI = GUICreate("(Example 2) StatusBar Set Icon", 400, 300)
    $hStatus = _GUICtrlStatusBar_Create ($hGUI)

    ; Create memo control
    $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 274, $WS_VSCROLL)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState()

    ; Set parts
    _GUICtrlStatusBar_SetParts ($hStatus, $aParts)
    _GUICtrlStatusBar_SetText ($hStatus, "Part 1")
    _GUICtrlStatusBar_SetText ($hStatus, "Part 2", 1)

    ; Set icons
    _GUICtrlStatusBar_SetIcon ($hStatus, 0, 23, "shell32.dll")
    _GUICtrlStatusBar_SetIcon ($hStatus, 1, 40, "shell32.dll")

    ; Show icon handles
    MemoWrite("Part 1 icon handle .: 0x" & Hex(_GUICtrlStatusBar_GetIcon ($hStatus, 0)))
    MemoWrite("Part 2 icon handle .: 0x" & Hex(_GUICtrlStatusBar_GetIcon ($hStatus, 1)))


    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example2

; Write message to memo
Func MemoWrite($sMessage = "")
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

This works fine. Now if you change the order of _GUICtrlStatusBar_SetIcon and _GUICtrlStatusBar_SetText icons are not shown.

_GUICtrlStatusBar_SetIcon ($hStatus, 0, 23, "shell32.dll")
    _GUICtrlStatusBar_SetIcon ($hStatus, 1, 40, "shell32.dll")
    _GUICtrlStatusBar_SetText ($hStatus, "Part 1")
    _GUICtrlStatusBar_SetText ($hStatus, "Part 2", 1)

Is it a bug that text clears icons and that Icons always have to be added last or is it a feature and it's the way it should be that Text always goes before Icon. I spent some time working out why it wouldn't work when i mixed up ordering of those 2 functions. Maybe this could/should be mentioned in the helpfile so ppl like me wouldn't spend too much time on such things :)

Thanks,

MadBoy

Edit:

Fixed typo

Edited by MadBoy

My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites
MadBoy

Also I've just noticed that in my program when i have code like below. When i watch program running and doing updates (using _UpdateStatusBar function) of status bar icons show up and work, when i click away (to firefox or some other program) and come back the icons are gone (although the program itself wasn't doing anything besides waiting for me to do something).

Global $StatusBar = _GUICtrlStatusBar_Create($Gui_Main)
Global $aParts[2] = [100, -1]
_GUICtrlStatusBar_SetParts($StatusBar, $aParts)
_UpdateStatusBar("Ready", "Waiting for user interaction..")

Func _UpdateStatusBar($Text1, $Text2)
        _GUICtrlStatusBar_SetText($StatusBar, $Text1)
    _GUICtrlStatusBar_SetText($StatusBar, $Text2, 1)
        _GUICtrlStatusBar_SetIcon($StatusBar, 0, 21, "shell32.dll") ; 21
    _GUICtrlStatusBar_SetIcon($StatusBar, 1, 167, "shell32.dll") ; 167


EndFunc   ;==>_UpdateStatusBar

My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites
MadBoy

So does anyone know if it's my bad habit or it's a bug?


My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites
Bowmore

So does anyone know if it's my bad habit or it's a bug?

It's not a bug.

I had a similar problem a while ago and ProgAndy showed me the solution. You need to extract the icon from the source file and use it's handel. The icon is then correctly redrawn whenever it needs to be, i.e. when you update the contents of the statustbar.

Your original example modified to show this behaviour.

#include <GuiConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

$Debug_SB = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

Global $iMemo

Example2()

Func Example2()

    Local $hGUI, $hStatus
    Local $aParts[4] = [75, 150, 300, 400]

    ; Create GUI
    $hGUI = GUICreate("(Example 2) StatusBar Set Icon", 400, 300)
    $hStatus = _GUICtrlStatusBar_Create ($hGUI)

    ; Create memo control
    $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 274, $WS_VSCROLL)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState()

    ; Set parts
    _GUICtrlStatusBar_SetParts ($hStatus, $aParts)
    _GUICtrlStatusBar_SetText ($hStatus, "Part 1")
    _GUICtrlStatusBar_SetText ($hStatus, "Part 2", 1)

    ; Set icons
    _GUICtrlStatusBar_SetIcon ($hStatus, 0, _WinAPI_ExtractIcon("shell32.dll",23)) ;<<==== icon remains visible
    _GUICtrlStatusBar_SetIcon ($hStatus, 1, 40, "shell32.dll") ; <<===== icon is lost on rdraw
   _GUICtrlStatusBar_SetText ($hStatus, "Part 1")
    _GUICtrlStatusBar_SetText ($hStatus, "Part 2", 1)

    ; Show icon handles
    MemoWrite("Part 1 icon handle .: 0x" & Hex(_GUICtrlStatusBar_GetIcon ($hStatus, 0)))
    MemoWrite("Part 2 icon handle .: 0x" & Hex(_GUICtrlStatusBar_GetIcon ($hStatus, 1)))
;~ _WinAPI_ExtractIcon(@AutoItExe,2)

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example2

; Write message to memo
Func MemoWrite($sMessage = "")
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite
; #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

"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

Share this post


Link to post
Share on other sites
MadBoy

It's not a bug.

I had a similar problem a while ago and ProgAndy showed me the solution. You need to extract the icon from the source file and use it's handel. The icon is then correctly redrawn whenever it needs to be, i.e. when you update the contents of the statustbar.

Your original example modified to show this behaviour.

#include <GuiConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

$Debug_SB = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

Global $iMemo

Example2()

Func Example2()

    Local $hGUI, $hStatus
    Local $aParts[4] = [75, 150, 300, 400]

    ; Create GUI
    $hGUI = GUICreate("(Example 2) StatusBar Set Icon", 400, 300)
    $hStatus = _GUICtrlStatusBar_Create ($hGUI)

    ; Create memo control
    $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 274, $WS_VSCROLL)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState()

    ; Set parts
    _GUICtrlStatusBar_SetParts ($hStatus, $aParts)
    _GUICtrlStatusBar_SetText ($hStatus, "Part 1")
    _GUICtrlStatusBar_SetText ($hStatus, "Part 2", 1)

    ; Set icons
    _GUICtrlStatusBar_SetIcon ($hStatus, 0, _WinAPI_ExtractIcon("shell32.dll",23)) ;<<==== icon remains visible
    _GUICtrlStatusBar_SetIcon ($hStatus, 1, 40, "shell32.dll") ; <<===== icon is lost on rdraw
   _GUICtrlStatusBar_SetText ($hStatus, "Part 1")
    _GUICtrlStatusBar_SetText ($hStatus, "Part 2", 1)

    ; Show icon handles
    MemoWrite("Part 1 icon handle .: 0x" & Hex(_GUICtrlStatusBar_GetIcon ($hStatus, 0)))
    MemoWrite("Part 2 icon handle .: 0x" & Hex(_GUICtrlStatusBar_GetIcon ($hStatus, 1)))
;~ _WinAPI_ExtractIcon(@AutoItExe,2)

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example2

; Write message to memo
Func MemoWrite($sMessage = "")
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite
; #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

Tnx bowmore ;-) works great now

My little company: Evotec (PL version: Evotec)

Share this post


Link to post
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
Sign in to follow this  

×