Jump to content

$WS_CLIPCHILDREN on ListView erases background


Recommended Posts

Hi,

when i useĀ $WS_CLIPCHILDREN with my listview control, parts of the listview control becomes erased, but i need this style for my child controls which i have excluded from this snippet. Does someone know a workaround for this problem?

#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ColorConstants.au3>


Global Const $ODT_LISTVIEW = 102
Global Const $ODA_DRAWENTIRE = 0x1
Global Const $ODA_SELECT = 0x2
Global Const $ODA_FOCUS = 0x4
Global Const $ODS_SELECTED = 0x0001

Global $default_font = "Arial"
Global $default_font_size = 9
Global $GUI_main = GUICreate("", 300, 300, -1, -1, -1, $WS_EX_ACCEPTFILES)
Global $hGUI_tab_listview[2][10]
;~ GUIRegisterMsg($WM_MEASUREITEM, "WM_MEASUREITEM") ;place before listview creation - message sent once for each ownerdrawn control created
$hGUI_tab_listview[0][0] = GUICtrlCreateListView("", 15, 10, 250, 280, _
  BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS, $LVS_OWNERDRAWFIXED, $WS_CLIPCHILDREN, $WS_BORDER), _
  BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER)) ; + $LVS_EX_CHECKBOXES + $LVS_SINGLESEL
GUICtrlSetFont(-1, $default_font_size, 400, 0, $default_font, 5)
GUICtrlSetBkColor(-1, $COLOR_RED)
GUICtrlSetColor(-1, $COLOR_RED)

_GUICtrlListView_AddColumn(-1, "Name")
_GUICtrlListView_SetColumnWidth(-1, 0, 155)
_GUICtrlListView_AddColumn(-1, "Count")
_GUICtrlListView_SetColumnWidth(-1, 1, 72)
For $i = 0 To 50 ; populate the listview for testing purposes
_GUICtrlListView_AddItem(-1, "test " & $i)
If $i = 5 Then ContinueLoop
_GUICtrlListView_AddSubItem(-1, $i, $i, 1)
Next

GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
GUISetState(@SW_SHOW)
; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $idOK
            ExitLoop

    EndSwitch
WEnd

Func WM_MEASUREITEM($hWnd, $Msg, $wParam, $lParam)
Local $tMEASUREITEMS = DllStructCreate("uint cType;uint cID;uint itmID;uint itmW;uint itmH;ulong_ptr itmData", $lParam)
If DllStructGetData($tMEASUREITEMS, "cType") <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG
DllStructSetData($tMEASUREITEMS, "itmH", 25);row height
;GUIRegisterMsg($WM_MEASUREITEM, "") ;call this after last ownerdrawn listview created
Return 1
EndFunc   ;==>WM_MEASUREITEM

Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
Local $tagDRAWITEMSTRUCT, $iBrushColor, $cID, $itmID, $itmAction, $itmState, $hItm, $hDC, $bSelected
$tagDRAWITEMSTRUCT = DllStructCreate( _
   "uint cType;" & _
   "uint cID;" & _
   "uint itmID;" & _
   "uint itmAction;" & _
   "uint itmState;" & _
   "hwnd hItm;" & _
   "handle hDC;" & _
   "long itmRect[4];" & _
   "ulong_ptr itmData" _
   , $lParam)
If DllStructGetData($tagDRAWITEMSTRUCT, "cType") <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG
$cID = DllStructGetData($tagDRAWITEMSTRUCT, "cID")
$itmID = DllStructGetData($tagDRAWITEMSTRUCT, "itmID")
$itmAction = DllStructGetData($tagDRAWITEMSTRUCT, "itmAction")
$itmState = DllStructGetData($tagDRAWITEMSTRUCT, "itmState")
$hItm = DllStructGetData($tagDRAWITEMSTRUCT, "hItm")
$hDC = DllStructGetData($tagDRAWITEMSTRUCT, "hDC")
$bSelected = BitAND($itmState, $ODS_SELECTED)
Switch $cID ; will look for ControlID, not window handle.
  Case $hGUI_tab_listview[0][0]
   Switch $itmAction
    Case $ODA_DRAWENTIRE
     ; don't forget, this is BGR, not RGB
     If $itmState = $bSelected Then ; item is not selected
      $iBrushColor = 0xEEDDBB
     Else ; item is selected
      $iBrushColor = $COLOR_RED
