Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Listbox text color change


  • Please log in to reply
15 replies to this topic

#1 Jex

Jex

    Polymath

  • Active Members
  • PipPipPipPip
  • 206 posts

Posted 09 November 2007 - 05:48 PM

For my Messenger script i need change listbox items text colors. Example if user online i need change that item text color green. I'm searched forum but not found.

Posted Image







#2 Siao

Siao

    RTFM, foo!

  • Active Members
  • PipPipPipPipPipPip
  • 937 posts

Posted 09 November 2007 - 06:39 PM

I would suggest using ListView instead of ListBox, even if you don't need columns.
With $LVS_NOCOLUMNHEADER style and other minor tweaks there would be no visual difference.
This would allow you to easy change the text color of any listview item with GUICtrlSetColor.

If you insist on using ListBox, I think the only way would be ownerdrawing it.
You can start with this code. It wouldn't be hard to modify it, probably simply checking the online or whatever condition of the item in WM_DRAWITEM and setting the color with
DLLCall("gdi32.dll","int","SetTextColor", "hwnd", $hDC, "int", $iColor).

Edited by Siao, 09 November 2007 - 07:02 PM.

"be smart, drink your wine"

#3 Jex

Jex

    Polymath

  • Active Members
  • PipPipPipPip
  • 206 posts

Posted 09 November 2007 - 08:03 PM

Thanks for your help but if im use "DLLCall("gdi32.dll","int","SetTextColor", "hwnd", $hDC, "int", $iColor)" all listbox items text color changing and i don't know how to "simply?" checking the online and setting the color with dllcall <_< So i need use listview.

#4 Valuater

Valuater

    www.PayFreeWireless.com

  • MVPs
  • 11,200 posts

Posted 09 November 2007 - 08:29 PM

another approach

Posted Image


...XSkin is not required

Located here...


http://www.autoitscript.com/forum/index.ph...st&p=425262

8)

Posted Image

Clic The Pic!!!


#5 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,707 posts

Posted 09 November 2007 - 08:55 PM

More elegant would be use RichText control.

#6 Jex

Jex

    Polymath

  • Active Members
  • PipPipPipPip
  • 206 posts

Posted 09 November 2007 - 09:20 PM

