Jump to content
Sign in to follow this  
jennico

GUISetIcon without $WM_DRAWITEM message ?

Recommended Posts

jennico

Is it possible to suppress the $WM_DRAWITEM message for the special action of changing GUI icon (GUISetIcon) ?

i guess no, because the new icon will not be shown then (?). but i am not sure about it.

and if this is not possible (as i assume), could i limit the redraw action just to the titlebar, and how ?

the reason is: i have a really big GUI with lots of ownerdrawn items and i want to avoid the redraw action (lots of flickering) when only the GUI icon is being changed.

thx in advance

j.


Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites
martin

Is it possible to suppress the $WM_DRAWITEM message for the special action of changing GUI icon (GUISetIcon) ?

i guess no, because the new icon will not be shown then (?). but i am not sure about it.

and if this is not possible (as i assume), could i limit the redraw action just to the titlebar, and how ?

the reason is: i have a really big GUI with lots of ownerdrawn items and i want to avoid the redraw action (lots of flickering) when only the GUI icon is being changed.

thx in advance

j.

If you want to deal with the icon in the window title bar then I don't think $WM_DRAWITEM is relevant. If you do want to suoppress $WM_DRAWITEM then you just have to handle it and return True.

The meassge $WM_NCPAINT is sent when the non client are of a window is redrawn so perhaps that would be what you need to deal with.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
jennico

try this example adapted from helpfile. run it from console.

it seems to me that guiseticon inevitably calls MY_WM_DRAWITEM.

; *******************************************************
; Example - Create an ownerdrawn/colored button
; *******************************************************

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>

Example()

Func Example()
    Local Const $BS_OWNERDRAW = 0x0000000B
    Global $hGUI, $nButton, $nButton2, $GUIMsg

    $hGUI = GUICreate("My Ownerdrawn Created Button", 300, 200)

    $nButton = GUICtrlCreateButton("", 90, 50, 120, 30)
    GUICtrlSetStyle($nButton, BitOR($WS_TABSTOP, $BS_NOTIFY, $BS_OWNERDRAW)) ; Set the ownerdrawn flag

    $nButton2 = GUICtrlCreateButton("Normal Button", 90, 110, 120, 30)

    GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
    ; WM_DRAWITEM has to registered before showing GUI otherwise the initial drawing isn't done
    GUIRegisterMsg($WM_DRAWITEM, "MY_WM_DRAWITEM")
    GUIRegisterMsg($WM_NCPAINT, "WM_NCPAINT")

    GUISetState()

    While 1
        $GUIMsg = GUIGetMsg()
        
        Switch $GUIMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop
                
            Case $nButton
                ; Normally should not run through cause of our MY_WM_COMMAND function
                MsgBox(0, "Info", "Button pressed")
            Case $nButton2
                ; Normally should not run through cause of our MY_WM_COMMAND function
                MsgBox(0, "Info", "Button2 pressed")
        EndSwitch
    WEnd
EndFunc   ;==>Example

Func WM_NCPAINT($hWnd, $Msg, $wParam, $lParam)
    ConsoleWrite("ncpaint called"&@LF)
    Return $GUI_RUNDEFMSG
EndFunc

; React on a button click
Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
    $hCtrl = $lParam
    
    If $nID <> 2 And $nNotifyCode = 0 Then ; Check for IDCANCEL - 2
        ; Ownerdrawn buttons don't send something by pressing ENTER
        ; So IDOK - 1 comes up, now check for the control that has the current focus
        If $nID = 1 Then
            $hFocus = DllCall("user32.dll", "hwnd", "GetFocus")
            $nCtrlID = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $hFocus[0])
            PostButtonclick($hWnd, $nCtrlID[0])
        Else
            If $nID=$nButton2 Then GUISetIcon("shell32.dll",0)
            ;comment this out to see that no drawitem happens
        EndIf
        Return 0 ; Only workout clicking on the button
    EndIf
    ; Proceed the default Autoit3 internal message commands.
    ; You also can complete let the line out.
    ; !!! But only 'Return' (without any value) will not proceed
    ; the default Autoit3-message in the future !!!
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_COMMAND


; RePost a WM_COMMAND message to a ctrl in a gui window
Func PostButtonclick($hWnd, $nCtrlID)
    DllCall("user32.dll", "int", "PostMessage", _
            "hwnd", $hWnd, _
            "int", $WM_COMMAND, _
            "int", BitAND($nCtrlID, 0x0000FFFF), _
            "hwnd", GUICtrlGetHandle($nCtrlID))
EndFunc   ;==>PostButtonclick


; Draw the button
Func MY_WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
    Local $stDrawItem = DllStructCreate("uint;uint;uint;uint;uint;uint;uint;int[4];dword", $lParam)
    Local Const $ODT_BUTTON = 4
    ConsoleWrite("drawiten called  -  lparam = "&$lParam&@LF)
    $nCtlType = DllStructGetData($stDrawItem, 1)
    If $nCtlType = $ODT_BUTTON Then
        $nCtrlID = DllStructGetData($stDrawItem, 2)
        $nItemState = DllStructGetData($stDrawItem, 5)
        $hCtrl = DllStructGetData($stDrawItem, 6)
        $hDC = DllStructGetData($stDrawItem, 7)
        $nLeft = DllStructGetData($stDrawItem, 8, 1)
        $nTop = DllStructGetData($stDrawItem, 8, 2)
        $nRight = DllStructGetData($stDrawItem, 8, 3)
        $nBottom = DllStructGetData($stDrawItem, 8, 4)
        $sText = "Ownerdrawn Button"
        $nTextColor = 0x5555DD
        $nBackColor = 0xFFEEDD
        DrawButton($hWnd, $hCtrl, $hDC, $nLeft, $nTop, $nRight, $nBottom, $nItemState, $sText, $nTextColor, $nBackColor)
        $stDrawItem = 0
        Return 1
    EndIf

    $stDrawItem = 0
    Return $GUI_RUNDEFMSG ; Proceed the default Autoit3 internal message commands
EndFunc   ;==>MY_WM_DRAWITEM


