jennico Posted January 5, 2009 Share Posted January 5, 2009 (edited) when you select a line in a listbox, it gets a "selected grid". if there is an icon, it get shaded (i guess, it's the same issue). how can i prevent list box from doing so ? i am satisfied with the simple color change. expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <GuiListBox.au3> #include <GuiImageList.au3> #include <WinAPI.au3> ; Example by rasim ; modified by Prog@ndy / MsCreatoR (Index storing issue, UDF merge, and tidy source ) Global Const $ODT_LISTBOX = 2 Global Const $ODA_DRAWENTIRE = 0x1 Global Const $ODA_SELECT = 0x2 Global Const $ODS_SELECTED = 0x1 $hGUI = GUICreate("ListBox with images - Demo!", 300, 200) $hListBoxIMGList = _GUIImageList_Create(16, 16, 6, 1, 4, 90) _GUIImageList_SetBkColor($hListBoxIMGList, $CLR_NONE) GUIRegisterMsg($WM_MEASUREITEM, "WM_MEASUREITEM") $ListBox = GUICtrlCreateList("", 10, 10, 280, 180, BitOR($LBS_HASSTRINGS, $LBS_OWNERDRAWFIXED, $WS_VSCROLL)) $hListBox = GUICtrlGetHandle($ListBox) For $i = 1 To 10 _GUICtrlListBox_AddStringEx($hListBox, "String " & $i, $hListBoxIMGList, @SystemDir & "\shell32.dll", $i) Next GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM") GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func _GUICtrlListBox_AddStringEx($hWnd, $sText, $hImageList = 0, $sIconFile = "", $iIndex = 0) If $hImageList = 0 Then Return _GUICtrlListBox_AddString($hWnd, $sText) Else Local $iIconIDX = _GUIImageList_AddIcon($hImageList, $sIconFile, $iIndex, 0) Local $iStrIndex = _GUICtrlListBox_AddString($hWnd, $sText) _GUICtrlListBox_SetItemData($hWnd, $iStrIndex, $iIconIDX) Return $iStrIndex EndIf EndFunc Func WM_MEASUREITEM($hWnd, $Msg, $wParam, $lParam) Local $CtlType, $tagMEASUREITEMSTRUCT = "UINT CtlType;UINT CtlID;UINT itemID;UINT itemWidth;UINT itemHeight;ULONG_PTR itemData;" Local $MEASUREITEMSTRUCT = DllStructCreate($tagMEASUREITEMSTRUCT, $lParam) $CtlType = DllStructGetData($MEASUREITEMSTRUCT, "CtlType") If $CtlType <> $ODT_LISTBOX Then Return $GUI_RUNDEFMSG DllStructSetData($MEASUREITEMSTRUCT, 5, 18) DllStructSetData($MEASUREITEMSTRUCT, 4, DllStructGetData($MEASUREITEMSTRUCT, 4) + 18) Return EndFunc Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam) Local $tagDRAWITEMSTRUCT, $cID, $itmID, $itmAction, $itmState, $hItm, $hDC, $iBrushColor, $hBrush, $hBrushOld $tagDRAWITEMSTRUCT = DllStructCreate("uint cType;uint cID;uint itmID;uint itmAction;uint itmState;" & _ "hwnd hItm;hwnd hDC;int itmRect[4];dword itmData", $lParam) If DllStructGetData($tagDRAWITEMSTRUCT, "cType") <> $ODT_LISTBOX 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") Switch $itmAction Case $ODA_DRAWENTIRE, $ODA_SELECT If $itmState = $ODS_SELECTED Then $iBrushColor = 0x6495ED Else $iBrushColor = 0x66CDAA EndIf $hBrush = _WinAPI_CreateSolidBrush($iBrushColor) $hBrushOld = _WinAPI_SelectObject($hDC, $hBrush) DllCall("user32.dll", "int", "FillRect", _ "hwnd", $hDC, _ "ptr", DllStructGetPtr($tagDRAWITEMSTRUCT, "itmRect"), _ "hwnd", $hBrush) _WinAPI_SelectObject($hDC, $hBrushOld) _WinAPI_DeleteObject($hBrush) DllCall("gdi32.dll", "int", "SetBkMode", "hwnd", $hDC, "int", 1) Local $tBuffer = DllStructCreate("char[256]") DllCall("user32.dll", "int", "SendMessage", _ "hwnd", $hItm, _ "int", $LB_GETTEXT, _ "int", $itmID, _ "ptr", DllStructGetPtr($tBuffer)) Local $itmText = DllStructGetData($tBuffer, 1) Local $itmTextIMG = _GUICtrlListBox_GetItemData($hListBox, $itmID) Local $tRECT = DllStructCreate("int Left;int Top;int Right;int Bottom") DllStructSetData($tRECT, "Left", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 1) + 18) DllStructSetData($tRECT, "Top", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 2)) DllStructSetData($tRECT, "Right", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 3)) DllStructSetData($tRECT, "Bottom", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 4)) DllCall("user32.dll", "int", "DrawText", "hwnd", $hDC, "str", $itmText, "int", StringLen($itmText), _ "ptr", DllStructGetPtr($tRECT), "int", $DT_LEFT) Local $iX = DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 1) + 1 Local $iY = DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 2) + 1 Local $fIsSelected = ($itmState = $ODS_SELECTED) * 2 If $itmTextIMG >= 0 Then _GUIImageList_Draw($hListBoxIMGList, $itmTextIMG, $hDC, $iX, $iY, BitOR(1, $fIsSelected)) EndSwitch Return $GUI_RUNDEFMSG EndFunc thx ! Edited January 5, 2009 by jennico Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96 Link to comment Share on other sites More sharing options...
rover Posted January 5, 2009 Share Posted January 5, 2009 when you select a line in a listbox, it gets a "selected grid". if there is an icon, it get shaded (i guess, it's the same issue). how can i prevent list box from doing so ? i am satisfied with the simple color change. expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <GuiListBox.au3> #include <GuiImageList.au3> #include <WinAPI.au3> ; Example by rasim ; modified by Prog@ndy / MsCreatoR (Index storing issue, UDF merge, and tidy source ) Global Const $ODT_LISTBOX = 2 Global Const $ODA_DRAWENTIRE = 0x1 Global Const $ODA_SELECT = 0x2 Global Const $ODS_SELECTED = 0x1 $hGUI = GUICreate("ListBox with images - Demo!", 300, 200) $hListBoxIMGList = _GUIImageList_Create(16, 16, 6, 1, 4, 90) _GUIImageList_SetBkColor($hListBoxIMGList, $CLR_NONE) GUIRegisterMsg($WM_MEASUREITEM, "WM_MEASUREITEM") $ListBox = GUICtrlCreateList("", 10, 10, 280, 180, BitOR($LBS_HASSTRINGS, $LBS_OWNERDRAWFIXED, $WS_VSCROLL)) $hListBox = GUICtrlGetHandle($ListBox) For $i = 1 To 10 _GUICtrlListBox_AddStringEx($hListBox, "String " & $i, $hListBoxIMGList, @SystemDir & "\shell32.dll", $i) Next GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM") GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func _GUICtrlListBox_AddStringEx($hWnd, $sText, $hImageList = 0, $sIconFile = "", $iIndex = 0) If $hImageList = 0 Then Return _GUICtrlListBox_AddString($hWnd, $sText) Else Local $iIconIDX = _GUIImageList_AddIcon($hImageList, $sIconFile, $iIndex, 0) Local $iStrIndex = _GUICtrlListBox_AddString($hWnd, $sText) _GUICtrlListBox_SetItemData($hWnd, $iStrIndex, $iIconIDX) Return $iStrIndex EndIf EndFunc Func WM_MEASUREITEM($hWnd, $Msg, $wParam, $lParam) Local $CtlType, $tagMEASUREITEMSTRUCT = "UINT CtlType;UINT CtlID;UINT itemID;UINT itemWidth;UINT itemHeight;ULONG_PTR itemData;" Local $MEASUREITEMSTRUCT = DllStructCreate($tagMEASUREITEMSTRUCT, $lParam) $CtlType = DllStructGetData($MEASUREITEMSTRUCT, "CtlType") If $CtlType <> $ODT_LISTBOX Then Return $GUI_RUNDEFMSG DllStructSetData($MEASUREITEMSTRUCT, 5, 18) DllStructSetData($MEASUREITEMSTRUCT, 4, DllStructGetData($MEASUREITEMSTRUCT, 4) + 18) Return EndFunc Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam) Local $tagDRAWITEMSTRUCT, $cID, $itmID, $itmAction, $itmState, $hItm, $hDC, $iBrushColor, $hBrush, $hBrushOld $tagDRAWITEMSTRUCT = DllStructCreate("uint cType;uint cID;uint itmID;uint itmAction;uint itmState;" & _ "hwnd hItm;hwnd hDC;int itmRect[4];dword itmData", $lParam) If DllStructGetData($tagDRAWITEMSTRUCT, "cType") <> $ODT_LISTBOX 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") Switch $itmAction Case $ODA_DRAWENTIRE, $ODA_SELECT If $itmState = $ODS_SELECTED Then $iBrushColor = 0x6495ED Else $iBrushColor = 0x66CDAA EndIf $hBrush = _WinAPI_CreateSolidBrush($iBrushColor) $hBrushOld = _WinAPI_SelectObject($hDC, $hBrush) DllCall("user32.dll", "int", "FillRect", _ "hwnd", $hDC, _ "ptr", DllStructGetPtr($tagDRAWITEMSTRUCT, "itmRect"), _ "hwnd", $hBrush) _WinAPI_SelectObject($hDC, $hBrushOld) _WinAPI_DeleteObject($hBrush) DllCall("gdi32.dll", "int", "SetBkMode", "hwnd", $hDC, "int", 1) Local $tBuffer = DllStructCreate("char[256]") DllCall("user32.dll", "int", "SendMessage", _ "hwnd", $hItm, _ "int", $LB_GETTEXT, _ "int", $itmID, _ "ptr", DllStructGetPtr($tBuffer)) Local $itmText = DllStructGetData($tBuffer, 1) Local $itmTextIMG = _GUICtrlListBox_GetItemData($hListBox, $itmID) Local $tRECT = DllStructCreate("int Left;int Top;int Right;int Bottom") DllStructSetData($tRECT, "Left", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 1) + 18) DllStructSetData($tRECT, "Top", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 2)) DllStructSetData($tRECT, "Right", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 3)) DllStructSetData($tRECT, "Bottom", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 4)) DllCall("user32.dll", "int", "DrawText", "hwnd", $hDC, "str", $itmText, "int", StringLen($itmText), _ "ptr", DllStructGetPtr($tRECT), "int", $DT_LEFT) Local $iX = DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 1) + 1 Local $iY = DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 2) + 1 Local $fIsSelected = ($itmState = $ODS_SELECTED) * 2 If $itmTextIMG >= 0 Then _GUIImageList_Draw($hListBoxIMGList, $itmTextIMG, $hDC, $iX, $iY, BitOR(1, $fIsSelected)) EndSwitch Return $GUI_RUNDEFMSG EndFunc thx ! I'll give you a hint. you should be able to figure this one out, it's in the help file. _GUIImageList_Draw() btw, Valik has posted a response to your topic in Developer chat. http://www.autoitscript.com/forum/index.php?showtopic=87063 cheers I see fascists... Link to comment Share on other sites More sharing options...
jennico Posted January 5, 2009 Author Share Posted January 5, 2009 (edited) thank you for pointing me to that. i can set the style to 0 or 1 (there seems no differernce). then i have no blend on the icons anymore ! very nice ! If $itmTextIMG >= 0 Then _GUIImageList_Draw($hListBoxIMGList, $itmTextIMG, $hDC, $iX, $iY, 1); Or 0 ;BitOR(1, $fIsSelected)) but i still have the dashed / dotted box around the selected item. how do i get rid of that ? thx j. Edited January 5, 2009 by jennico Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96 Link to comment Share on other sites More sharing options...
rover Posted January 5, 2009 Share Posted January 5, 2009 thank you for pointing me to that. i can set the style to 0 or 1 (there seems no differernce). then i have no blend on the icons anymore ! very nice ! If $itmTextIMG >= 0 Then _GUIImageList_Draw($hListBoxIMGList, $itmTextIMG, $hDC, $iX, $iY, 1); Or 0 ;BitOR(1, $fIsSelected)) but i still have the dashed / dotted box around the selected item. how do i get rid of that ? thx j. the example code I think is originally from Siao and Gary Frost this bit is from the example they posted. Switch $itmAction Case $ODA_FOCUS ;~ Return $GUI_RUNDEFMSG;enable for focus rectangle Return 1 I see fascists... Link to comment Share on other sites More sharing options...
jennico Posted January 5, 2009 Author Share Posted January 5, 2009 (edited) can you give me a link to this ? i need the value for $ODA_FOCUS. i took my above example from here.edit: i searched forum for $ODA_FOCUS without result. so maybe you can paste the entire example ?thx Edited January 5, 2009 by jennico Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96 Link to comment Share on other sites More sharing options...
jennico Posted January 5, 2009 Author Share Posted January 5, 2009 thanks to your help i solved it: expandcollapse popupGlobal Const $ODA_FOCUS = 4 If $itmAction = $ODA_FOCUS Then Return 1;$GUI_RUNDEFMSGoÝ÷ ÚØ^ën®{ÚçµÈ¦¦íj{m¢Þ½éí¶¬zWµç[£(,¶Ø^ë.×è®az»,w¶«z+'¢az·±jjez«zØZ¶ë³Mú808%jëh×6#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <GuiListBox.au3> #include <GuiImageList.au3> #include <WinAPI.au3> ; Example by rasim ; modified by Prog@ndy / MsCreatoR (Index storing issue, UDF merge, and tidy source ) Global Const $ODT_LISTBOX = 2 Global Const $ODA_DRAWENTIRE = 0x1 Global Const $ODA_SELECT = 0x2 Global Const $ODS_SELECTED = 0x1 Global Const $ODA_FOCUS = 4 $hGUI = GUICreate("ListBox with images - Demo!", 300, 200) $hListBoxIMGList = _GUIImageList_Create(16, 16, 6, 1, 4, 90) _GUIImageList_SetBkColor($hListBoxIMGList, $CLR_NONE) GUIRegisterMsg($WM_MEASUREITEM, "WM_MEASUREITEM") $ListBox = GUICtrlCreateList("", 10, 10, 280, 180, BitOR($LBS_HASSTRINGS, $LBS_OWNERDRAWFIXED, $WS_VSCROLL)) $hListBox = GUICtrlGetHandle($ListBox) For $i = 1 To 10 _GUICtrlListBox_AddStringEx($hListBox, "String " & $i, $hListBoxIMGList, @SystemDir & "\shell32.dll", $i) Next GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM") GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func _GUICtrlListBox_AddStringEx($hWnd, $sText, $hImageList = 0, $sIconFile = "", $iIndex = 0) If $hImageList = 0 Then Return _GUICtrlListBox_AddString($hWnd, $sText) Else Local $iIconIDX = _GUIImageList_AddIcon($hImageList, $sIconFile, $iIndex, 0) Local $iStrIndex = _GUICtrlListBox_AddString($hWnd, $sText) _GUICtrlListBox_SetItemData($hWnd, $iStrIndex, $iIconIDX) Return $iStrIndex EndIf EndFunc Func WM_MEASUREITEM($hWnd, $Msg, $wParam, $lParam) Local $CtlType, $tagMEASUREITEMSTRUCT = "UINT CtlType;UINT CtlID;UINT itemID;UINT itemWidth;UINT itemHeight;ULONG_PTR itemData;" Local $MEASUREITEMSTRUCT = DllStructCreate($tagMEASUREITEMSTRUCT, $lParam) $CtlType = DllStructGetData($MEASUREITEMSTRUCT, "CtlType") If $CtlType <> $ODT_LISTBOX Then Return $GUI_RUNDEFMSG DllStructSetData($MEASUREITEMSTRUCT, 5, 18) DllStructSetData($MEASUREITEMSTRUCT, 4, DllStructGetData($MEASUREITEMSTRUCT, 4) + 18) Return EndFunc Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam) Local $tagDRAWITEMSTRUCT, $cID, $itmID, $itmAction, $itmState, $hItm, $hDC, $iBrushColor, $hBrush, $hBrushOld $tagDRAWITEMSTRUCT = DllStructCreate("uint cType;uint cID;uint itmID;uint itmAction;uint itmState;" & _ "hwnd hItm;hwnd hDC;int itmRect[4];dword itmData", $lParam) If DllStructGetData($tagDRAWITEMSTRUCT, "cType") <> $ODT_LISTBOX 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") Switch $itmAction Case $ODA_FOCUS ;~ Return $GUI_RUNDEFMSG;enable for focus rectangle Return 1 Case $ODA_DRAWENTIRE, $ODA_SELECT If $itmState = $ODS_SELECTED Then $iBrushColor = 0x6495ED Else $iBrushColor = 0x66CDAA EndIf $hBrush = _WinAPI_CreateSolidBrush($iBrushColor) $hBrushOld = _WinAPI_SelectObject($hDC, $hBrush) DllCall("user32.dll", "int", "FillRect", _ "hwnd", $hDC, _ "ptr", DllStructGetPtr($tagDRAWITEMSTRUCT, "itmRect"), _ "hwnd", $hBrush) _WinAPI_SelectObject($hDC, $hBrushOld) _WinAPI_DeleteObject($hBrush) DllCall("gdi32.dll", "int", "SetBkMode", "hwnd", $hDC, "int", 1) Local $tBuffer = DllStructCreate("char[256]") DllCall("user32.dll", "int", "SendMessage", _ "hwnd", $hItm, _ "int", $LB_GETTEXT, _ "int", $itmID, _ "ptr", DllStructGetPtr($tBuffer)) Local $itmText = DllStructGetData($tBuffer, 1) Local $itmTextIMG = _GUICtrlListBox_GetItemData($hListBox, $itmID) Local $tRECT = DllStructCreate("int Left;int Top;int Right;int Bottom") DllStructSetData($tRECT, "Left", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 1) + 18) DllStructSetData($tRECT, "Top", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 2)) DllStructSetData($tRECT, "Right", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 3)) DllStructSetData($tRECT, "Bottom", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 4)) DllCall("user32.dll", "int", "DrawText", "hwnd", $hDC, "str", $itmText, "int", StringLen($itmText), _ "ptr", DllStructGetPtr($tRECT), "int", $DT_LEFT) Local $iX = DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 1) + 1 Local $iY = DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 2) + 1 Local $fIsSelected = ($itmState = $ODS_SELECTED) * 2 If $itmTextIMG >= 0 Then _GUIImageList_Draw($hListBoxIMGList, $itmTextIMG, $hDC, $iX, $iY);, BitOR(1, $fIsSelected)) EndSwitch Return $GUI_RUNDEFMSG EndFunc there are no selected boxes anymore and no shadow masks on the icons. very interesting. Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96 Link to comment Share on other sites More sharing options...
jennico Posted January 5, 2009 Author Share Posted January 5, 2009 @rover i would still be very interested in Siao's and Gary's example script, if you find it ! Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96 Link to comment Share on other sites More sharing options...
rover Posted January 5, 2009 Share Posted January 5, 2009 @rover i would still be very interested in Siao's and Gary's example script, if you find it !edit: i searched forum for $ODA_FOCUS without result. so maybe you can paste the entire example ?strip the dollar sign from constants for forum or Google AutoIt site searches.example by Siao, modified by Gary Frost (attribution is in such short supply on the forum)ListBox Set Selection Color, Default is dark Bluehttp://www.autoitscript.com/forum/index.php?showtopic=56066 I see fascists... Link to comment Share on other sites More sharing options...
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