I want if im double click nick in listbox or listview conversation window open. So i cant use editbox (http://www.autoitscript.com/forum/index.php?s=&showtopic=32494&view=findpost&p=425262 ) or RichText control. Now im changed my listbox codes to listview and i can use GUICtrlSetColor. Now i have another problem if im double click listview item how new gui will be open. ( I'm not searched yet double click thing because now im working on online/offline system in my messenger ) Thanks anyway <_<

#7 Jex

Jex

    Polymath

  • Active Members
  • PipPipPipPip
  • 206 posts

Posted 09 November 2007 - 09:36 PM

_GUICtrlListView_DeleteItem function have problem <_<

AutoIt         
#include <GUIConstants.au3> #include <GuiListView.au3> $Width = 170 $Height = 250 $Form = GUICreate("FLEXY", $Width, $Height, -1, -1, BitOR($WS_POPUP, $WS_BORDER)) $Close = GUICtrlCreateLabel("X", $Width - 15, 0, 11, 20) GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS") GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetCursor(-1, 0) $Formtitle = GUICtrlCreateLabel(" " & " (Online)", 0, 4, @DesktopWidth, 20, -1, $GUI_WS_EX_PARENTDRAG) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) $Formtitlebackground = GUICtrlCreateGraphic(0, 0, @DesktopWidth, 22) GUICtrlSetBkColor(-1, 0x000000) $List = GUICtrlCreateListView ( "col1", 0, 23, $Width, 215, $LVS_NOCOLUMNHEADER) $MenuItem = GUICtrlCreateMenu("Menu") $MenuItem1 = GUICtrlCreateMenuItem("Add user", $MenuItem) $MenuItem2 = GUICtrlCreateMenuItem("Delete user", $MenuItem) $MenuItem3 = GUICtrlCreateMenuItem("Save users", $MenuItem) $Separator1 = GUICtrlCreateMenuItem("", $MenuItem, 2) $MenuItem4 = GUICtrlCreateMenuItem("Exit", $MenuItem) GUISetState(@SW_SHOW, $Form) $Data = "!List||admin[]admin 3[]admin2[]flexy 123" If StringInStr($Data, "!List||") Then     $Friendlist = StringSplit($Data, "||", 1)     $Friendlist2 = StringSplit($Friendlist[2], "[]", 1)     ;$Onlinelist = StringSplit($Friendlist[4], "***", 1)     Dim $Listbox[UBound($Friendlist2) ]     For $i = 1 To UBound($Friendlist2) - 1         If $Friendlist2[$i] <> "" Then             GUICtrlCreateListViewItem ($Friendlist2[$i], $List)         EndIf     Next EndIf While 1     $msg = GUIGetMsg()     If $msg = $Close Then Exit     If $msg = $MenuItem2 Then         $Count = _GUICtrlListView_GetSelectedIndices ($List)         MsgBox("","",$Count)         _GUICtrlListView_DeleteItem ($List, $Count)         ;_GUICtrlListView_DeleteItem ($List, 2)  <-- If im write number working true..     EndIf WEnd


That not my real client just im crop for find what is wrong but i think that function have bug?

Edit: I'm solved my problem now working

Edit:

That working:
_GUICtrlListView_DeleteItem ($List, 2)

But that not work:
$Count = _GUICtrlListView_GetSelectedIndices ($List)
MsgBox("","",$Count)
_GUICtrlListView_DeleteItem ($List, 2)

Msgbox saying true count but already not delete item i can't understand what is wrong?

Edited by Jex, 09 November 2007 - 09:56 PM.


#8 Valuater

Valuater

    www.PayFreeWireless.com

  • MVPs
  • 11,200 posts

Posted 09 November 2007 - 09:59 PM

Try this

While 1   ;wait a sec... doesnt work


8)

Edited by Valuater, 09 November 2007 - 10:10 PM.

Posted Image

Clic The Pic!!!


#9 Jex

Jex

    Polymath

  • Active Members
  • PipPipPipPip
  • 206 posts

Posted 09 November 2007 - 10:03 PM

_GUICtrlListView_DeleteItem ($List,_GUICtrlListView_SetItemSelected ($List, 1))

Deleting index 1. Not selected item. :)

Edit :
_GUICtrlListView_DeleteItem ($List, _GUICtrlListView_GetItemSelected($List, 1))

Deleting first item. Not selected item... :P
I'm for that reason using listbox instead listview <_<

Edited by Jex, 09 November 2007 - 10:10 PM.


#10 Siao

Siao

    RTFM, foo!

  • Active Members
  • PipPipPipPipPipPip
  • 937 posts

Posted 09 November 2007 - 10:20 PM

I suggest you use handles instead of control IDs when working with these functions.

Other than that, you really need to read the manual. About return value of functions.
_GUICtrlListView_GetSelectedIndices returns string or array. When you pass string "2" to GuiCtrlSendMsg (that happens when you call _GUICtrlListView_DeleteItem with control ID of listview) it doesn't work. When you pass it to _SendMessage wrapper (that happens if you call _GUICtrlListView_DeleteItem with handle of listview), it works.

Edited by Siao, 09 November 2007 - 10:27 PM.

"be smart, drink your wine"

#11 Valuater

Valuater

    www.PayFreeWireless.com

  • MVPs
  • 11,200 posts

Posted 09 November 2007 - 10:27 PM

Got it....