; The main drawing procedure
Func DrawButton($hWnd, $hCtrl, $hDC, $nLeft, $nTop, $nRight, $nBottom, $nItemState, $sText, $nTextColor, $nBackColor)
    ;Local $bDefault    = FALSE
    Local Const $GWL_STYLE = -16
    Local Const $ODS_SELECTED = 0x0001
    Local Const $ODS_GRAYED = 0x0002
    Local Const $ODS_DISABLED = 0x0004
    Local Const $ODS_CHECKED = 0x0008
    Local Const $ODS_FOCUS = 0x0010
    Local Const $ODS_HOTLIGHT = 0x0040
    Local Const $ODS_INACTIVE = 0x0080
    Local Const $ODS_NOACCEL = 0x0100
    Local Const $ODS_NOFOCUSRECT = 0x0200
    Local Const $DFC_BUTTON = 4
    Local Const $DFCS_BUTTONPUSH = 0x0010
    Local $bChecked = BitAND($nItemState, $ODS_CHECKED)
    Local $bFocused = BitAND($nItemState, $ODS_FOCUS)
    Local $bGrayed = BitAND($nItemState, BitOR($ODS_GRAYED, $ODS_DISABLED))
    Local $bSelected = BitAND($nItemState, $ODS_SELECTED)

    $stRect = DllStructCreate("int;int;int;int")
    DllStructSetData($stRect, 1, $nLeft)
    DllStructSetData($stRect, 2, $nTop)
    DllStructSetData($stRect, 3, $nRight)
    DllStructSetData($stRect, 4, $nBottom)
    
    If $bGrayed Then
        $nClrTxt = SetTextColor($hDC, GetSysColor($COLOR_HIGHLIGHTTEXT))
    ElseIf $nTextColor = -1 Then
        $nClrTxt = SetTextColor($hDC, GetSysColor($COLOR_BTNTEXT))
    Else
        $nClrTxt = SetTextColor($hDC, $nTextColor)
    EndIf
    
    If $nBackColor = -1 Then
        $hBrush = GetSysColorBrush($COLOR_BTNFACE)
        $nClrSel = GetSysColor($COLOR_BTNFACE)
    Else
        $hBrush = CreateSolidBrush($nBackColor)
        $nClrSel = $nBackColor;
    EndIf

    $nClrBk = SetBkColor($hDC, $nClrSel)
    $hOldBrush = SelectObject($hDC, $hBrush)

    $nTmpLeft = $nLeft
    $nTmpTop = $nTop
    $nTmpRight = $nRight
    $nTmpBottom = $nBottom
    
    If $bSelected Then
        InflateRect($nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, -1, -1)
        $hBrushSel = CreateSolidBrush(GetSysColor($COLOR_BTNSHADOW))
        FrameRect($hDC, $nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, $hBrushSel)
        DeleteObject($hBrushSel)
    Else
        If $bFocused And Not $bSelected Then InflateRect($nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, -1, -1)
        DrawFrameControl($hDC, $nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, $DFC_BUTTON, $DFCS_BUTTONPUSH)
    EndIf
    
    $nTmpLeft = $nLeft
    $nTmpTop = $nTop
    $nTmpRight = $nRight
    $nTmpBottom = $nBottom
    
    If $bSelected Then
        InflateRect($nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, -2, -2)
    Else
        If $bFocused And Not $bSelected Then
            InflateRect($nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, -3, -3)
            $nTmpLeft -= 1
            $nTmpTop -= 1
        Else
            InflateRect($nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, -2, -2)
            $nTmpLeft -= 1
            $nTmpTop -= 1
        EndIf
    EndIf
    
    FillRect($hDC, $nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, $hBrush)
    
    If $bSelected Or $bGrayed Then
        $nTmpLeft = $nTmpLeft + 2
        $nTmpTop = $nTmpTop + 2
    EndIf
    
    $uFlags = BitOR($DT_NOCLIP, $DT_CENTER, $DT_VCENTER)

    If Not BitAND(GetWindowLong($hCtrl, $GWL_STYLE), $BS_MULTILINE) Then $uFlags = BitOR($uFlags, $DT_SINGLELINE)
    
    DrawText($hDC, $sText, $nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, $uFlags)

    If $bGrayed Then
        $nTmpLeft = $nLeft
        $nTmpTop = $nTop
        $nTmpRight = $nRight
        $nTmpBottom = $nBottom
        
        $nTmpLeft -= 1
        
        $nClrTxt = SetTextColor($hDC, GetSysColor($COLOR_GRAYTEXT))
        DrawText($hDC, $sText, $nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, BitOR($DT_NOCLIP, $DT_CENTER, $DT_VCENTER, $DT_SINGLELINE))
    EndIf

    $nTmpLeft = $nLeft
    $nTmpTop = $nTop
    $nTmpRight = $nRight
    $nTmpBottom = $nBottom
    
    If $bFocused Then
        $hBrush = CreateSolidBrush(0)
        FrameRect($hDC, $nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, $hBrush)
        
        $nTmpLeft = $nLeft
        $nTmpTop = $nTop
        $nTmpRight = $nRight
        $nTmpBottom = $nBottom
        
        InflateRect($nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, -4, -4)
        DrawFocusRect($hDC, $nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom)
    EndIf

    SelectObject($hDC, $hOldBrush)
    DeleteObject($hBrush)
    SetTextColor($hDC, $nClrTxt)
    SetBkColor($hDC, $nClrBk)
    
    Return 1
EndFunc   ;==>DrawButton


; Some graphic / windows functions
Func CreateSolidBrush($nColor)
    Local $hBrush = DllCall("gdi32.dll", "hwnd", "CreateSolidBrush", "int", $nColor)
    Return $hBrush[0]
EndFunc   ;==>CreateSolidBrush


Func GetSysColor($nIndex)
    Local $nColor = DllCall("user32.dll", "int", "GetSysColor", "int", $nIndex)
    Return $nColor[0]
EndFunc   ;==>GetSysColor


Func GetSysColorBrush($nIndex)
    Local $hBrush = DllCall("user32.dll", "hwnd", "GetSysColorBrush", "int", $nIndex)
    Return $hBrush[0]
EndFunc   ;==>GetSysColorBrush


Func DrawFrameControl($hDC, $nLeft, $nTop, $nRight, $nBottom, $nType, $nState)
    Local $stRect = DllStructCreate("int;int;int;int")
    
    DllStructSetData($stRect, 1, $nLeft)
    DllStructSetData($stRect, 2, $nTop)
    DllStructSetData($stRect, 3, $nRight)
    DllStructSetData($stRect, 4, $nBottom)
    
    DllCall("user32.dll", "int", "DrawFrameControl", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "int", $nType, "int", $nState)

    $stRect = 0
EndFunc   ;==>DrawFrameControl


Func DrawFocusRect($hDC, $nLeft, $nTop, $nRight, $nBottom)
    Local $stRect = DllStructCreate("int;int;int;int")
    
    DllStructSetData($stRect, 1, $nLeft)
    DllStructSetData($stRect, 2, $nTop)
    DllStructSetData($stRect, 3, $nRight)
    DllStructSetData($stRect, 4, $nBottom)
    
    DllCall("user32.dll", "int", "DrawFocusRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect))
    
    $stRect = 0
EndFunc   ;==>DrawFocusRect


Func DrawText($hDC, $sText, $nLeft, $nTop, $nRight, $nBottom, $nFormat)
    Local $nLen = StringLen($sText)
    
    Local $stRect = DllStructCreate("int;int;int;int")
    DllStructSetData($stRect, 1, $nLeft)
    DllStructSetData($stRect, 2, $nTop)
    DllStructSetData($stRect, 3, $nRight)
    DllStructSetData($stRect, 4, $nBottom)
    
    Local $stText = DllStructCreate("char[260]")
    DllStructSetData($stText, 1, $sText)
    
    DllCall("user32.dll", "int", "DrawText", "hwnd", $hDC, "ptr", DllStructGetPtr($stText), "int", $nLen, "ptr", DllStructGetPtr($stRect), "int", $nFormat)
    
    $stRect = 0
    $stText = 0
EndFunc   ;==>DrawText


Func FillRect($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBrush)
    Local $stRect = DllStructCreate("int;int;int;int")
    
    DllStructSetData($stRect, 1, $nLeft)
    DllStructSetData($stRect, 2, $nTop)
    DllStructSetData($stRect, 3, $nRight)
    DllStructSetData($stRect, 4, $nBottom)
    
    DllCall("user32.dll", "int", "FillRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)
    
    $stRect = 0
EndFunc   ;==>FillRect


Func FrameRect($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBrush)
    Local $stRect = DllStructCreate("int;int;int;int")
    
    DllStructSetData($stRect, 1, $nLeft)
    DllStructSetData($stRect, 2, $nTop)
    DllStructSetData($stRect, 3, $nRight)
    DllStructSetData($stRect, 4, $nBottom)
    
    DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)
    
    $stRect = 0
EndFunc   ;==>FrameRect


Func InflateRect(ByRef $nLeft, ByRef $nTop, ByRef $nRight, ByRef $nBottom, $nX, $nY)
    Local $stRect = DllStructCreate("int;int;int;int")
    
    DllStructSetData($stRect, 1, $nLeft)
    DllStructSetData($stRect, 2, $nTop)
    DllStructSetData($stRect, 3, $nRight)
    DllStructSetData($stRect, 4, $nBottom)
    
    DllCall("user32.dll", "int", "InflateRect", "ptr", DllStructGetPtr($stRect), "int", $nX, "int", $nY)
    
    $nLeft = DllStructGetData($stRect, 1)
    $nTop = DllStructGetData($stRect, 2)
    $nRight = DllStructGetData($stRect, 3)
    $nBottom = DllStructGetData($stRect, 4)
    
    $stRect = 0
EndFunc   ;==>InflateRect


Func SetBkColor($hDC, $nColor)
    Local $nOldColor = DllCall("gdi32.dll", "int", "SetBkColor", "hwnd", $hDC, "int", $nColor)
    Return $nOldColor[0]
EndFunc   ;==>SetBkColor


Func SetTextColor($hDC, $nColor)
    Local $nOldColor = DllCall("gdi32.dll", "int", "SetTextColor", "hwnd", $hDC, "int", $nColor)
    Return $nOldColor[0]
EndFunc   ;==>SetTextColor


Func SelectObject($hDC, $hObj)
    Local $hOldObj = DllCall("gdi32.dll", "hwnd", "SelectObject", "hwnd", $hDC, "hwnd", $hObj)
    Return $hOldObj[0]
EndFunc   ;==>SelectObject


Func DeleteObject($hObj)
    Local $nResult = DllCall("gdi32.dll", "hwnd", "DeleteObject", "hwnd", $hObj)
EndFunc   ;==>DeleteObject


Func GetWindowLong($hWnd, $nIndex)
    Local $nVal = DllCall("user32.dll", "int", "GetWindowLong", "hwnd", $hWnd, "int", $nIndex)
    Return $nVal[0]
EndFunc   ;==>GetWindowLong

when you click the normal button, the icon changes and window is redrawn. you will see that guiseticon causes drawitem.

when you comment line 65 out you will see that no draw is done (draw is not caused by button click).

(click the button several times)

the lparam cannot be used to identify the redraw caused by iconchange. so i did not find a way to "sort out" and suppress it (by just return). the lparam is not different from normal drawitem calls.

i think i will have to find some kind of workaround.

will look at $WM_NCPAINT first.

j.

edit: i added $WM_NCPAINT to the example. it is not sent when changing icon. :)

Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites
martin