;~    GUICtrlSetColor($hGUI_tab_listview[0][0], $COLOR_WHITE)
     EndIf
     Local $aBrush = _WinAPI_CreateSolidBrush($iBrushColor)
     Local $aBrushOld = _WinAPI_SelectObject($hDC, $aBrush)
     Local $iLeft = DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 1)
     DllStructSetData($tagDRAWITEMSTRUCT, "itmRect", $iLeft + 1, 1) ; rectangle coordinates for coloring
     ; +1 is the left margin
     _WinAPI_FillRect($hDC, DllStructGetPtr($tagDRAWITEMSTRUCT, "itmRect"), $aBrush)
     _WinAPI_SelectObject($hDC, $aBrushOld)
     _WinAPI_DeleteObject($aBrush)

;~     LOcal $hPen = _WinAPI_CreatePen($PS_SOLID, 20, $COLOR_RED)
;~     LOcal $o_Orig = _WinAPI_SelectObject($hDC, $hPen)


     ; for all columns of the row:
     $local_alignment = $DT_LEFT
     For $i = 0 To _GUICtrlListView_GetColumnCount($hGUI_tab_listview[0][0]) - 1
      ; 1. get subitem text:
      Local $iSubItmText = _GUICtrlListView_GetItemText($hGUI_tab_listview[0][0], $itmID, $i)
      If $iSubItmText = "" Then Return $GUI_RUNDEFMSG ;ConsoleWrite("hier")
      ; 2. get subitem coordinates for drawing its respective text
      Local $aSubItmRect = _GUICtrlListView_GetSubItemRect($hGUI_tab_listview[0][0], $itmID, $i)
      ; the function above accepts not only subitems (one-based index), but also main item (index=0)
      ; 3. pass the coordinates to a DLL struct
      Local $iSubItmRect = DllStructCreate("long[4]")
      DllStructSetData($iSubItmRect, 1, $aSubItmRect[0] + 6, 1) ; +6 is left margin (X)
      DllStructSetData($iSubItmRect, 1, $aSubItmRect[1] + (-2), 2) ; + (-2) is upper margin (Y)
      DllStructSetData($iSubItmRect, 1, $aSubItmRect[2], 3)
      DllStructSetData($iSubItmRect, 1, $aSubItmRect[3], 4)
      _WinAPI_SetTextColor($hDC, $COLOR_RED)

      DllCall("user32.dll", "int", "DrawTextW", "hwnd", $hDC, "wstr", $iSubItmText, "int", StringLen($iSubItmText), _
        "ptr", DllStructGetPtr($iSubItmRect), "int", $local_alignment)
     Next
     ;#ce
   EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DRAWITEM
Edited by Trolleule
Link to comment
Share on other sites

Give this a try..

#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ColorConstants.au3>


Global Const $ODT_LISTVIEW = 102
Global Const $ODA_DRAWENTIRE = 0x1
Global Const $ODA_SELECT = 0x2
Global Const $ODA_FOCUS = 0x4
Global Const $ODS_SELECTED = 0x0001

Global $default_font = "Arial"
Global $default_font_size = 9
Global $GUI_main = GUICreate("", 300, 300, -1, -1, -1, $WS_EX_ACCEPTFILES)
Global $hGUI_tab_listview[2][10]
;~ GUIRegisterMsg($WM_MEASUREITEM, "WM_MEASUREITEM") ;place before listview creation - message sent once for each ownerdrawn control created
$hGUI_tab_listview[0][0] = GUICtrlCreateListView("", 15, 10, 250, 280, _
  BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS, $LVS_OWNERDRAWFIXED, $WS_BORDER), _
  BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER)) ; + $LVS_EX_CHECKBOXES + $LVS_SINGLESEL