AutoIt         
#include <GUIConstants.au3> #include <GuiListView.au3> #include <array.au3> $Width = 170 $Height = 250 $Form = GUICreate("FLEXY", $Width, $Height, -1, -1, BitOR($WS_POPUP, $WS_BORDER)) $MenuItem = GUICtrlCreateMenu("Menu") $MenuItem1 = GUICtrlCreateMenuItem("Add user", $MenuItem) $MenuItem2 = GUICtrlCreateMenuItem("Delete user", $MenuItem) $MenuItem3 = GUICtrlCreateMenuItem("Save users", $MenuItem) $Separator1 = GUICtrlCreateMenuItem("", $MenuItem, 2) $MenuItem4 = GUICtrlCreateMenuItem("Exit", $MenuItem) $Close = GUICtrlCreateLabel("X", $Width - 15, 0, 11, 20) GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS") GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetCursor(-1, 0) $Formtitle = GUICtrlCreateLabel(" " & " (Online)", 0, 4, @DesktopWidth, 20, -1, $GUI_WS_EX_PARENTDRAG) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) $Formtitlebackground = GUICtrlCreateGraphic(0, 0, @DesktopWidth, 22) GUICtrlSetBkColor(-1, 0x000000) $List = GUICtrlCreateListView("test", 0, 23, $Width, 215, $LVS_NOCOLUMNHEADER) _GUICtrlListView_InsertColumn ($List, 0, "Column 1", $Width - 10) GUISetState(@SW_SHOW, $Form) $Data = "!List||admin[]admin 3[]admin2[]flexy 123" If StringInStr($Data, "!List||") Then     $Friendlist = StringSplit($Data, "||", 1)     $Friendlist2 = StringSplit($Friendlist[2], "[]", 1)     ;$Onlinelist = StringSplit($Friendlist[4], "***", 1)     Dim $Listbox[UBound($Friendlist2) ]     For $i = 1 To UBound($Friendlist2) - 1         If $Friendlist2[$i] <> "" Then             _GUICtrlListView_AddItem ($List, $Friendlist2[$i], 0)         EndIf     Next EndIf While 1     $msg = GUIGetMsg()     If $msg = $Close Or $msg = $MenuItem4 Then Exit     If $msg = $MenuItem2 Then         $selected = _GUICtrlListView_GetSelectedIndices($List, 1)         If IsArray($selected) Then _GUICtrlListView_DeleteItem ($List,$selected[1])     EndIf WEnd


8)

EDIT: added error checking

If IsArray($selected) Then _GUICtrlListView_DeleteItem ($List,$selected[1])

Edited by Valuater, 09 November 2007 - 10:40 PM.

Posted Image

Clic The Pic!!!


#12 Jex

Jex

    Polymath

  • Active Members
  • PipPipPipPip
  • 206 posts

Posted 09 November 2007 - 10:43 PM

Very thanks Valuater <_<

#13 Valuater

Valuater

    www.PayFreeWireless.com

  • MVPs
  • 11,200 posts

Posted 09 November 2007 - 10:56 PM

Very thanks Valuater <_<


Welcome!!

8)

Posted Image

Clic The Pic!!!


#14 Jex

Jex

    Polymath

  • Active Members
  • PipPipPipPip
  • 206 posts

Posted 10 November 2007 - 12:32 AM

