September Posted August 27, 2023 Posted August 27, 2023 Can "GUICtrlCreateList" make below effect? Items are marked with alternate background color.
pixelsearch Posted August 27, 2023 Posted August 27, 2023 Hi September I hope you find someone being able to do it with a list control (e.g. GUICtrlCreateList) Meanwhile, here is the easy way to do it with a listview control. Who knows, it may help you in case you want to try a "no header listview control with 1 column only" looking like a list control. #include <GUIConstantsEx.au3> #include <GuiListView.au3> Example() Func Example() Local $hGUI = GUICreate("Alternate color in LV", 270, 175, 100, 200) Local $idListview = GUICtrlCreateListView("", 10, 10, 250, 155, $LVS_NOCOLUMNHEADER) _GUICtrlListView_AddColumn($idListview, "", 228) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE) ; <============ GUICtrlSetBkColor(-1, 0xFFFFFF) ; white background (will show on odd lines) For $i = 1 To 20 GUICtrlCreateListViewItem("Line " & $i, $idListview) GUICtrlSetBkColor(-1, 0xE6E6E6) ; light grey background (will show only on even lines) Next GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>Example Zedna and Musashi 2
September Posted August 27, 2023 Author Posted August 27, 2023 Hi piexlsearch, Thanks, but if using the "listview", I have to change a lot of script and it might cause other issues. Still thinking how to implement it on "list".
Andreik Posted August 27, 2023 Posted August 27, 2023 The only way it's by redrawing the control by yourself.
pixelsearch Posted August 28, 2023 Posted August 28, 2023 (edited) ( deleted the overdrawn lisbox script as it was not concise ) Edited August 29, 2023 by pixelsearch
Andreik Posted August 29, 2023 Posted August 29, 2023 Maybe Mod($itmID, 2) instead of ($itmID / 2 = Int($itmID / 2)) looks a little bit more concise.
Nine Posted August 31, 2023 Posted August 31, 2023 (edited) Maybe this ? expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListBox.au3> ; ListBox OwnerDrawn Colors Global Const $tagDRAWITEMSTRUCT = "uint CtlType;uint CtlID;uint itemID;uint itemAction;uint itemState;hwnd hwndItem;handle hDC;dword rcItem[4];ptr itemData" Global Const $ODA_DRAWENTIRE = 1 Global Const $ROW_HEIGHT = 24, $MARGIN = 4 Example() Func Example() GUICreate("Ownerdrawn Listbox", 300, 300) Local $idListBox = GUICtrlCreateList("", 4, 4, 292, 292, $WS_VSCROLL + $LBS_OWNERDRAWFIXED) _GUICtrlListBox_SetItemHeight($idListBox, $ROW_HEIGHT) For $i = 0 To 19 _GUICtrlListBox_AddString($idListBox, "") Next GUIRegisterMsg($WM_DRAWITEM, WM_DRAWITEM) GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>Example Func WM_DRAWITEM($hWnd, $iMsg, $wParam, $lParam) Local $tDRAWITEMSTRUCT = DllStructCreate($tagDRAWITEMSTRUCT, $lParam) Switch $tDRAWITEMSTRUCT.itemAction Case $ODA_DRAWENTIRE Local $tRECT = DllStructCreate($tagRECT, DllStructGetPtr($tDRAWITEMSTRUCT, "rcItem")) Local $hBrush = _WinAPI_CreateSolidBrush(Mod($tDRAWITEMSTRUCT.itemID, 2) ? 0xFFFFFF : 0xE0E0E0) _WinAPI_FillRect($tDRAWITEMSTRUCT.hDC, $tRECT, $hBrush) Local $sItemText = "Line " & $tDRAWITEMSTRUCT.itemID $tRECT.Left += $MARGIN $tRECT.Top += $MARGIN _WinAPI_DrawText($tDRAWITEMSTRUCT.hDC, $sItemText, $tRECT, $DT_LEFT) _WinAPI_DeleteObject($hBrush) EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_DRAWITEM Edited September 1, 2023 by Nine increased conciseness Zedna, KaFu and spudw2k 3 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
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