_GUICtrlListView_SetExtendedListViewStyle($hGUI_tab_listview[0][0], $WS_CLIPCHILDREN) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< set the ex style after creating the listview
GUICtrlSetFont(-1, $default_font_size, 400, 0, $default_font, 5)
GUICtrlSetBkColor(-1, $COLOR_RED)
GUICtrlSetColor(-1, $COLOR_RED)

_GUICtrlListView_AddColumn(-1, "Name")
_GUICtrlListView_SetColumnWidth(-1, 0, 155)
_GUICtrlListView_AddColumn(-1, "Count")
_GUICtrlListView_SetColumnWidth(-1, 1, 72)
For $i = 0 To 50 ; populate the listview for testing purposes
_GUICtrlListView_AddItem(-1, "test " & $i)
If $i = 5 Then ContinueLoop
_GUICtrlListView_AddSubItem(-1, $i, $i, 1)
Next

GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
GUISetState(@SW_SHOW)
; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $idOK
            ExitLoop

    EndSwitch
WEnd

Func WM_MEASUREITEM($hWnd, $Msg, $wParam, $lParam)
Local $tMEASUREITEMS = DllStructCreate("uint cType;uint cID;uint itmID;uint itmW;uint itmH;ulong_ptr itmData", $lParam)
If DllStructGetData($tMEASUREITEMS, "cType") <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG
DllStructSetData($tMEASUREITEMS, "itmH", 25);row height
;GUIRegisterMsg($WM_MEASUREITEM, "") ;call this after last ownerdrawn listview created
Return 1
EndFunc   ;==>WM_MEASUREITEM


Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
Local $tagDRAWITEMSTRUCT, $iBrushColor, $cID, $itmID, $itmAction, $itmState, $hItm, $hDC, $bSelected
$tagDRAWITEMSTRUCT = DllStructCreate( _
   "uint cType;" & _
   "uint cID;" & _
   "uint itmID;" & _
   "uint itmAction;" & _
   "uint itmState;" & _
   "hwnd hItm;" & _
   "handle hDC;" & _
   "long itmRect[4];" & _
   "ulong_ptr itmData" _
   , $lParam)
If DllStructGetData($tagDRAWITEMSTRUCT, "cType") <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG
$cID = DllStructGetData($tagDRAWITEMSTRUCT, "cID")
$itmID = DllStructGetData($tagDRAWITEMSTRUCT, "itmID")
$itmAction = DllStructGetData($tagDRAWITEMSTRUCT, "itmAction")
$itmState = DllStructGetData($tagDRAWITEMSTRUCT, "itmState")
$hItm = DllStructGetData($tagDRAWITEMSTRUCT, "hItm")
$hDC = DllStructGetData($tagDRAWITEMSTRUCT, "hDC")
$bSelected = BitAND($itmState, $ODS_SELECTED)
Switch $cID ; will look for ControlID, not window handle.
  Case $hGUI_tab_listview[0][0]
   Switch $itmAction
    Case $ODA_DRAWENTIRE
     ; don't forget, this is BGR, not RGB
     If $itmState = $bSelected Then ; item is not selected
      $iBrushColor = 0xEEDDBB
     Else ; item is selected
      $iBrushColor = $COLOR_RED
;~    GUICtrlSetColor($hGUI_tab_listview[0][0], $COLOR_WHITE)
     EndIf
     Local $aBrush = _WinAPI_CreateSolidBrush($iBrushColor)
     Local $aBrushOld = _WinAPI_SelectObject($hDC, $aBrush)
     Local $iLeft = DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 1)
     DllStructSetData($tagDRAWITEMSTRUCT, "itmRect", $iLeft + 1, 1) ; rectangle coordinates for coloring
     ; +1 is the left margin
     _WinAPI_FillRect($hDC, DllStructGetPtr($tagDRAWITEMSTRUCT, "itmRect"), $aBrush)
     _WinAPI_SelectObject($hDC, $aBrushOld)
     _WinAPI_DeleteObject($aBrush)