$WM_DRAWITEM is not called for drawing the non-client area as far as I know. It is called for buttons and menus say.

Maybe The message $WM_NCPAINT is only used for the frame. I think $WM_PAINT is used redraw the caption and I think this includes the gui icon.

I assume that GuiSetIcon redraws the whole window so then $WM_DRAWITEM will get called for every control.

If you have no controls, ie no buttons, this us what you get (using $WM_PAINT instead of $MW_NCPAINT

; *******************************************************
; Example - Create an ownerdrawn/colored button
; *******************************************************

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
Global $nButton = 0;
Global $nButton2 = 0
Example()

Func Example()
    Local Const $BS_OWNERDRAW = 0x0000000B
    Global $hGUI, $nButton, $nButton2, $GUIMsg

    $hGUI = GUICreate("My Ownerdrawn Created Button", 300, 200)

;$nButton = GUICtrlCreateButton("", 90, 50, 120, 30)
;GUICtrlSetStyle($nButton, BitOR($WS_TABSTOP, $BS_NOTIFY, $BS_OWNERDRAW)); Set the ownerdrawn flag

;$nButton2 = GUICtrlCreateButton("Normal Button", 90, 110, 120, 30)

    GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
; WM_DRAWITEM has to registered before showing GUI otherwise the initial drawing isn't done
    GUIRegisterMsg($WM_DRAWITEM, "MY_WM_DRAWITEM")
    GUIRegisterMsg($WM_PAINT, "WM_NCPAINT")

    GUISetState()
    For $n = 0 To 5
        GUISetIcon("shell32.dll", $n)
        Sleep(2000)
    Next
    MsgBox(262144,"See what I mean?","ok")
    exit
    While 1
        $GUIMsg = GUIGetMsg()

        Switch $GUIMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $nButton
            ; Normally should not run through cause of our MY_WM_COMMAND function
                MsgBox(0, "Info", "Button pressed")
            Case $nButton2
            ; Normally should not run through cause of our MY_WM_COMMAND function
                MsgBox(0, "Info", "Button2 pressed")
        EndSwitch
    WEnd
EndFunc  ;==>Example

Func WM_NCPAINT($hWnd, $Msg, $wParam, $lParam)
    ConsoleWrite("ncpaint called" & @LF)
    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_NCPAINT

; React on a button click
Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
    $hCtrl = $lParam

    If $nID <> 2 And $nNotifyCode = 0 Then; Check for IDCANCEL - 2
    ; Ownerdrawn buttons don't send something by pressing ENTER
    ; So IDOK - 1 comes up, now check for the control that has the current focus
        If $nID = 1 Then
            $hFocus = DllCall("user32.dll", "hwnd", "GetFocus")
            $nCtrlID = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $hFocus[0])
            PostButtonclick($hWnd, $nCtrlID[0])
        Else
            If $nID = $nButton2 Then GUISetIcon("shell32.dll", 0)
        ;comment this out to see that no drawitem happens
        EndIf
        Return 0; Only workout clicking on the button
    EndIf
; Proceed the default Autoit3 internal message commands.
; You also can complete let the line out.
; !!! But only 'Return' (without any value) will not proceed
; the default Autoit3-message in the future !!!
    Return $GUI_RUNDEFMSG
EndFunc  ;==>MY_WM_COMMAND


; RePost a WM_COMMAND message to a ctrl in a gui window
Func PostButtonclick($hWnd, $nCtrlID)
    DllCall("user32.dll", "int", "PostMessage", _
            "hwnd", $hWnd, _
            "int", $WM_COMMAND, _
            "int", BitAND($nCtrlID, 0x0000FFFF), _
            "hwnd", GUICtrlGetHandle($nCtrlID))
EndFunc  ;==>PostButtonclick


; Draw the button
Func MY_WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
    Local $stDrawItem = DllStructCreate("uint;uint;uint;uint;uint;uint;uint;int[4];dword", $lParam)
    Local Const $ODT_BUTTON = 4
    ConsoleWrite("drawiten called  -  lparam = " & $lParam & @LF)
    $nCtlType = DllStructGetData($stDrawItem, 1)
    If $nCtlType = $ODT_BUTTON Then
        $nCtrlID = DllStructGetData($stDrawItem, 2)
        $nItemState = DllStructGetData($stDrawItem, 5)
        $hCtrl = DllStructGetData($stDrawItem, 6)
        $hDC = DllStructGetData($stDrawItem, 7)
        $nLeft = DllStructGetData($stDrawItem, 8, 1)
        $nTop = DllStructGetData($stDrawItem, 8, 2)
        $nRight = DllStructGetData($stDrawItem, 8, 3)
        $nBottom = DllStructGetData($stDrawItem, 8, 4)
        $sText = "Ownerdrawn Button"
        $nTextColor = 0x5555DD
        $nBackColor = 0xFFEEDD
        DrawButton($hWnd, $hCtrl, $hDC, $nLeft, $nTop, $nRight, $nBottom, $nItemState, $sText, $nTextColor, $nBackColor)
        $stDrawItem = 0
        Return 1
    EndIf

    $stDrawItem = 0
    Return $GUI_RUNDEFMSG; Proceed the default Autoit3 internal message commands
EndFunc  ;==>MY_WM_DRAWITEM


; The main drawing procedure
Func DrawButton($hWnd, $hCtrl, $hDC, $nLeft, $nTop, $nRight, $nBottom, $nItemState, $sText, $nTextColor, $nBackColor)
;Local $bDefault    = FALSE
    Local Const $GWL_STYLE = -16
    Local Const $ODS_SELECTED = 0x0001
    Local Const $ODS_GRAYED = 0x0002
    Local Const $ODS_DISABLED = 0x0004
    Local Const $ODS_CHECKED = 0x0008
    Local Const $ODS_FOCUS = 0x0010
    Local Const $ODS_HOTLIGHT = 0x0040
    Local Const $ODS_INACTIVE = 0x0080
    Local Const $ODS_NOACCEL = 0x0100
    Local Const $ODS_NOFOCUSRECT = 0x0200
    Local Const $DFC_BUTTON = 4
    Local Const $DFCS_BUTTONPUSH = 0x0010
    Local $bChecked = BitAND($nItemState, $ODS_CHECKED)
    Local $bFocused = BitAND($nItemState, $ODS_FOCUS)
    Local $bGrayed = BitAND($nItemState, BitOR($ODS_GRAYED, $ODS_DISABLED))
    Local $bSelected = BitAND($nItemState, $ODS_SELECTED)

    $stRect = DllStructCreate("int;int;int;int")
    DllStructSetData($stRect, 1, $nLeft)
    DllStructSetData($stRect, 2, $nTop)
    DllStructSetData($stRect, 3, $nRight)
    DllStructSetData($stRect, 4, $nBottom)

    If $bGrayed Then
        $nClrTxt = SetTextColor($hDC, GetSysColor($COLOR_HIGHLIGHTTEXT))
    ElseIf $nTextColor = -1 Then
        $nClrTxt = SetTextColor($hDC, GetSysColor($COLOR_BTNTEXT))
    Else
        $nClrTxt = SetTextColor($hDC, $nTextColor)
    EndIf

    If $nBackColor = -1 Then
        $hBrush = GetSysColorBrush($COLOR_BTNFACE)
        $nClrSel = GetSysColor($COLOR_BTNFACE)
    Else
        $hBrush = CreateSolidBrush($nBackColor)
        $nClrSel = $nBackColor;
    EndIf

    $nClrBk = SetBkColor($hDC, $nClrSel)
    $hOldBrush = SelectObject($hDC, $hBrush)

    $nTmpLeft = $nLeft
    $nTmpTop = $nTop
    $nTmpRight = $nRight
    $nTmpBottom = $nBottom

    If $bSelected Then
        InflateRect($nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, -1, -1)
        $hBrushSel = CreateSolidBrush(GetSysColor($COLOR_BTNSHADOW))
        FrameRect($hDC, $nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, $hBrushSel)
        DeleteObject($hBrushSel)
    Else
        If $bFocused And Not $bSelected Then InflateRect($nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, -1, -1)
        DrawFrameControl($hDC, $nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, $DFC_BUTTON, $DFCS_BUTTONPUSH)
    EndIf

    $nTmpLeft = $nLeft
    $nTmpTop = $nTop
    $nTmpRight = $nRight
    $nTmpBottom = $nBottom

    If $bSelected Then
        InflateRect($nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, -2, -2)
    Else
        If $bFocused And Not $bSelected Then
            InflateRect($nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, -3, -3)
            $nTmpLeft -= 1
            $nTmpTop -= 1
        Else
            InflateRect($nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, -2, -2)
            $nTmpLeft -= 1
            $nTmpTop -= 1
        EndIf
    EndIf

    FillRect($hDC, $nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, $hBrush)

    If $bSelected Or $bGrayed Then
        $nTmpLeft = $nTmpLeft + 2
        $nTmpTop = $nTmpTop + 2
    EndIf

    $uFlags = BitOR($DT_NOCLIP, $DT_CENTER, $DT_VCENTER)

    If Not BitAND(GetWindowLong($hCtrl, $GWL_STYLE), $BS_MULTILINE) Then $uFlags = BitOR($uFlags, $DT_SINGLELINE)

    DrawText($hDC, $sText, $nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, $uFlags)

    If $bGrayed Then
        $nTmpLeft = $nLeft
        $nTmpTop = $nTop
        $nTmpRight = $nRight
        $nTmpBottom = $nBottom

        $nTmpLeft -= 1

        $nClrTxt = SetTextColor($hDC, GetSysColor($COLOR_GRAYTEXT))
        DrawText($hDC, $sText, $nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, BitOR($DT_NOCLIP, $DT_CENTER, $DT_VCENTER, $DT_SINGLELINE))
    EndIf

    $nTmpLeft = $nLeft
    $nTmpTop = $nTop
    $nTmpRight = $nRight
    $nTmpBottom = $nBottom

    If $bFocused Then
        $hBrush = CreateSolidBrush(0)
        FrameRect($hDC, $nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, $hBrush)

        $nTmpLeft = $nLeft
        $nTmpTop = $nTop
        $nTmpRight = $nRight
        $nTmpBottom = $nBottom

        InflateRect($nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, -4, -4)
        DrawFocusRect($hDC, $nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom)
    EndIf

    SelectObject($hDC, $hOldBrush)
    DeleteObject($hBrush)
    SetTextColor($hDC, $nClrTxt)
    SetBkColor($hDC, $nClrBk)

    Return 1
