Champak Posted February 29, 2008 Share Posted February 29, 2008 (edited) I just can't get the alternate color thing working on my listview. So help please. I see how it is done when you have a few rows and you set the colors right under the item, but I haven't seen an example of how to do it with an array, and my attempt just isn't working...it is setting the whole listview to the color. Also if it is possible, I would rather be able to select both my alternating colors, rather than the one color that alternates with the regular white. $GUISongList = GUICreate("Song List", $GUIWidth, 330,$GUIXPOS, $GUIYPOS+86, $WS_POPUP+$WS_BORDER,BitOr($WS_EX_TOPMOST,$WS_EX_TOOLWINDOW)) $SongListView = GUICtrlCreateListView("", 5, 5, 590, 258,-1,$LVS_EX_FULLROWSELECT+$LVS_EX_GRIDLINES+$LVS_EX_TRACKSELECT) GUICtrlSetBkColor($SongListView, $GUI_BKCOLOR_LV_ALTERNATE) GUICtrlSetFont($SongListView, 16, 700, "") _GUICtrlListView_AddColumn ($SongListView, "Song", 335) _GUICtrlListView_AddColumn ($SongListView, "Artist", 230) Dim $SongListItems[UBound($aSource)][2] For $z = 0 To UBound($aSource) - 1 $SongListItems[$z][0] = StringReplace(Stringtrimleft($aSource[$z][0], StringInStr($aSource[$z][0], "\", 0, -1)),".mp3","") $SongListItems[$z][1] = $aSource[$z][2] GUICtrlSetBkColor($SongListView,0xFF0000) _ConsoleWrite($aSource[$z][0] & " Songs - : - (Line = " & @ScriptLineNumber & ")") Next Also, is there a way to speed up the "Hot" select function...how fast the highlight appears when you hover over a list item? Edited February 29, 2008 by Champak Link to comment Share on other sites More sharing options...
Champak Posted March 2, 2008 Author Share Posted March 2, 2008 (edited) 1/ I figured how to get the alternate bgcolor with listview. But in doing so I have to get rid of the "_GUICtrlListView_AddColumn" and instead put "GUICtrlCreateListViewItem" in my loop. That basically brings me to another problem in my column width not being what I want. I know about padding the header, but that gets to be so messy with how much padding I want and it doesn't even actually pad how much I want. So I'm still stuck at my problem of adding back ground alternate color to my listview. Anyone?2/ How do I utilize something like "_GUICtrlListBox_SetCurSel" for _GUICtrlListView_? I've tried "_SetSelectionMark ", "_SetItemSelected ", "_SetHotItem ", and "_SetItemFocused" in _GUICtrlListView. None have done the trick unless I am utilizing them incorrectly. Is this possible?3/ Lastly, how do I colorize the selected item as well? I've tried doing the following, but I can only get it to work in a single column situation, it fails because I have two columns.:$SongListView = GUICtrlCreateListView("", 5, 5, 590, 258,-1,$LVS_EX_FULLROWSELECT+$LVS_EX_GRIDLINES+$LVS_EX_TRACKSELECT) ;============================= ;==========BUNCH OF OTHER STUFF ;============================= $SongTitleItem = $oPlayer1.currentMedia.getItemInfobyAtom($oPlayer1.mediaCollection.getMediaAtom("Title")) For $i = 0 To UBound($SongListItems) If GUICtrlRead($SongListItems[$i][0]) = $SongTitleItem Then For $x = 0 To UBound($SongListItems) Next ExitLoop EndIf Next GUICtrlSetBkColor($SongListItems[$i][0], 0xFF0000) GUICtrlSetBkColor($SongListItems[$i][1], 0xFF0000)I got the concept from this: http://www.autoitscript.com/forum/index.ph...st&p=337385If you need more code let me know.4/ I figured out how to speed up the highlight...right in the help, just didn't see it.Thanks Edited March 2, 2008 by Champak Link to comment Share on other sites More sharing options...
Champak Posted March 12, 2008 Author Share Posted March 12, 2008 Bump Link to comment Share on other sites More sharing options...
Siao Posted March 12, 2008 Share Posted March 12, 2008 Good posts are hard to find, aren't they... #487264 "be smart, drink your wine" Link to comment Share on other sites More sharing options...
Champak Posted March 12, 2008 Author Share Posted March 12, 2008 (edited) Ha, Ha. I actually found that a couple days ago, but my error in what I sometimes do when I'm multitasking is go to the last posted code and check that out, because usually the first couple of codes are just working out bugs in the code. The last code wasn't working for me, so I just gave it up after fiddling with it for an hour or so. Anyway, this looks VERY good, great work. But I am also having a problem with this and haven't been able to solve it. Somewhere in the function you created is activating some other buttons in my script and I can't figure it out. When I click on the 4th and 5th row (counting: 0,1,2,3,"4","5") in my listview, it is activating my "$CloseSongList" and "$SelectSongList" buttons (and I have a feeling it is going to activate a couple other buttons in my main loop). Here is what it looks like....I've widdled what you have down to fit my needs...and of course not including the globals. expandcollapse popupFunc _SongList() $GUISongList = GUICreate("Song List", $GUIWidth, 330,$GUIXPOS, $GUIYPOS+86, $WS_POPUP+$WS_BORDER,BitOr($WS_EX_TOPMOST,$WS_EX_TOOLWINDOW)) $SongListView = GUICtrlCreateListView("", 5, 5, 590, 258,-1,$LVS_EX_FULLROWSELECT+$LVS_EX_GRIDLINES+$LVS_EX_TRACKSELECT) $hListView = GUICtrlGetHandle($SongListView) GUICtrlSetFont($SongListView, 16, 700, "") _GUICtrlListView_SetHoverTime($SongListView, 10) _GUICtrlListView_InsertColumn ($SongListView, 0, "Song", 335) _GUICtrlListView_InsertColumn ($SongListView, 1, "Artist", 230) For $i = 0 To UBound($aSource) - 1 _GUICtrlListView_AddItem($SongListView, StringReplace(Stringtrimleft($aSource[$i][0], StringInStr($aSource[$i][0], "\", 0, -1)),".mp3","")) For $j = 1 To 2 _GUICtrlListView_AddSubItem ($SongListView, $i, $aSource[$i][1], $j) Next _ConsoleWrite($aSource[$i][0] & " Songs - : - (Line = " & @ScriptLineNumber & ")") Next If WMGetState($oPlayer) = "Playing" Then $SongTitle = $oPlayer1.currentMedia.getItemInfobyAtom($oPlayer1.mediaCollection.getMediaAtom("Title")) $iIndex = _GUICtrlListView_FindText ($SongListView, $SongTitle) _GuiCtrlListView_SetItemSelected ($SongListView, $iIndex) _ConsoleWrite("Current Song Index " & $iIndex & " - : - (Line = " & @ScriptLineNumber & ")") EndIf $CloseSongList = GUICtrlCreateButton("Close", 10, 270,90, 30) $SelectSongList = GUICtrlCreateButton("Select", 120, 270,90, 30) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState () While 1 $msg11 = GuiGetMsg() Select Case $msg11 = $CloseSongList GUIDelete($GUISongList) ExitLoop Case $msg11 = $SelectSongList $iKeySelectSong = _ArraySearch2d( $aSource, _GUICtrlListView_GetItemText($SongListView, _GUICtrlListView_GetSelectionMark($SongListView)), 0, 0, -1, -1, 0, True) WMStop($oPlayer) WMLoadFile($oPlayer1,$aSource[$iKeySelectSong[0]][0]) GUIDelete($GUISongList) TitleView() ExitLoop EndSelect Wend EndFunc Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW If Not _GUICtrlListView_GetViewDetails($hWndFrom) Then Return $GUI_RUNDEFMSG Local $tCustDraw = DllStructCreate('hwnd hwndFrom;int idFrom;int code;' & _ 'dword DrawStage;hwnd hdc;long rect[4];dword ItemSpec;int ItemState;dword Itemlparam;' & _ 'dword clrText;dword clrTextBk;int SubItem;' & _ 'dword ItemType;dword clrFace;int IconEffect;int IconPhase;int PartID;int StateID;long rectText[4];int Align', _ ;winxp or later $lParam), $iDrawStage, $iItem, $iSubitem, $hDC, $tRect, $iColor1, $iColor2, $iColor3 $iDrawStage = DllStructGetData($tCustDraw, 'DrawStage') Switch $iDrawStage Case $CDDS_ITEMPREPAINT Return $CDRF_NOTIFYSUBITEMDRAW Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM) $iItem = DllStructGetData($tCustDraw, 'ItemSpec') $iSubitem = DllStructGetData($tCustDraw, 'SubItem') If _GUICtrlListView_GetItemSelected($hWndFrom, $iItem) Then $hDC = _WinAPI_GetDC($hWndFrom) $tRect = DllStructCreate('long;long;long;long') If $iSubitem = 0 Then DllCall('user32.dll','int','SendMessage', 'hwnd',$hWndFrom, 'uint',$LVM_GETSUBITEMRECT, 'wparam',$iItem, 'lparam',DllStructGetPtr($tRect)) DllStructSetData($tRect, 1, 2) DllCall('user32.dll', 'int', 'FillRect', 'ptr', $hDC, 'ptr', DllStructGetPtr($tRect), 'int', _WinAPI_GetStockObject(4)) EndIf DllStructSetData($tRect, 1, 2) DllStructSetData($tRect, 2, $iSubitem) DllCall('user32.dll','int','SendMessage', 'hwnd',$hWndFrom, 'uint',$LVM_GETSUBITEMRECT, 'wparam',$iItem, 'lparam',DllStructGetPtr($tRect)) Local $sText = _GUICtrlListView_GetItemText($hWndFrom, $iItem, $iSubitem) DLLCall("gdi32.dll","int","SetTextColor", "ptr", $hDC, "int", RGB2BGR(0xffff00)) DLLCall("gdi32.dll","int","SetBkMode", "ptr", $hDC, "int", 1) DLLCall("gdi32.dll","hwnd","SelectObject", "hwnd", $hDC, "hwnd", $aFont1[0]) DllStructSetData($tRect, 1, DllStructGetData($tRect, 1)+2) _WinAPI_DrawText($hDC, $sText, $tRect, 0x8000) ;; $DT_END_ELLIPSIS _WinAPI_ReleaseDC($hWndFrom, $hDC) Return $CDRF_SKIPDEFAULT EndIf Switch $iItem Case 0 To UBound($aSource) - 1 $iColor1 = RGB2BGR(0xcaff70) ;$iColor1 = RGB2BGR(0xFF0000) $iColor2 = RGB2BGR(-1) If Mod($iItem, 2) Then ;odd rows DllStructSetData($tCustDraw, 'clrTextBk', $iColor2) Else DllStructSetData($tCustDraw, 'clrTextBk', $iColor1) EndIf EndSwitch Return $CDRF_NEWFONT Case Else EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func RGB2BGR($iColor) Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF) EndFunc Also, not to look a gift horse in the mouth, this doesn't resolve the set cursor function...so if the item that I want to highlight isn't in view, it scrolls to where it is and brings it into view and highlights it. Or is that only possible in _GUICtrlListBox with "_GUICtrlListBox_SetCurSel"? Thanks. Edited March 12, 2008 by Champak Link to comment Share on other sites More sharing options...
Champak Posted March 12, 2008 Author Share Posted March 12, 2008 Fixed it...although I don't understand why it was happening. I got rid of your: For $i = 0 To UBound($aSource) - 1 _GUICtrlListView_AddItem($SongListView, StringReplace(Stringtrimleft($aSource[$i][0], StringInStr($aSource[$i][0], "\", 0, -1)),".mp3",""), $i-1) For $j = 1 To 2 _GUICtrlListView_AddSubItem ($SongListView, $i, $aSource[$i][1], $j) Next NextoÝ÷ ٩ݦë[iÉ&É«¢+Ø%¥´ÀÌØíM½¹1¥ÍÑ%ѵÍmU ½Õ¹ ÀÌØíM½ÕÉ¥ulÉt(%½ÈÀÌØíèôÀQ¼U ½Õ¹ ÀÌØíM½Õɤ´Ä($$($$ÀÌØíM½¹1¥ÍÑ%ѵÍlÀÌØíéulÁtôMÑÉ¥¹IÁ±¡MÑÉ¥¹ÑÉ¥µ±Ð ÀÌØíM½ÕÉlÀÌØíéulÁt°MÑÉ¥¹%¹MÑÈ ÀÌØíM½ÕÉlÀÌØíéulÁt°ÅÕ½ÐìÀäÈìÅÕ½Ðì°À°´Ä¤¤°ÅÕ½Ðì¹µÀÌÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì¤($$ÀÌØíM½¹1¥ÍÑ%ѵÍlÀÌØíéulÅtôÀÌØíM½ÕÉlÀÌØíéulÅt($$(%9áÐ(%}U% Ñɱ1¥ÍÑY¥Ý}ÉÉä ÀÌØíM½¹1¥ÍÑY¥Ü°ÀÌØíM½¹1¥ÍÑ%ÑµÌ But is this still possible: Also, not to look a gift horse in the mouth, this doesn't resolve the set cursor function...so if the item that I want to highlight isn't in view, it scrolls to where it is and brings it into view and highlights it. Or is that only possible in _GUICtrlListBox with "_GUICtrlListBox_SetCurSel"? Link to comment Share on other sites More sharing options...
DjDeep00 Posted March 12, 2008 Share Posted March 12, 2008 @Champak...After you find the item and get the index of the item..you can use _GuiCtrlListViewScroll() function to scroll to that index and then you can use _GuiCtrlListViewSetItemSelState() to highlight it.... Link to comment Share on other sites More sharing options...
Champak Posted March 12, 2008 Author Share Posted March 12, 2008 Thanks, all good now. _GUICtrlListView_Scroll($SongListView, 0, $iIndex * 25) For anyone else, just in case, The 25 is the height of each row, and allows the item to be at the top of the listview. 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