;~     LOcal $hPen = _WinAPI_CreatePen($PS_SOLID, 20, $COLOR_RED)
;~     LOcal $o_Orig = _WinAPI_SelectObject($hDC, $hPen)


     ; for all columns of the row:
     $local_alignment = $DT_LEFT
     For $i = 0 To _GUICtrlListView_GetColumnCount($hGUI_tab_listview[0][0]) - 1
      ; 1. get subitem text:
      Local $iSubItmText = _GUICtrlListView_GetItemText($hGUI_tab_listview[0][0], $itmID, $i)
      If $iSubItmText = "" Then Return $GUI_RUNDEFMSG ;ConsoleWrite("hier")
      ; 2. get subitem coordinates for drawing its respective text
      Local $aSubItmRect = _GUICtrlListView_GetSubItemRect($hGUI_tab_listview[0][0], $itmID, $i)
      ; the function above accepts not only subitems (one-based index), but also main item (index=0)
      ; 3. pass the coordinates to a DLL struct
      Local $iSubItmRect = DllStructCreate("long[4]")
      DllStructSetData($iSubItmRect, 1, $aSubItmRect[0] + 6, 1) ; +6 is left margin (X)
      DllStructSetData($iSubItmRect, 1, $aSubItmRect[1] + (-2), 2) ; + (-2) is upper margin (Y)
      DllStructSetData($iSubItmRect, 1, $aSubItmRect[2], 3)
      DllStructSetData($iSubItmRect, 1, $aSubItmRect[3], 4)
      _WinAPI_SetTextColor($hDC, $COLOR_RED)

      DllCall("user32.dll", "int", "DrawTextW", "hwnd", $hDC, "wstr", $iSubItmText, "int", StringLen($iSubItmText), _
        "ptr", DllStructGetPtr($iSubItmRect), "int", $local_alignment)
     Next
     ;#ce
   EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DRAWITEM

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use. Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Forum FAQ

Ā 

Link to comment
Share on other sites

I can't help you with your main script if it isn't like your reproducer script.

Can you post your main script, so that I can take a look at the differences? :)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use. Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Forum FAQ

Ā 

Link to comment
Share on other sites

  • Moderators

Trolleule,

Ā 

I have edit controls as child controls of the listview and when I track the column they will move but are not properly draw

Rather than having edit controls permanently within the ListView, why not use my GUIListView UDF (the link is in my sig) to get these to pop up when you doubleclick a cell? That way you might get round this problem. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.pngĀ AnyĀ of myĀ own codeĀ posted anywhere on the forumĀ isĀ available for use by others without any restrictionĀ of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSortĀ ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- AĀ highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort,Ā edit and colourĀ ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Ā 

Link to comment
Share on other sites

Trolleule,

Ā 

Rather than having edit controls permanently within the ListView, why not use my GUIListView UDF (the link is in my sig) to get these to pop up when you doubleclick a cell? That way you might get round this problem. ;)

M23

Ā 

Melba is quite right. I use this UDF whenever I use ListViews as it is just that good. :)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use. Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Forum FAQ

Ā 

Link to comment
Share on other sites

  • Moderators

MikahS,

Gosh - thanks for that endorsement. :blush:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.pngĀ AnyĀ of myĀ own codeĀ posted anywhere on the forumĀ isĀ available for use by others without any restrictionĀ of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSortĀ ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- AĀ highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort,Ā edit and colourĀ ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Ā 

Link to comment
Share on other sites

@Melba23: What's wrong with you?

You pointed out the same problem in >another topic

This time, $LVS_EX_DOUBLEBUFFER has the same value with $WS_EX_CONTROLPARENT.Ā Problem solved.

Trolleule,

Don't throw a random flag to a control if you don't know what it's exactly for.

Do you addĀ child controlĀ to the listview?Ā If not, remove the $WS_CLIPCHILDREN flag. Add it to the main GUI.