EndFunc  ;==>DrawButton


; Some graphic / windows functions
Func CreateSolidBrush($nColor)
    Local $hBrush = DllCall("gdi32.dll", "hwnd", "CreateSolidBrush", "int", $nColor)
    Return $hBrush[0]
EndFunc  ;==>CreateSolidBrush


Func GetSysColor($nIndex)
    Local $nColor = DllCall("user32.dll", "int", "GetSysColor", "int", $nIndex)
    Return $nColor[0]
EndFunc  ;==>GetSysColor


Func GetSysColorBrush($nIndex)
    Local $hBrush = DllCall("user32.dll", "hwnd", "GetSysColorBrush", "int", $nIndex)
    Return $hBrush[0]
EndFunc  ;==>GetSysColorBrush


Func DrawFrameControl($hDC, $nLeft, $nTop, $nRight, $nBottom, $nType, $nState)
    Local $stRect = DllStructCreate("int;int;int;int")

    DllStructSetData($stRect, 1, $nLeft)
    DllStructSetData($stRect, 2, $nTop)
    DllStructSetData($stRect, 3, $nRight)
    DllStructSetData($stRect, 4, $nBottom)

    DllCall("user32.dll", "int", "DrawFrameControl", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "int", $nType, "int", $nState)

    $stRect = 0
EndFunc  ;==>DrawFrameControl


Func DrawFocusRect($hDC, $nLeft, $nTop, $nRight, $nBottom)
    Local $stRect = DllStructCreate("int;int;int;int")

    DllStructSetData($stRect, 1, $nLeft)
    DllStructSetData($stRect, 2, $nTop)
    DllStructSetData($stRect, 3, $nRight)
    DllStructSetData($stRect, 4, $nBottom)

    DllCall("user32.dll", "int", "DrawFocusRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect))

    $stRect = 0
EndFunc  ;==>DrawFocusRect


Func DrawText($hDC, $sText, $nLeft, $nTop, $nRight, $nBottom, $nFormat)
    Local $nLen = StringLen($sText)

    Local $stRect = DllStructCreate("int;int;int;int")
    DllStructSetData($stRect, 1, $nLeft)
    DllStructSetData($stRect, 2, $nTop)
    DllStructSetData($stRect, 3, $nRight)
    DllStructSetData($stRect, 4, $nBottom)

    Local $stText = DllStructCreate("char[260]")
    DllStructSetData($stText, 1, $sText)

    DllCall("user32.dll", "int", "DrawText", "hwnd", $hDC, "ptr", DllStructGetPtr($stText), "int", $nLen, "ptr", DllStructGetPtr($stRect), "int", $nFormat)

    $stRect = 0
    $stText = 0
EndFunc  ;==>DrawText


Func FillRect($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBrush)
    Local $stRect = DllStructCreate("int;int;int;int")

    DllStructSetData($stRect, 1, $nLeft)
    DllStructSetData($stRect, 2, $nTop)
    DllStructSetData($stRect, 3, $nRight)
    DllStructSetData($stRect, 4, $nBottom)

    DllCall("user32.dll", "int", "FillRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)

    $stRect = 0
EndFunc  ;==>FillRect


Func FrameRect($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBrush)
    Local $stRect = DllStructCreate("int;int;int;int")

    DllStructSetData($stRect, 1, $nLeft)
    DllStructSetData($stRect, 2, $nTop)
    DllStructSetData($stRect, 3, $nRight)
    DllStructSetData($stRect, 4, $nBottom)

    DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)

    $stRect = 0
EndFunc  ;==>FrameRect


Func InflateRect(ByRef $nLeft, ByRef $nTop, ByRef $nRight, ByRef $nBottom, $nX, $nY)
    Local $stRect = DllStructCreate("int;int;int;int")

    DllStructSetData($stRect, 1, $nLeft)
    DllStructSetData($stRect, 2, $nTop)
    DllStructSetData($stRect, 3, $nRight)
    DllStructSetData($stRect, 4, $nBottom)

    DllCall("user32.dll", "int", "InflateRect", "ptr", DllStructGetPtr($stRect), "int", $nX, "int", $nY)

    $nLeft = DllStructGetData($stRect, 1)
    $nTop = DllStructGetData($stRect, 2)
    $nRight = DllStructGetData($stRect, 3)
    $nBottom = DllStructGetData($stRect, 4)

    $stRect = 0
EndFunc  ;==>InflateRect


Func SetBkColor($hDC, $nColor)
    Local $nOldColor = DllCall("gdi32.dll", "int", "SetBkColor", "hwnd", $hDC, "int", $nColor)
    Return $nOldColor[0]
EndFunc  ;==>SetBkColor


Func SetTextColor($hDC, $nColor)
    Local $nOldColor = DllCall("gdi32.dll", "int", "SetTextColor", "hwnd", $hDC, "int", $nColor)
    Return $nOldColor[0]
EndFunc  ;==>SetTextColor


Func SelectObject($hDC, $hObj)
    Local $hOldObj = DllCall("gdi32.dll", "hwnd", "SelectObject", "hwnd", $hDC, "hwnd", $hObj)
    Return $hOldObj[0]
EndFunc  ;==>SelectObject


Func DeleteObject($hObj)
    Local $nResult = DllCall("gdi32.dll", "hwnd", "DeleteObject", "hwnd", $hObj)
EndFunc  ;==>DeleteObject


Func GetWindowLong($hWnd, $nIndex)
    Local $nVal = DllCall("user32.dll", "int", "GetWindowLong", "hwnd", $hWnd, "int", $nIndex)
    Return $nVal[0]
EndFunc  ;==>GetWindowLong

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
jennico

good example, martin. this seems to clear it. WM_Paint is called.

but see my current project. if you click an icon, gui icon is changed and afterwards the entire window is redrawn , which i want to avoid.

when you comment out line 141 (GUISetIcon($t[1], $t[2])), then no redraw is done. so what is the reason ?

#sage
Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites
martin

I played with it a bit and I produced something which shows it is possible, but now the Title bar buttons don't work. Maybe you can find some way to get round that problem. Maybe set the $firstdraw and $doBGPPaint variables if the mouse moves away from the client area or something like that.

I expect there is some other message we need to know about. Try investigating owner drawn title bars and you should find something.

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GuiListBox.au3>
#include <GuiImageList.au3>
#include <WinAPI.au3>
#Include <GuiStatusBar.au3>

; copyright 2009 by jennico

Global Const $ODA_DRAWENTIRE = 1
Global Const $ODA_SELECT = 2
Global Const $ODA_FOCUS = 4
Global Const $ODS_SELECTED = 1
Global Const $ODT_LISTBOX = 2
Global $doBGPPaint = true
Global $firstdraw = true
;Global Const $ODT_STATIC = 5
;Global Const $ODT_BUTTON = 4
;Global Const $ODT_COMBOBOX = 3
;Global Const $ODT_MENU = 1

Dim $sound = @WindowsDir & "\Media\start.wav", $ini = @HomeDrive & "\IS.ini", $title = " IconSearch  ©  2008 by jennico ", $res = "Resources", $mode, $S32 = "shell32.dll"

Global Const $C32 = "ComCtl32.dll", $G32 = "GDI32.dll", $U32 = "User32.dll", $INT = "int", $HWN = "hwnd", $STR = "str", $LPA = "lparam", $WPA = "wparam", $PTR = "ptr", $UIN = "uint"
Global Const $tagSTRUCT = "uint cType;uint cID;uint itmID;uint itmAction;uint itmState;hwnd hItm;hwnd hDC;int itmRect[4];dword itmData"

Global $Count = 0, $IconSize = 32, $BorderSize = 4;,$Resource = "shell32.dll"
Global $aParts[3] = [90, 190, -1], $aText[3] = ["AutoIt", "Windows", ""], $Reference[1]
;$no=0

$Child = GUICreate($title, 371, 245, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_THICKFRAME, $WS_MAXIMIZEBOX))
TraySetIcon($S32, -219)

