Jump to content

Listbox text color change


Jex
 Share

Recommended Posts

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

"be smart, drink your wine"

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 <_<

Link to comment
Share on other sites

_GUICtrlListView_DeleteItem function have problem <_<

#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
Link to comment
Share on other sites

_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
Link to comment
Share on other sites

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

"be smart, drink your wine"

Link to comment
Share on other sites

Got it....

#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

NEWHeader1.png

Link to comment
Share on other sites

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 :"> )

#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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...