If you have overlapped controls, then add $WS_CLIPSIBLINGS to those.

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Link to comment
Share on other sites

puhhh...

MikahS: Sorry, I can't share the whole script, it's too big, but i try to get the matching parts.

Ā 

Melba23: I don't want to use the edit mode, i try to get it work in permanent mode.

Ā 

Thats the way how i create the child controls

#include-once

#include <GuiEdit.au3> ; _GUICtrlEdit_Create
#include <GuiButton.au3> ; _GUICtrlButton_Create
#include <GuiComboBox.au3> ; _GUICtrlComboBox_Create
#include <ExListViewConstants.au3>


Func _InsertListViewEx($hWnd, $sText, $iItemIndex, $iSubItemIndex = 0, $sType = Default, $iStyle = -1, $iExStyle = -1)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

;~     Local $iLVStyle = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
;~  If BitAND($iLVStyle, $WS_CLIPCHILDREN) <> $WS_CLIPCHILDREN Then
;~      _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, BitOR($iLVStyle, $WS_CLIPCHILDREN))
;~  EndIf


    Local $oLV_EXT = ObjCreate("Scripting.Dictionary")
    Local $aRect = __GUICtrlListView_GetSubItemRect($hWnd, $iItemIndex, $iSubItemIndex, 1)
    __GUICtrlListView_AddSubItem($hWnd, $iItemIndex, $sText, $iSubItemIndex) ; add item to support sort function

    Local $hWndNew = _CreateListViewEx($hWnd, $sText, $sType, $aRect[0], $aRect[1], $aRect[2]-$aRect[0], $aRect[3]-$aRect[1], $iStyle, $iExStyle)

    $oLV_EXT.add("hWnd", $hWndNew)
    $oLV_EXT.add("iItemIndex", $iItemIndex)
    $oLV_EXT.add("iSubItemIndex", $iSubItemIndex)
    $oLV_EXT.add("sType", $sType)
    Return $oLV_EXT
EndFunc     ;==>_InsertListViewEx


Func _CreateListViewEx($hWnd, $sText, $sType, $iX, $iY, $iWidth, $iHeight, $iStyle, $iExStyle)
    Local $hWndNew, $iForcedStyle = BitOR($WS_CHILD, $WS_TABSTOP, $WS_VISIBLE, $WS_CLIPSIBLINGS)

    Switch $sType
        Case Default, "Edit"
            If $iStyle = -1 Then $iStyle = 0x003010C4
            If $iExStyle = -1 Then $iExStyle = 0x00000200

            If BitAND($iStyle, $ES_READONLY) = $ES_READONLY Then
                $iStyle = BitOR($WS_CHILD, $WS_VISIBLE, $iStyle)
            Else
                $iStyle = BitOR($iForcedStyle, $iStyle)
            EndIf
        Case "Button"
            $iForcedStyle = BitOR($iForcedStyle, $BS_NOTIFY)

            If $iStyle = -1 Then
                $iStyle = $iForcedStyle
            Else
                $iStyle = BitOR($iStyle, $iForcedStyle)
            EndIf
            If $iExStyle = -1 Then $iExStyle = 0
        Case "ComboBox"
            If $iStyle = -1 Then $iStyle = BitOR($WS_VSCROLL, $CBS_AUTOHSCROLL, $CBS_DROPDOWN)
            If $iExStyle = -1 Then $iExStyle = 0x00000000

            $iStyle = BitOR($iStyle, $iForcedStyle)
    EndSwitch
    Return _WinAPI_CreateWindowEx($iExStyle, $sType, $sText, $iStyle, $iX, $iY, $iWidth, $iHeight, $hWnd)
EndFunc     ;==>_CreateListViewEx