$ListBox = GUICtrlCreateList("", 3, 3, 365, 220, BitOR($LBS_NOINTEGRALHEIGHT, $LBS_OWNERDRAWFIXED, $WS_HSCROLL, $LBS_MULTICOLUMN))
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS);110;$LBS_HASSTRINGS,
GUICtrlSendMsg(-1, $LB_SETITEMHEIGHT, 0, $IconSize + $BorderSize * 2)
GUICtrlSendMsg(-1, $LB_SETCOLUMNWIDTH, $IconSize + $BorderSize * 2, 0)
$hListBox = GUICtrlGetHandle(-1)

$StatusBar = _GUICtrlStatusBar_Create ($Child, $aParts, $aText)
; Remarks .......: The status bar must have been created with the $SBARS_TOOLTIPS style to enable ToolTips

$hListBoxIMGList = DllCall($C32, $HWN, "ImageList_Create", $INT, $IconSize, $INT, $IconSize, $INT, BitOR($ILC_MASK, $ILC_COLORDDB), $INT, 4, $INT, 4)
DllCall($C32, $INT, "ImageList_SetBkColor", $HWN, $hListBoxIMGList[0], $INT, 0xFFFFFF)

;MsgBox(0,"",_GUICtrlStatusBar_GetHeight ($StatusBar));14

$Count = _GUICtrlListBox_AddIconsFromResource($hListBox, $hListBoxIMGList[0], $S32, $Count, $StatusBar)

GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
    GUIRegisterMsg($WM_PAINT, "WM_NCPAINT")
    GUIRegisterMsg($WM_ERASEBKGND,"BGPaint")

GUISetState()

Do
    $msg = GUIGetMsg()
   ;    TreeViewToolTip(GUICtrlGetHandle($TreeView1))
Until $msg = -3

;Sleep(2000)
;_GUIImageList_Destroy ($hListBoxIMGList[0])

#cs
    Func TreeViewToolTip($TreeViewHandle)
    $HotTreeviewItem = TreeItemFromPoint($TreeViewHandle)
    If $HotTreeviewItem <> 0 Then
    $MousePos = GUIGetCursorInfo ()
    ToolTip("TreeView Item ID is " & $HotTreeviewItem, $MousePos[0], $MousePos[1], $MousePos[0] & "," & $MousePos[1], 2)
    ElseIf $HotTreeviewItem = 0 Then
    ToolTip("")
    EndIf
    EndFunc
#ce
Func BGPaint($hWnd, $Msg, $wParam, $lParam)
    
    if $doBGPPaint then return 0
    $doBGPPaint = true
    return 1
    
EndFunc

Func WM_NCPAINT($hWnd, $Msg, $wParam, $lParam)
     if $firstdraw then 
       $firstdraw = False
       return $GUI_RUNDEFMSG
     EndIf
     $firstdraw = False
     return 0
    if $doBGPPaint then return $GUI_RUNDEFMSG
;$doBGPPaint = true
    return 0
    ConsoleWrite("paint called" & @LF)
    Return 0; 0 $GUI_RUNDEFMSG
EndFunc ;==>WM_NCPAINT

Func _GUICtrlListBox_AddIconsFromResource($hLBox, $hImageList, $sIconFile, $sCount, $hStatusBar = 0);anzahl angeben, wenn nicht dll (oder array)
    Local $iIconIDX, $iStrIndex, $tIcon, $hIcon
    Local $hCount = DllCall($S32, $INT, "ExtractIconEx", $STR, $sIconFile, $INT, -1, $HWN, "", $HWN, "", $UIN, "")
    DllCall($C32, $INT, "ImageList_SetImageCount", $HWN, $hImageList, $INT, $sCount + $hCount[0] + 20)
    ReDim $Reference[$Count + $hCount[0] + 1]
    For $i = 0 To $hCount[0] - 1;muss nummer in array,$iconfile merken
        $tIcon = DllStructCreate("int Handle")
        DllCall($S32, $INT, "ExtractIconEx", $STR, $sIconFile, $INT, $i, $PTR, DllStructGetPtr($tIcon), $PTR, 0, $INT, 1)
        $hIcon = DllStructGetData($tIcon, "Handle")
        $iIconIDX = DllCall($C32, $INT, "ImageList_ReplaceIcon", $HWN, $hImageList, $INT, -1, $HWN, $hIcon)
        DllCall($U32, $INT, "DestroyIcon", $HWN, $hIcon)
        $iStrIndex = DllCall($U32, $LPA, "SendMessage", $HWN, $hLBox, $INT, $LB_ADDSTRING, $WPA, 0, $STR, "")
        DllCall($U32, $LPA, "SendMessage", $HWN, $hLBox, $INT, $LB_SETITEMDATA, $WPA, $iStrIndex[0], $LPA, $iIconIDX[0])
        $Reference[$Count + $i] = $sIconFile & "|" & $i
    Next;   evtl raus
    If $hStatusBar Then _GUICtrlStatusBar_SetText ($hStatusBar, '" ' & $sIconFile & '" ' & $hCount[0] & " icon(s)", 2)
    Return $iStrIndex[0];brauch ich ja nicht
EndFunc  ;==>_GUICtrlListBox_AddIconsFromResource

;_GUICtrlListView_SetHoverTime($hWnd, $iTime)
;The hover time only affects list-view controls that have the $LVS_EX_TRACKSELECT,
;$LVS_EX_ONECLICKACTIVATE, or $LVS_EX_TWOCLICKACTIVATE extended list-view style

Func WM_DRAWITEM($hWnd, $msg, $wParam, $lParam)
        If $lParam<>0x0089F41C Then ConsoleWrite($msg & "*" & $lParam& "*" &$wParam&@LF)
   ;   If $lParam=0x0089F3E8 Then Return $GUI_RUNDEFMSG
   ;43*0x0089F474
   ;43*0x0089F478;nein
   ;43*0x0089F45C
   ;43*0x0089F3E8
   ;43*0x0089F3E8
    _GUICtrlStatusBar_SetIcon ($StatusBar, 0, 0, @AutoItExe)
    _GUICtrlStatusBar_SetIcon ($StatusBar, 1, 1, "xpsp2res.dll")
    _GUICtrlStatusBar_SetIcon ($StatusBar, 2, 7, "explorer.exe")
    Local $iBrushColor = 0xFFFFFF;0x66CDAA
    Local $tagDRAWITEMSTRUCT = DllStructCreate($tagSTRUCT, $lParam)
    If DllStructGetData($tagDRAWITEMSTRUCT, "cType") <> $ODT_LISTBOX Then Return $GUI_RUNDEFMSG
    Local $hDC = DllStructGetData($tagDRAWITEMSTRUCT, "hDC")
    Local $itmAction = DllStructGetData($tagDRAWITEMSTRUCT, "itmAction")
    If $itmAction = $ODA_FOCUS Then Return 1
    If $itmAction = $ODA_DRAWENTIRE Or $itmAction = $ODA_SELECT Then
       ;   If $no=1 Then
       ;      $no=0
       ;      Return $GUI_RUNDEFMSG
       ;   EndIf
        If DllStructGetData($tagDRAWITEMSTRUCT, "itmState") = $ODS_SELECTED Then
            $iBrushColor = 0x00FFFF;0x6495ED;0x00FF00;
            If $itmAction = $ODA_SELECT Then
                SoundPlay($sound)
                Local $itmID = DllStructGetData($tagDRAWITEMSTRUCT, "itmID")
               ;      MsgBox(0,$itmID,$Reference[$itmID])
                $t = StringSplit($Reference[$itmID], "|")
                If $mode = 0 Then $t[2] = -$t[2] - 1;($t[2] > 0)
                $t[1] = IniRead($ini, $res, $t[1], "") & $t[1]
                $f = '"' & $t[1] & '", ' & $t[2]
                ClipPut($f)
                TraySetToolTip($title & @CRLF & " Loaded Icon: " & $f & ". ")
                TraySetIcon($t[1], $t[2])
                $no = 1
                $doBGPPaint = false
               ;GUIRegisterMsg($WM_DRAWITEM, "")
                 $v_ret =  DllCall("user32.dll", "int", "InvalidateRect","hwnd",$StatusBar,"ptr", 0,"int",0)
                GUISetIcon($t[1], $t[2])
               ;GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
            EndIf
        EndIf
        Local $hBrush = DllCall($G32, $HWN, "CreateSolidBrush", $INT, $iBrushColor)
        DllCall($U32, $INT, "FillRect", $HWN, $hDC, $PTR, DllStructGetPtr($tagDRAWITEMSTRUCT, "itmRect"), $HWN, $hBrush[0])
        DllCall($G32, $INT, "DeleteObject", $INT, $hBrush[0])
        Local $itmTextIMG = DllCall($U32, $LPA, "SendMessage", $HWN, $hListBox, $INT, $LB_GETITEMDATA, $WPA, DllStructGetData($tagDRAWITEMSTRUCT, "itmID"), $LPA, 0)
        If $itmTextIMG[0] >= 0 Then DllCall($C32, $INT, "ImageList_Draw", $HWN, $hListBoxIMGList[0], $INT, $itmTextIMG[0], $HWN, $hDC, $INT, DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 1) + $BorderSize, $INT, DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 2) + $BorderSize, $UIN, 0)
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_DRAWITEM