First i want sort listview later check user online or offline and later i want change color to red or green but my script dont work? ( By the way sorry for my bad English but i think at least understandable :"> )

AutoIt         
#include <GUIConstants.au3> #include <GuiListView.au3> #include <array.au3> $Width = 170 $Height = 250 $Form = GUICreate("FLEXY", $Width, $Height, -1, -1, BitOR($WS_POPUP, $WS_BORDER)) $MenuItem = GUICtrlCreateMenu("Menu") $MenuItem1 = GUICtrlCreateMenuItem("TEST!", $MenuItem) $MenuItem2 = GUICtrlCreateMenuItem("Delete user", $MenuItem) $MenuItem3 = GUICtrlCreateMenuItem("Save users", $MenuItem) $Separator1 = GUICtrlCreateMenuItem("", $MenuItem, 2) $MenuItem4 = GUICtrlCreateMenuItem("Exit", $MenuItem) $Close = GUICtrlCreateLabel("X", $Width - 15, 0, 11, 20) GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS") GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetCursor(-1, 0) $Formtitle = GUICtrlCreateLabel(" " & " (Online)", 0, 4, @DesktopWidth, 20, -1, $GUI_WS_EX_PARENTDRAG) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) $Formtitlebackground = GUICtrlCreateGraphic(0, 0, @DesktopWidth, 22) GUICtrlSetBkColor(-1, 0x000000) $List = GUICtrlCreateListView("test", 0, 23, $Width, 215, $LVS_NOCOLUMNHEADER) _GUICtrlListView_InsertColumn ($List, 0, "Column 1", $Width - 45) GUISetState(@SW_SHOW, $Form) $Data = "!List||flexy 123[]admin 3[]admin2[]admin" If StringInStr($Data, "!List||") Then     $Friendlist = StringSplit($Data, "||", 1)     $Friendlist2 = StringSplit($Friendlist[2], "[]", 1)     ;$Onlinelist = StringSplit($Friendlist[4], "***", 1)     Dim $Listbox[UBound($Friendlist2) ]     For $i = 1 To UBound($Friendlist2) - 1         If $Friendlist2[$i] <> "" Then             _GUICtrlListView_AddItem ($List, $Friendlist2[$i], 0)         EndIf     Next EndIf While 1     $msg = GUIGetMsg()     If $msg = $Close Or $msg = $MenuItem4 Then Exit     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|     If $msg = $MenuItem1 Then         Local $Index[_GUICtrlListView_GetItemCount($List) + 1]         Global $B_DESCENDING[_GUICtrlListView_GetColumnCount ($List)]         _GUICtrlListView_SimpleSort ($List, $B_DESCENDING, 0)         For $i = 1 To _GUICtrlListView_GetItemCount($List)             $Index[$i] = _GUICtrlListView_MapIndexToID($List, $i - 1)         Next         GUICtrlSetColor($Index[1], 0xFFFF00)         GUICtrlSetColor($Index[2], 0xFF0000)         GUICtrlSetColor($Index[3], 0x00FF00)         GUICtrlSetColor($Index[4], 0x0000FF)     EndIf     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;| WEnd


#15 Jex

Jex

    Polymath

  • Active Members
  • PipPipPipPip
  • 206 posts

Posted 12 November 2007 - 11:38 PM

Finally im managed change listview colors but now i can't add small images.

Posted Image

Like that :

Posted Image

My code imagelist create part :

$List = GUICtrlCreateListView("                                            ", 0, 23, $Width, 215, BitOR($LVS_SHOWSELALWAYS, $LVS_SINGLESEL, $LVS_NOCOLUMNHEADER)) $Image = _GUIImageList_Create () _GUIImageList_Add ($Image, _GUICtrlListView_CreateSolidBitMap (GUICtrlGetHandle($List), 0xFF0000, 10, 10)) _GUIImageList_Add ($Image, _GUICtrlListView_CreateSolidBitMap (GUICtrlGetHandle($List), 0x00FF00, 10, 10)) _GUIImageList_Add ($Image, _GUICtrlListView_CreateSolidBitMap (GUICtrlGetHandle($List), 0x0000FF, 10, 10)) _GUICtrlListView_SetImageList ($List, $Image, 1)

Edited by Jex, 12 November 2007 - 11:38 PM.


#16 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,707 posts

Posted 14 November 2007 - 12:23 AM

Finally im managed change listview colors but now i can't add small images.


Like that :


My code imagelist create part :

$List = GUICtrlCreateListView("                                            ", 0, 23, $Width, 215, BitOR($LVS_SHOWSELALWAYS, $LVS_SINGLESEL, $LVS_NOCOLUMNHEADER)) $Image = _GUIImageList_Create () _GUIImageList_Add ($Image, _GUICtrlListView_CreateSolidBitMap (GUICtrlGetHandle($List), 0xFF0000, 10, 10)) _GUIImageList_Add ($Image, _GUICtrlListView_CreateSolidBitMap (GUICtrlGetHandle($List), 0x00FF00, 10, 10)) _GUIImageList_Add ($Image, _GUICtrlListView_CreateSolidBitMap (GUICtrlGetHandle($List), 0x0000FF, 10, 10)) _GUICtrlListView_SetImageList ($List, $Image, 1)

What OS do you use?
There is bug in GUICtrlListView_CreateSolidBitMap() on WIN98.
I noticed some bug there but I didn't have much time to debug it more deeply yet.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users