Func _MoveControl($idListView, $hWnd, $iItemIndex, $iSubItemIndex)
    If Not IsHWnd($hWnd) Then $hWnd = HWnd($hWnd) ; storing handles in dictionaries or lists fails, so this converts the expression into handles

    Local $aRect = __GUICtrlListView_GetSubItemRect($idListView, $iItemIndex, $iSubItemIndex, 1)

    If $aRect[1] < 10 Then
        _WinAPI_ShowWindow($hWnd, $SW_HIDE)
    ElseIf $aRect[1] >= 10 Then
        _WinAPI_ShowWindow($hWnd, $SW_SHOW)
    EndIf

    WinMove($hWnd, "", $aRect[0]+2, $aRect[1]+1, $aRect[2]-$aRect[0]-2, $aRect[3]-$aRect[1]-1)
EndFunc     ;==>_MoveControl


Func __GUICtrlListView_GetSubItemRect($hWnd, $iItemIndex, $iSubItemIndex, $iPart = 0, $aMargins = 0)
    Local $aPart[3] = [$LVIR_BOUNDS, $LVIR_LABEL, $LVIR_ICON]

    Local $tRect = DllStructCreate($tagRECT)
    DllStructSetData($tRect, "Top", $iSubItemIndex)
    DllStructSetData($tRect, "Left", $aPart[$iPart])
    If IsHWnd($hWnd) Then
        _SendMessage($hWnd, $LVM_GETSUBITEMRECT, $iItemIndex, $tRect, 0, "wparam", "struct*")
    Else
        GUICtrlSendMsg($hWnd, $LVM_GETSUBITEMRECT, $iItemIndex, DllStructGetPtr($tRect))
    EndIf
    Local $aRect[4]
    $aRect[0] = DllStructGetData($tRect, "Left")
    $aRect[1] = DllStructGetData($tRect, "Top")
    $aRect[2] = DllStructGetData($tRect, "Right")
    $aRect[3] = DllStructGetData($tRect, "Bottom")
    If IsArray($aMargins) Then
        DllStructSetData($tRect, 1, $aRect[0]+$aMargins[0], 1) ; left margin
        DllStructSetData($tRect, 1, $aRect[1]+$aMargins[1], 2) ; upper margin
        DllStructSetData($tRect, 1, $aRect[2]+$aMargins[2], 3) ; right margin
        DllStructSetData($tRect, 1, $aRect[3]+$aMargins[3], 4) ; bottom margin
        Return $tRect
    EndIf
    Return $aRect
EndFunc     ;==>__GUICtrlListView_GetSubItemRect


Func __GUICtrlListView_AddSubItem($hWnd, $iItemIndex, $sText, $iSubItemIndex, $iImage = -1)
    Local $iBuffer = StringLen($sText) + 1

    Local $tBuffer = DllStructCreate("wchar Text[" & $iBuffer & "]")
    Local $pBuffer = DllStructGetPtr($tBuffer)
    Local $tItem = DllStructCreate($tagLVITEM)
    Local $iMask = $LVIF_TEXT
    If $iImage <> -1 Then $iMask = BitOR($iMask, $LVIF_IMAGE)
    DllStructSetData($tBuffer, "Text", $sText)
    DllStructSetData($tItem, "Text", $pBuffer)
    DllStructSetData($tItem, "Mask", $iMask)
    DllStructSetData($tItem, "Item", $iItemIndex)
    DllStructSetData($tItem, "SubItem", $iSubItemIndex)
    DllStructSetData($tItem, "Image", $iImage)
    Local $iRet
    If IsHWnd($hWnd) Then
        $iRet = _SendMessage($hWnd, $LVM_SETITEMW, 0, $tItem, 0, "wparam", "struct*")
    Else
        $iRet = GUICtrlSendMsg($hWnd, $LVM_SETITEMW, 0, DllStructGetPtr($tItem))
    EndIf
    Return $iRet <> 0
EndFunc

The ListView styles areĀ BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $WS_BORDER, $LVS_OWNERDRAWFIXED,Ā $WS_CLIPCHILDREN) and the Ex styles areĀ BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER)

The part where the child controls get prepared for creation

