Tec Posted July 26, 2010 Posted July 26, 2010 Hi i need some help with Listview Sort and Background Color. Example: expandcollapse popup#include <GuiListView.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Gui = GUICreate("Test", 300, 200) $hListView = GUICtrlCreateListView("Client | Status", 5, 0, 290, 250) GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) For $a = 1 To 10 if $a = 4 then GUICtrlCreateListViewItem("PC" & $a & "| Offline", $hListView) GUICtrlSetBkColor(-1, 0xFF0000) else GUICtrlCreateListViewItem("PC" & $a & "| Online", $hListView) EndIf Next GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)] While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch Sleep( 10 ) WEnd Exit Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView $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 $LVN_COLUMNCLICK Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) _GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) EndSwitch EndSwitch EndFunc I want to highlight all Offline clients. But how can I highlight the offline Clients if the order change? I read something about $NM_CUSTOMDRAW and read the post from Siao but i dont understand this. Need some small Example/help please.
KaFu Posted July 26, 2010 Posted July 26, 2010 (edited) Here ya go ... expandcollapse popup#include <GuiListView.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Gui = GUICreate("Test", 300, 200) $hListView = GUICtrlCreateListView("Client | Status", 5, 0, 290, 250) GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) For $a = 1 To 10 If $a = 4 Then GUICtrlCreateListViewItem("PC" & $a & "| Offline", $hListView) Else GUICtrlCreateListViewItem("PC" & $a & "| Online", $hListView) EndIf Next GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState() Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)] While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch Sleep(10) WEnd Exit Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView $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 $LVN_COLUMNCLICK Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) _GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) Case $NM_CUSTOMDRAW Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam) Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage") Switch $iDrawStage Case $CDDS_PREPAINT Return $CDRF_NOTIFYITEMDRAW ;request custom drawing of items Case $CDDS_ITEMPREPAINT Return $CDRF_NOTIFYSUBITEMDRAW ;request drawing each cell separately EndSwitch Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec") Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem") Local $hDC = DllStructGetData($tCustDraw, 'hdc') If $iSubItem = 1 Then If _GUICtrlListView_GetItemText($hWndListView, $iItem, 1) = " Offline" Then ;ConsoleWrite(_GUICtrlListView_GetItemText($hWndListView, $iItem, 1) & @CRLF) DllStructSetData($tCustDraw, "clrTextBk", 0x0000FF) ; in BGR EndIf EndIf Return $CDRF_NEWFONT EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Edit: Added "Return $GUI_RUNDEFMSG" to the Notify functions. Edited July 26, 2010 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
Tec Posted July 27, 2010 Author Posted July 27, 2010 Good morning I change the code to highlight the complete row. But two more question I have. 1. Is the code modification the right way ? It works for me but I am a little bit confusion about the Return Values $CDRF_NEWFONT and $CDRF_NOTIFYSUBITEMDRAW 2. Is there a simple way to highlight only the "offline" cell ? thx for help expandcollapse popup#include <GuiListView.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Gui = GUICreate("Test", 300, 200) $hListView = GUICtrlCreateListView("Client | Status| test", 5, 0, 290, 250) GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) For $a = 1 To 10 If $a = 4 Then GUICtrlCreateListViewItem("PC" & $a & "|Offline|" & $a, $hListView) Else GUICtrlCreateListViewItem("PC" & $a & "|Online|" & $a, $hListView) EndIf Next GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState() Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)] While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch Sleep(10) WEnd Exit Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView $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 $LVN_COLUMNCLICK Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) _GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) Case $NM_CUSTOMDRAW Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam) Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage") Switch $iDrawStage Case $CDDS_PREPAINT Return $CDRF_NOTIFYITEMDRAW ;request custom drawing of items Case $CDDS_ITEMPREPAINT Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec") If _GUICtrlListView_GetItemText($hWndListView, $iItem, 1) = "Offline" Then DllStructSetData($tCustDraw, "clrTextBk", 0x0000FF) EndIf Return $CDRF_NOTIFYSUBITEMDRAW ;request drawing each cell separately EndSwitch #cs Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec") Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem") ;Local $hDC = DllStructGetData($tCustDraw, 'hdc') If $iSubItem = 1 Then If _GUICtrlListView_GetItemText($hWndListView, $iItem, 1) = "Offline" Then ConsoleWrite(_GUICtrlListView_GetItemText($hWndListView, $iItem, 1) & @CRLF) DllStructSetData($tCustDraw, "clrTextBk", 0x0000FF) ; in BGR EndIf EndIf Return $CDRF_NEWFONT #ce EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY
KaFu Posted July 27, 2010 Posted July 27, 2010 (edited) It works for me but I am a little bit confusion about the Return Values $CDRF_NEWFONT and $CDRF_NOTIFYSUBITEMDRAW Don't ask me about the why's, thats just the way its documented ... 2. Is there a simple way to highlight only the "offline" cell ? According to this MSDN article, I would have expected a $CDDS_SUBITEM drawing stage... but case else also seems to work fine ... expandcollapse popup#include <GuiListView.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Gui = GUICreate("Test", 300, 200) $hListView = GUICtrlCreateListView("Client | Status| test", 5, 0, 290, 250) GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) For $a = 1 To 10 If $a = 4 Then GUICtrlCreateListViewItem("PC" & $a & "|Offline|" & $a, $hListView) Else GUICtrlCreateListViewItem("PC" & $a & "|Online|" & $a, $hListView) EndIf Next GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState() Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)] While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch Sleep(10) WEnd Exit Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView $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 $LVN_COLUMNCLICK Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) _GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) Case $NM_CUSTOMDRAW ; http://msdn.microsoft.com/en-us/library/bb761817(VS.85).aspx Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam) Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage") Switch $iDrawStage Case $CDDS_PREPAINT Return $CDRF_NOTIFYITEMDRAW ;request custom drawing of items Case $CDDS_ITEMPREPAINT Return $CDRF_NOTIFYSUBITEMDRAW Case Else ;case $CDDS_SUBITEM Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec") Switch DllStructGetData($tCustDraw, "iSubItem") Case 1 If _GUICtrlListView_GetItemText($hWndListView, $iItem, 1) = "Offline" Then DllStructSetData($tCustDraw, "clrTextBk", 0x0000FF) Else DllStructSetData($tCustDraw, "clrTextBk", 0xffffff) EndIf Case Else DllStructSetData($tCustDraw, "clrTextBk", 0xffffff) EndSwitch Return $CDRF_NEWFONT EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Edited July 27, 2010 by KaFu Chiitus 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
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