Mingre Posted May 24, 2016 Posted May 24, 2016 (edited) expandcollapse popup#include <GuiListView.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <WinAPI.au3> #include <GuiEdit.au3> Global $tText = DllStructCreate("wchar[100]") Global $aItems[100000][10], $aColors[100][10] Global $hGuui, $hListView Global $hEdit, $hDC, $hBrush, $Item = -1, $SubItem = 0 $hGUI = GUICreate("ListView Subitems edit in place", 300, 200) $hListView = _GUICtrlListView_Create($hGUI, "Items|SubItems|hwhw", 2, 2, 296, 196, $LVS_REPORT, BitOR( $WS_EX_CLIENTEDGE, $LVS_EX_DOUBLEBUFFER, $LVS_EX_FULLROWSELECT )) _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_GRIDLINES) For $i = 1 To 10 _GUICtrlListView_AddItem($hListView, "Item " & $i) _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 1) _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 2) Next GUISetState(@SW_SHOW, $hGuui) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") For $row = 0 To 10 Step +1 For $col = 0 To 2 Step +1 $aColors[$row][$col] = 0xCCCCFF Next Next GUICtrlSendMsg( $hListView, $LVM_SETITEMCOUNT, 10, 0 ) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_DBLCLK ; used for sub item edit Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) $SubItem = DllStructGetData($tInfo, "SubItem") Switch $SubItem Case 0 _GUICtrlListView_EditLabel($hWndFrom, DllStructGetData($tInfo, "Index")) Case Else Local $aHit = _GUICtrlListView_SubItemHitTest($hListView) If ($aHit[0] <> -1) And ($aHit[1] > 0) Then $Item = $aHit[0] ;$SubItem = $aHit[1] Local $iSubItemText = _GUICtrlListView_GetItemText($hListView, $Item, $SubItem) Local $iLen = _GUICtrlListView_GetStringWidth($hListView, $iSubItemText) Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $Item, $SubItem) $hEdit = _GUICtrlEdit_Create($hGUI, $iSubItemText, $aRect[0] + 6, $aRect[1], $iLen + 10, 17, BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)) _GUICtrlEdit_SetSel($hEdit, 0, -1) _WinAPI_SetFocus($hEdit) $hDC = _WinAPI_GetWindowDC($hEdit) $hBrush = _WinAPI_CreateSolidBrush(0) ;FrameRect($hDC, 0, 0, $iLen + 10, 17, $hBrush) EndIf EndSwitch Case $NM_CUSTOMDRAW Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam) Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage") Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any item-related drawing operations Case $CDDS_ITEMPREPAINT ; Before painting an item Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any subitem-related drawing operations Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM) ; Before painting a subitem ;Local $iItem = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec") ; Item index ;Local $iSubItem = DllStructGetData($tNMLVCUSTOMDRAW, "iSubItem") ; Subitem index ;DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", $aColors[$iItem][$iSubItem] ) ; Backcolor of item/subitem DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", $aColors[DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec")][DllStructGetData($tNMLVCUSTOMDRAW, "iSubItem")]) Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY 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 Func WM_COMMAND($hWnd, $Msg, $wParam, $ilParam) Local $iCode = BitShift($wParam, 16) Switch $ilParam Case $hEdit Switch $iCode Case $EN_KILLFOCUS Local $iText = _GUICtrlEdit_GetText($hEdit) _GUICtrlListView_SetItemText($hListView, $Item, $iText, $SubItem) _WinAPI_DeleteObject($hBrush) _WinAPI_ReleaseDC($hEdit, $hDC) _WinAPI_DestroyWindow($hEdit) ;ToolTip('hehe') $Item = -1 $SubItem = 0 EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND The listview initially appears white and becomes colored only after it is placed below another window. (I'm using XP SP3.) Thanks! PS: I don't own the script, Got this somewhere else in this site but I failed to save the source, sorry. Edited May 25, 2016 by Mingre
Moderators Melba23 Posted May 24, 2016 Moderators Posted May 24, 2016 Mingre, Move the GUIRegisterMsg lines to before the GUISetState line - that way the handlers can do the colouring as the GUI is first displayed. As it is they only take affect on the first redraw after the initial display. M23 Mingre 1 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: Reveal hidden contents ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now