#Region - Add Items
                GUICtrlCreateListViewItem("|" & StringReplace($sStrings[2][1], '"', '') & "|" & $sFoundIn & "|" & $sVersion & "|" & $sArchitecture, $idListView) ; Problem bei $sVersion!!!!!!!!!!!!!!!!!
                $LvActiveBoxList.add(_InsertListViewEx($idListView, "", $iCount, 0, "Button", $BS_AUTOCHECKBOX)) ; column 1: checkboxes
                $LvProgramNameList.add(_InsertListViewEx($idListView, StringReplace($sStrings[1][1], '"', ''), $iCount, 5, "Edit", BitOR($ES_LEFT, $ES_AUTOHSCROLL, $ES_NOHIDESEL))) ; column 6: programname
                $LvSilentKeyList.add(_InsertListViewEx($idListView, StringReplace($sStrings[3][1], '"', ''), $iCount, 6, "Edit", BitOR($ES_LEFT, $ES_AUTOHSCROLL, $ES_NOHIDESEL))) ; column 7: silentkey
                #EndRegion - Add Items
binhnx: You see i have child controls. I think i know whatĀ $WS_CLIPCHILDREN is doing, i need it, else the child controls are not drawn properly, look at my attach. But the negative side effect is that the header is grey after drawing is finished, while drawing the header looks normal, perhaps this information is relevant. $WS_CLIPSIBLINGS is set on every child control.

Ā 

Ā 

The ListView control is created on a child window:

Local $hIntegrateGui = GUICreate("Child_Integrate", 300, 300, 250, 150, BitOR($WS_CHILD, $WS_TABSTOP), -1, $hParentGui) ; child gui integrate

The Parent GUI has no styles.

post-76912-0-34375800-1413584101_thumb.p

Link to comment
Share on other sites

@Trolleule
Read the topic I linked.Ā 
Ā 

AdmiralManHairAlkex,

It is because the GUICtrlCreateListView function expects $WS_EX_* extended styles and rather than $LVS_EX_* extended styles. Moreover, the $LVS_EX_* extended styles are often numerically similar to $WS_EX_* ones and so cannot be distinguished. _GUICtrlListView_SetExtendedListViewStyle uses SENDMESSAGE to do the job and so avoids any confusion. :)

M23


Remove those $LVS_EX_.. styles from your GUICtrlCreateListView, and set them later using _GUICtrlListView_SetExtendedListViewStyle, and see the problem solved.

About $WS_CLIPCHILDREN, I must say that it'sĀ strange if your listview has child control (don't count the header). The items created by GUICtrlCreateListViewItem areĀ not control, it items only.Ā 

Edit: Sorry, I don't notice your image. Child control inside a listview is not a so good idea, try using another way :)

Edited by binhnx

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Link to comment
Share on other sites

oh sorry i don't realized it, but that increases the problem. This must be an good idea Sir, look here http://www.codeproject.com/Articles/13006/Extended-ListView

I think c# is more solid as AutoIt, but i will try to get it work. These ext. listviews are mostly done in the same way like i do.

Have you an idea what i can do to get it work please.

Edit: Also the strange thing is, that it erses the background only sometimesĀ  :ermm:Ā is it possible to cause an redraw of the listview with _WINAPI_InvalidateRect or something similar, it would be a workaround??

Edited by Trolleule
Link to comment
Share on other sites

Interesting...Ā 

Why don't you write in C# :) so you don't need to do everything yourself

Writing this kind of things in AutoIt is so heavy task, I don't like anything that is too complicate so I have no comment :)

Surely you can, try it. But I think the problem is in another part of your code. Since I have only some parts, I cannot guarantee anything. Retry with the flag, may be some flag is miss-set.

Take a look at $WS_EX_TRANSPARENT. AutoIt (not sure for what reason) put this flag on a listview by default, so when you create the listview try provide a specify exstyle like 0x200 instead of leaving empty or default

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Link to comment
Share on other sites

If everything is out of your control,Ā hide the listview. Manually add a header control and other controls connect to the items to the child window where the listview is created and handle scrolling yourself.

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Link to comment
Share on other sites