Func WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam)
    DllCall($U32, $LPA, "SendMessage", $HWN, $StatusBar, $INT, $__STATUSBARCONSTANT_WM_SIZE, $WPA, 0, $LPA, 0)
    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_SIZE

Func SendMessage($hWnd, $iMsg, $wParam = 0, $lParam = 0, $iReturn = 0, $wParamType = $WPA, $lParamType = $LPA, $sReturnType = $LPA)
    Local $aResult = DllCall($U32, $sReturnType, "SendMessage", $HWN, $hWnd, $INT, $iMsg, $wParamType, $wParam, $lParamType, $lParam)
    If @error Then Return SetError(@error, @extended, "")
    If $iReturn >= 0 And $iReturn <= 4 Then Return $aResult[$iReturn]
    Return $aResult
EndFunc  ;==>SendMessage

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
jennico

thx martin, but this doesn't work here at all, no redraw on moving and sizing anymore. :)

strange problem, since your first attempt with WM_Paint really seemed to fix it.


Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites
martin

thx martin, but this doesn't work here at all, no redraw on moving and sizing anymore. :)

strange problem, since your first attempt with WM_Paint really seemed to fix it.

Yes, I was only looking at selecting the icon without making the status bar flash.

If you can live with the flicker when the window is being resized then the easy solution is to just make the window stytle include $WS_CLIPCHILDREN.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
jennico

If you can live with the flicker when the window is being resized then the easy solution is to just make the window stytle include $WS_CLIPCHILDREN.

hey, how you come now with that ? :) this works almost perfectly !!!!

no flicker here, but the scrollbar is messed up and the listbox border on sizing. but this does not seem hard to fix - somehow.

a great step ahead for me. though i am far from understanding what's happening.

j.

Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites
jennico

no flicker here, but the scrollbar is messed up and the listbox border on sizing. but this does not seem hard to fix - somehow.

not that easy :)

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites
rover

@jennico

regarding the slow repaint of the listbox, statusbar icon flicker and statusbar text repaint problem.

you should remove the status bar icons from WM_DRAWITEM

always have a little as possible going on in registered message handlers and subclassing procedures.

being a scripting language, anything outside the native controls is a performance hit. (learned that from Sensei 'Siao') :o

_GUICtrlStatusBar_SetIcon() destroys the icon handle on return when setting an icon from a file.

a bit of a problem if your gui involves any sort of repainting :)

I forgot all about this problem with _GUICtrlStatusBar_SetIcon().

no one else has raised this question as the code is still the same.

haven't used it since a project I finished in 2007 with v3.2.8.1.

fixed by modifying the UDF to return an icon handle then destroying the icons on exit.

there is a 'bolding' effect of the statusbar text on repaint,

the previous text is not removed.

remove the 'InvalidateRect' call from WM_DRAWITEM

you had that there to deal with the icon problem anyway.

Edit typos 'n' grammar... again... as usual...

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GuiListBox.au3>
#include <GuiImageList.au3>
#include <WinAPI.au3>
#Include <GuiStatusBar.au3>
#Include <GuiListBox.au3>

; copyright 2009 by jennico

Global Const $ODA_DRAWENTIRE = 1
Global Const $ODA_SELECT = 2
Global Const $ODA_FOCUS = 4
Global Const $ODS_SELECTED = 1
Global Const $ODT_LISTBOX = 2
Global $doBGPPaint = true
Global $firstdraw = true
;Global Const $ODT_STATIC = 5
;Global Const $ODT_BUTTON = 4
;Global Const $ODT_COMBOBOX = 3
;Global Const $ODT_MENU = 1

Dim $sound = @WindowsDir & "\Media\start.wav", $ini = @HomeDrive & "\IS.ini", $title = " IconSearch  ©  2008 by jennico ", $res = "Resources", $mode, $S32 = "shell32.dll"

Global Const $C32 = "ComCtl32.dll", $G32 = "GDI32.dll", $U32 = "User32.dll", $INT = "int", $HWN = "hwnd", $STR = "str", $LPA = "lparam", $WPA = "wparam", $PTR = "ptr", $UIN = "uint"
Global Const $tagSTRUCT = "uint cType;uint cID;uint itmID;uint itmAction;uint itmState;hwnd hItm;hwnd hDC;int itmRect[4];dword itmData"

Global $Count = 0, $IconSize = 32, $BorderSize = 4;,$Resource = "shell32.dll"
Global $aParts[3] = [90, 190, -1], $aText[3] = ["AutoIt", "Windows", ""], $Reference[1]
;$no=0

$Child = GUICreate($title, 371, 245, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_THICKFRAME, $WS_MAXIMIZEBOX, $WS_CLIPCHILDREN))
TraySetIcon($S32, -219)

$ListBox = GUICtrlCreateList("", 3, 3, 365, 220, BitOR($LBS_NOINTEGRALHEIGHT, $LBS_OWNERDRAWFIXED, $WS_HSCROLL, $LBS_MULTICOLUMN))
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS);110;$LBS_HASSTRINGS,
GUICtrlSendMsg(-1, $LB_SETITEMHEIGHT, 0, $IconSize + $BorderSize * 2)
GUICtrlSendMsg(-1, $LB_SETCOLUMNWIDTH, $IconSize + $BorderSize * 2, 0)
$hListBox = GUICtrlGetHandle(-1)

$StatusBar = _GUICtrlStatusBar_Create ($Child, $aParts, $aText)
; Remarks .......: The status bar must have been created with the $SBARS_TOOLTIPS style to enable ToolTips

Global $hIcon1 = __GUICtrlStatusBar_SetIcon ($StatusBar, 0, 0, @AutoItExe)
Global $hIcon2 = __GUICtrlStatusBar_SetIcon ($StatusBar, 1, 1, "xpsp2res.dll")
Global $hIcon3 = __GUICtrlStatusBar_SetIcon ($StatusBar, 2, 7, "explorer.exe")


$hListBoxIMGList = DllCall($C32, $HWN, "ImageList_Create", $INT, $IconSize, $INT, $IconSize, $INT, BitOR($ILC_MASK, $ILC_COLORDDB), $INT, 4, $INT, 4)
DllCall($C32, $INT, "ImageList_SetBkColor", $HWN, $hListBoxIMGList[0], $INT, 0xFFFFFF)

;MsgBox(0,"",_GUICtrlStatusBar_GetHeight ($StatusBar));14


    _GUICtrlListBox_BeginUpdate($hListBox)
$Count = _GUICtrlListBox_AddIconsFromResource($hListBox, $hListBoxIMGList[0], $S32, $Count, $StatusBar)
    _GUICtrlListBox_EndUpdate($hListBox)



GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
 ;GUIRegisterMsg($WM_PAINT, "WM_NCPAINT")
 ;GUIRegisterMsg($WM_ERASEBKGND,"BGPaint")

