Jump to content

listview subitem ‘s bkcolor


netegg
 Share

Recommended Posts

I've made out a listview with the checkbox in subitem, but i don't know why the subitem has a block grey color on the right side in the subitem, could anybody tell me?

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <GuiEdit.au3>

Opt('MustDeclareVars', 1)

$Debug_LV = False

Global $hListView, $hButton[100], $hGUI,$hDC,$hBrush

_Main()

Func _Main()

    $hGUI = GUICreate("(UDF Created) ListView Create", 400, 300)

    $hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 394, 268, $LVS_EX_GRIDLINES)
    GUISetState()
    
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    ; Add columns
    _GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
    _GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 112)
    _GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)

    ; Add items
    _GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0)
    _GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1)
    _GUICtrlListView_AddItem($hListView, "Row 3: Col 1", 2)
    _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1)
    _GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1)
    _GUICtrlListView_AddSubItem($hListView, 2, "Row 3: Col 2", 1)
    For $i = 0 To _GUICtrlListView_GetItemCount($hListView) - 1
        _initedit($i, 1)  
    Next

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

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom,  $iCode, $tNMHDR, $hWndListView, $tInfo, $Index
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK    
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    $Index = DllStructGetData($tInfo, "Index")
                    
                    If _GUICtrlButton_GetCheck($hButton[$Index]) Then                 
                        _GUICtrlButton_SetCheck($hButton[$Index], $BST_UNCHECKED)
                    Else
                        _GUICtrlButton_SetCheck($hButton[$Index])
                    EndIf
                    ConsoleWrite(_GUICtrlButton_GetState($hButton[$Index]) & @CRLF)     
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Func _initedit($item, $subitem)                
    Local $iSubItemText = _GUICtrlListView_GetItemText($hListView, $item, $subitem)
    Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $item, $subitem)
    $hButton[$item] = _GUICtrlButton_Create($hGUI, '', $aRect[0], $aRect[1], 16, 17, $BS_AUTOCHECKBOX + $bs_flat)
    Local $hEdit =_GUICtrlEdit_Create($hGUI, $iSubItemText, $aRect[0] + 16, $aRect[1], 100, 17)
    $hDC = _WinAPI_GetWindowDC($hEdit)
    $hBrush = _WinAPI_CreateSolidBrush(0x0000FF)
    FrameRect($hDC, $aRect[0] + 16, $aRect[1], 100, 17, $hBrush)
EndFunc   ;==>_initedit
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)
EndFunc   ;==>FrameRect
Edited by netegg
Link to comment
Share on other sites

It's the bizarre button you put there with _GuiCtrlButton_Create() inside the equally bizarre _initedit() function.

Why you put there is anybody's guess.

BTW, your WM_NOTIFY function crashes if you click on any column other than the first, because $Index = -1. See MSDN: NM_CLICK (List View) Notification:

Remarks

The iItem member of lParam is only valid if the icon or first-column label has been clicked. To determine which item is selected when a click takes place elsewhere in a row, send an LVM_SUBITEMHITTEST message.

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

It's the bizarre button you put there with _GuiCtrlButton_Create() inside the equally bizarre _initedit() function.

Why you put there is anybody's guess.

BTW, your WM_NOTIFY function crashes if you click on any column other than the first, because $Index = -1. See MSDN: NM_CLICK (List View) Notification:

:mellow:

Hi, thx. But how should I do? I've had no mind!
Link to comment
Share on other sites

It looks like you copy/pasted this from somewhere else with no idea how any of it works. That makes it hard to figure out how much you need to know.

1. If you didn't need the button there for some reason, just delete it from the script.

2. Test $Index to see if it's < 0, and if so either ignore it (requiring the user to click either the first column or icon), or send LVM_SUBITEMHITTEST to find out which item it was. What matters is not using $Index when it's invalid, i.e. for $hButton[$Index].

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...