Thanks for the ideas. I can ensure that nothing other is wrong. I removed theĀ $WS_CLIPCHILDREN from the listview, then loaded the listview items with Begin- and EndUpdate. After that i put an Sleep(4000), until this moment the listview is drawn properly. After the time i set this code:Ā 

Local $iStyle   = _WinAPI_GetWindowLong(GUICtrlGetHandle($idListView), $GWL_STYLE)
_WinAPI_SetWindowLong(GUICtrlGetHandle($idListView), $GWL_STYLE, BitOR($iStyle, $WS_CLIPCHILDREN))

And the listview becomes greyĀ  :idiot: Ā thats sadĀ 

Iam not skilled enough to override the basic listview functions :/ and i can't change the language. It would engage too much time.

Ā 

Edit: Ā If $WS_CLIPCHILDREN is a function, how could it look like? I only need this flag to move the child controls and draw them properly, perhaps i can get this effect elsewhere??

Edited by Trolleule
Link to comment
Share on other sites

Ā 

Edit: Ā If $WS_CLIPCHILDREN is a function, how could it look like? I only need this flag to move the child controls and draw them properly, perhaps i can get this effect elsewhere??

Don't mess with it.Ā 

$WS_CLIPCHILDREN is a flag, not a function.

To simulate behavior of it, you need to subclass the listview (a kind of GUIRegisterMsg, but it's not available for controls in AutoIt). You need to manually subclass the listview using $pListViewOldProc = _WinAPI_SetWindowLong($idListView, -4, $pListViewNewProc) with $pListViewNewProc is created by DllCallbackGetPtr(DllCallBackRegister("YourSubclassFunc", "LRESULT", "HWND;UINT;WPARAM;LPARAM"))

Then intercept $WM_PAINT (if $uMsg = $WM_PAINT Then ...)

Then exclude clip region yourself. You need to loop all the child controls, get it position, and call _WinAPI_ExcludeClipRect()

Then paint the listview background.

Then invalidate all child controls to make them repaint themselves

Then return 1 indicate that you handled this message and both AutoIt and Windows don't need to handle it.

If $uMsg <> $WM_PAINT, you should call the default window proc by _WinAPI_CallWindowProc($pListViewOldProc, $hWnd, $uMsg, $wParam, $lParam)

A bunch of works, I think you learn C#, download the code on codeproject and use it is even faster and easier than what you are trying to do.

Double-check any style, flag style as I suggest. The $WS_CLIPCHILDREN should not be the main problem!

Edited by binhnx

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Link to comment
Share on other sites

I think i goit it.

One problem is still there, but is no side effect of the main problem. Perhaps you or someone has an idea.

Every child control i create will get the size of there subitem rectangle, and that makes problems on checkbox controls. The checkbox control have not to be as wide as the column width, but dont want to make aĀ segmentationĀ (switch, case ) like If child control is checkbox then width = 17, height = 17. The problem:

When i click an item the selection rectangle not draw over the checkbox. But if i hover over the checkbox it becomes blue. Any ideas to get a full row selection (full_rowselect flag is set -.-)?

Ā 

I could reduce the size when calculating the subitem rectsĀ 

post-76912-0-50173500-1413596643_thumb.p

Edited by Trolleule
Link to comment
Share on other sites

  • Moderators

binhnx,

Ā 

@Melba23: What's wrong with you?

You pointed out the same problem in another topic

That thread dates from a few years ago - my memory is good, but by no means perfect. :D

Besides I was not offering a solution to the problem as such - more another way of going about it. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.pngĀ AnyĀ of myĀ own codeĀ posted anywhere on the forumĀ isĀ available for use by others without any restrictionĀ of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSortĀ ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- AĀ highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort,Ā edit and colourĀ ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Ā 

Link to comment
Share on other sites

MikahS,

Gosh - thanks for that endorsement. :blush:

M23

Ā 

Least I can do for the hard work put in ;)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use. Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Ā  Forum FAQ

Ā 

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