GUISetState()

Do
    $msg = GUIGetMsg()
;   TreeViewToolTip(GUICtrlGetHandle($TreeView1))
Until $msg = -3


DllCall("user32.dll", "int", "DestroyIcon", "hwnd", $hIcon1)
DllCall("user32.dll", "int", "DestroyIcon", "hwnd", $hIcon2)
DllCall("user32.dll", "int", "DestroyIcon", "hwnd", $hIcon3)



;Sleep(2000)
;_GUIImageList_Destroy ($hListBoxIMGList[0])

#cs
    Func TreeViewToolTip($TreeViewHandle)
    $HotTreeviewItem = TreeItemFromPoint($TreeViewHandle)
    If $HotTreeviewItem <> 0 Then
    $MousePos = GUIGetCursorInfo ()
    ToolTip("TreeView Item ID is " & $HotTreeviewItem, $MousePos[0], $MousePos[1], $MousePos[0] & "," & $MousePos[1], 2)
    ElseIf $HotTreeviewItem = 0 Then
    ToolTip("")
    EndIf
    EndFunc
#ce
Func BGPaint($hWnd, $Msg, $wParam, $lParam)
    
    if $doBGPPaint then return 0
    $doBGPPaint = true
    return 1
    
EndFunc

Func WM_NCPAINT($hWnd, $Msg, $wParam, $lParam)
     if $firstdraw then
       $firstdraw = False
       return $GUI_RUNDEFMSG
     EndIf
     $firstdraw = False
     return 0
    if $doBGPPaint then return $GUI_RUNDEFMSG
;$doBGPPaint = true
    return 0
 ;ConsoleWrite("paint called" & @LF)
    Return 0; 0 $GUI_RUNDEFMSG
EndFunc;==>WM_NCPAINT

Func _GUICtrlListBox_AddIconsFromResource($hLBox, $hImageList, $sIconFile, $sCount, $hStatusBar = 0);anzahl angeben, wenn nicht dll (oder array)
    Local $iIconIDX, $iStrIndex, $tIcon, $hIcon
    Local $hCount = DllCall($S32, $INT, "ExtractIconEx", $STR, $sIconFile, $INT, -1, $HWN, "", $HWN, "", $UIN, "")
    DllCall($C32, $INT, "ImageList_SetImageCount", $HWN, $hImageList, $INT, $sCount + $hCount[0] + 20)
    ReDim $Reference[$Count + $hCount[0] + 1]
    For $i = 0 To $hCount[0] - 1;muss nummer in array,$iconfile merken
        $tIcon = DllStructCreate("int Handle")
        DllCall($S32, $INT, "ExtractIconEx", $STR, $sIconFile, $INT, $i, $PTR, DllStructGetPtr($tIcon), $PTR, 0, $INT, 1)
        $hIcon = DllStructGetData($tIcon, "Handle")
        $iIconIDX = DllCall($C32, $INT, "ImageList_ReplaceIcon", $HWN, $hImageList, $INT, -1, $HWN, $hIcon)
        DllCall($U32, $INT, "DestroyIcon", $HWN, $hIcon)
        $iStrIndex = DllCall($U32, $LPA, "SendMessage", $HWN, $hLBox, $INT, $LB_ADDSTRING, $WPA, 0, $STR, "")
        DllCall($U32, $LPA, "SendMessage", $HWN, $hLBox, $INT, $LB_SETITEMDATA, $WPA, $iStrIndex[0], $LPA, $iIconIDX[0])
        $Reference[$Count + $i] = $sIconFile & "|" & $i
    Next;   evtl raus
    If $hStatusBar Then _GUICtrlStatusBar_SetText ($hStatusBar, '" ' & $sIconFile & '" ' & $hCount[0] & " icon(s)", 2)
    Return $iStrIndex[0];brauch ich ja nicht
EndFunc;==>_GUICtrlListBox_AddIconsFromResource

;_GUICtrlListView_SetHoverTime($hWnd, $iTime)
;The hover time only affects list-view controls that have the $LVS_EX_TRACKSELECT,
;$LVS_EX_ONECLICKACTIVATE, or $LVS_EX_TWOCLICKACTIVATE extended list-view style

Func WM_DRAWITEM($hWnd, $msg, $wParam, $lParam)
     ;If $lParam<>0x0089F41C Then ConsoleWrite($msg & "*" & $lParam& "*" &$wParam&@LF)
;   If $lParam=0x0089F3E8 Then Return $GUI_RUNDEFMSG
;43*0x0089F474
;43*0x0089F478;nein
;43*0x0089F45C
;43*0x0089F3E8
;43*0x0089F3E8

    Local $iBrushColor = 0xFFFFFF;0x66CDAA
    Local $tagDRAWITEMSTRUCT = DllStructCreate($tagSTRUCT, $lParam)
    If DllStructGetData($tagDRAWITEMSTRUCT, "cType") <> $ODT_LISTBOX Then Return $GUI_RUNDEFMSG
    Local $hDC = DllStructGetData($tagDRAWITEMSTRUCT, "hDC")
    Local $itmAction = DllStructGetData($tagDRAWITEMSTRUCT, "itmAction")
    If $itmAction = $ODA_FOCUS Then Return 1
    If $itmAction = $ODA_DRAWENTIRE Or $itmAction = $ODA_SELECT Then
    ;   If $no=1 Then
    ;     $no=0
    ;     Return $GUI_RUNDEFMSG
    ;   EndIf
        If DllStructGetData($tagDRAWITEMSTRUCT, "itmState") = $ODS_SELECTED Then
            $iBrushColor = 0x00FFFF;0x6495ED;0x00FF00;
            If $itmAction = $ODA_SELECT Then
                SoundPlay($sound)
                Local $itmID = DllStructGetData($tagDRAWITEMSTRUCT, "itmID")
            ;     MsgBox(0,$itmID,$Reference[$itmID])
                $t = StringSplit($Reference[$itmID], "|")
                If $mode = 0 Then $t[2] = -$t[2] - 1;($t[2] > 0)
                $t[1] = IniRead($ini, $res, $t[1], "") & $t[1]
                $f = '"' & $t[1] & '", ' & $t[2]
                ClipPut($f)
                TraySetToolTip($title & @CRLF & " Loaded Icon: " & $f & ". ")
                TraySetIcon($t[1], $t[2])
                $no = 1
                $doBGPPaint = false
            ;GUIRegisterMsg($WM_DRAWITEM, "")
               
            ;** remove this line: statusbar text not being repainted
        ;$v_ret =  DllCall("user32.dll", "int", "InvalidateRect","hwnd",$StatusBar,"ptr", 0,"int",0)
                 
                GUISetIcon($t[1], $t[2])
            ;GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
            EndIf
        EndIf
        Local $hBrush = DllCall($G32, $HWN, "CreateSolidBrush", $INT, $iBrushColor)
        DllCall($U32, $INT, "FillRect", $HWN, $hDC, $PTR, DllStructGetPtr($tagDRAWITEMSTRUCT, "itmRect"), $HWN, $hBrush[0])
        DllCall($G32, $INT, "DeleteObject", $INT, $hBrush[0])
        Local $itmTextIMG = DllCall($U32, $LPA, "SendMessage", $HWN, $hListBox, $INT, $LB_GETITEMDATA, $WPA, DllStructGetData($tagDRAWITEMSTRUCT, "itmID"), $LPA, 0)
        If $itmTextIMG[0] >= 0 Then DllCall($C32, $INT, "ImageList_Draw", $HWN, $hListBoxIMGList[0], $INT, $itmTextIMG[0], $HWN, $hDC, $INT, DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 1) + $BorderSize, $INT, DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 2) + $BorderSize, $UIN, 0)
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc;==>WM_DRAWITEM

Func WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam)
    DllCall($U32, $LPA, "SendMessage", $HWN, $StatusBar, $INT, $__STATUSBARCONSTANT_WM_SIZE, $WPA, 0, $LPA, 0)
    Return $GUI_RUNDEFMSG
EndFunc;==>WM_SIZE

Func SendMessage($hWnd, $iMsg, $wParam = 0, $lParam = 0, $iReturn = 0, $wParamType = $WPA, $lParamType = $LPA, $sReturnType = $LPA)
    Local $aResult = DllCall($U32, $sReturnType, "SendMessage", $HWN, $hWnd, $INT, $iMsg, $wParamType, $wParam, $lParamType, $lParam)
    If @error Then Return SetError(@error, @extended, "")
    If $iReturn >= 0 And $iReturn <= 4 Then Return $aResult[$iReturn]
    Return $aResult
EndFunc;==>SendMessage


Func __GUICtrlStatusBar_SetIcon($hWnd, $iPart, $hIcon = -1, $sIconFile = "")
    If $Debug_SB Then _GUICtrlStatusBar_ValidateClassName($hWnd)
    Local $tIcon, $result
    If $hIcon = -1 Then; Remove Icon
        Return _SendMessage($hWnd, $SB_SETICON, $iPart, $hIcon, 0, "wparam", "hwnd") <> 0
    ElseIf StringLen($sIconFile) > 0 Then; set icon from file
        $tIcon = DllStructCreate("int")
        $result = DllCall("shell32.dll", "int", "ExtractIconEx", "str", $sIconFile, "int", $hIcon, "hwnd", 0, "ptr", DllStructGetPtr($tIcon), "int", 1)
        $result = $result[0]
        If $result > 0 Then $result = _SendMessage($hWnd, $SB_SETICON, $iPart, DllStructGetData($tIcon, 1), 0, "wparam", "ptr")
;DllCall("user32.dll", "int", "DestroyIcon", "hwnd", DllStructGetData($tIcon, 1))
        Return DllStructGetData($tIcon, 1)
    Else; set icon from icon handle
        Return _SendMessage($hWnd, $SB_SETICON, $iPart, $hIcon) <> 0
    EndIf
EndFunc;==>_GUICtrlStatusBar_SetIcon
Edited by rover

I see fascists...

Share this post


Link to post
Share on other sites
jennico

@rover: thank you for helping me out with the statbaricons. they always disappeared on repaint and i did not see why. :):o now they do not flicker anymore. i knew it was wrong to put them in there.

as you can see, i myself don't "trust" the UDFs and i always use the native calls instead. btw one can learn more in doing so. but i left _GUICtrlStatusBar_SetIcon without looking into the function.

i still have the pending problem:

- when i use $WS_CLIPCHILDREN, no repaint is done on updating titlebar icon, but in exchange the scrollbar is not updated either.

- when i do not use $WS_CLIPCHILDREN, the scrollbar is correctly updated, but then i get that annoying "pulse" (especially in a maximized window) on changing gui title bar icon.

i cannot get both problems solved at the same time, it seems. i could use a workaround by making pixelchecksum on the right scrollbar button but i don't like this.

another workaround i thought of (not sure if it really helps), would be to make two guis, one with the titlebar, and the child popup with listbox and statusbar. in this way i think i could avoid repainting of the entire client area. but i don't like that either.

i tried anything else i could think of (see the comments), but nothing works.

and there is a next problem arising: i tried to add a second icon resource to the listbox. but it seems i get problems with the imagelist dimension. the line i use to resize imagelist:

DllCall($C32, $INT, "ImageList_SetImageCount", $HWN, $hImageList, $INT, $sCount + $hCount[0] + 20)

i found by experiments on the count parameter and it works on the first resource, but not on the second. the list gets messed up. what is wrong with it ?

of course, i would like to add as many icons as possible to the list, but i could not find any info on msdn about the limit.

maybe i should work with several imagelists ? this would involve a hell too much coding (and probanly is wrong anyway).

see what i got so far (sorry for the mess of comments) (the inifile in the script is produced by IconSearch in my sign, but you don't need it):

#

really thx for helping me !!

j.

Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites
rover

@rover: thank you for helping me out with the statbaricons. they always disappeared on repaint and i did not see why. :) :) now they do not flicker anymore. i knew it was wrong to put them in there.

as you can see, i myself don't "trust" the UDFs and i always use the native calls instead. btw one can learn more in doing so. but i left _GUICtrlStatusBar_SetIcon without looking into the function.

i still have the pending problem:

- when i use $WS_CLIPCHILDREN, no repaint is done on updating titlebar icon, but in exchange the scrollbar is not updated either.

- when i do not use $WS_CLIPCHILDREN, the scrollbar is correctly updated, but then i get that annoying "pulse" (especially in a maximized window) on changing gui title bar icon.

i cannot get both problems solved at the same time, it seems. i could use a workaround by making pixelchecksum on the right scrollbar button but i don't like this.

another workaround i thought of (not sure if it really helps), would be to make two guis, one with the titlebar, and the child popup with listbox and statusbar. in this way i think i could avoid repainting of the entire client area. but i don't like that either.

i tried anything else i could think of (see the comments), but nothing works.

and there is a next problem arising: i tried to add a second icon resource to the listbox. but it seems i get problems with the imagelist dimension. the line i use to resize imagelist:

DllCall($C32, $INT, "ImageList_SetImageCount", $HWN, $hImageList, $INT, $sCount + $hCount[0] + 20)

i found by experiments on the count parameter and it works on the first resource, but not on the second. the list gets messed up. what is wrong with it ?

of course, i would like to add as many icons as possible to the list, but i could not find any info on msdn about the limit.

maybe i should work with several imagelists ? this would involve a hell too much coding (and probanly is wrong anyway).

see what i got so far (sorry for the mess of comments) (the inifile in the script is produced by IconSearch in my sign, but you don't need it):

really thx for helping me !!

j.

there is a repaint happening with GuiSetIcon() that is problematic when called repeatedly in your application.

part of the internal housekeeping required to make the native controls work together without the need for users to add message handling

for repainting controls.

make the extract icon and WM_SETICON message calls in GuiSetIcon() yourself so extra repainting is not done

and you no longer have flickering when changing the titlebar icon.

getting the icons from the imagelist instead of re-reading the dll would be better, maybe with _GUIImageList_GetIcon().

regarding the problem with adding icons to an existing imagelist:

I noticed that the function referred to in the helpfile remarks

for _GUIImageList_SetImageCount() was _GUIImageList_Replace(), not _GUIImageList_ReplaceIcon()

but there's no _GUIImageList_Replace function listed in the help file.

_GUIImageList_Replace() is an undocumented function in GuiImageList.au3

however it requires a bitmap handle, not an icon handle and a bitmap mask as well.

_GUIImageList_SetImageCount() was the cause of the problem with the imagelist updating incorrectly.

I don't think you need to increase the imagelist size with _GUIImageList_SetImageCount()

I tested the imagelist with 32000 icons with just the 'Grow' parameter of ImageList_Create set to 32000

and _GUIImageList_ReplaceIcon() with the -1 index setting to append icons to the imagelist.

try this example

_GUICtrlListBox_AddIconsFromResource1() is faster

try the load test of 32000 icons (144 meg memory usage)

with the device dependent bitmap flag $ILC_COLORDDB, the listbox had invisible icons after about 5000 icons

with 32bit DIB flag $ILC_COLOR32 all 32000 icons were visible.

Cheers

[autoit]#include <GuiConstantsEx.au3>

#include <WindowsConstants.au3>

#include <Constants.au3>

#include <GuiListBox.au3>

#include <GuiImageList.au3>

#include <WinAPI.au3>

#Include <GuiStatusBar.au3>

; copyright 2009 by jennico

;IconServeU IconhelpU

;extract to .ico

;add all ini files !

;dropaccept / parent

;destroy mit "|" wie bei combo ; _GUICtrlListBox_ResetContent

;jedesmal neue imagelist !

Opt("TrayOnEventMode", 1)

Opt("PixelCoordMode", 2)

;Opt("GUIOnEventMode", 1)

Opt("TrayAutoPause", 0)

Opt("TrayMenuMode", 3)

Global Const $ODA_DRAWENTIRE = 1

Global Const $ODA_SELECT = 2

Global Const $ODA_FOCUS = 4

Global Const $ODS_SELECTED = 1

Global Const $ODT_LISTBOX = 2

;Global Const $ODT_STATIC = 5

;Global Const $ODT_BUTTON = 4

;Global Const $ODT_COMBOBOX = 3

;Global Const $ODT_MENU = 1

Dim $sound = @WindowsDir & "\Media\start.wav", $ini = @HomeDrive & "\IS.ini", $title = " IconSearch


I see fascists...

Share this post


Link to post
Share on other sites
jennico

thank you this is relly great !

part of the internal housekeeping required to make the native controls work together without the need for users to add message handling

for repainting controls.

make the extract icon and WM_SETICON message calls in GuiSetIcon() yourself so extra repainting is not done

and you no longer have flickering when changing the titlebar icon.

yes, now i see it clearly. so i have to be careful with mixing native and autoit controls.

_GUIImageList_SetImageCount() was the cause of the problem with the imagelist updating incorrectly.

I don't think you need to increase the imagelist size with _GUIImageList_SetImageCount()

I tested the imagelist with 32000 icons with just the 'Grow' parameter of ImageList_Create set to 32000

and _GUIImageList_ReplaceIcon() with the -1 index setting to append icons to the imagelist.

i suspected that, but i could not find any documentation about how to handle the params correctly (initial and grow). same with $iColor parameter.

thanks for your excellent tutorial !

j.


Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

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  

×