I tried FillRect to fill the background color & text color of a listbox, but it didn't work. What do I do to set the background color of a listbox(Text color, too)? Please give example!
I tried FillRect to fill the background color & text color of a listbox, but it didn't work. What do I do to set the background color of a listbox(Text color, too)? Please give example!
Website(s): http://www16.brinkster.com/trifaze/
E-mail: [email protected]
---------------------------------
C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
DirectX Version: 9.0b
DX SDK: DirectX 8.1 SDK
Assuming your program is dialog base and you're using MFC, try this:
declare first 3 variable like these:
COLORREF m_crText;
COLORREF m_crBackground;
CBrush m_brush;
in your OnInitDialog function, code these:
m_crText = GetSysColor(COLOR_WINDOWTEXT);
m_crBackground = GetSysColor(COLOR_WINDOW);
m_brush.CreateSolidBrush (m_crBackground);
and assuming you have a button to change the text color and background color, code the click function as follows:
void CMyDialog::OnBackColor()
{
CColorDialog dlg;
if(dlg.Domodal() == IDOK)
{
m_crBackground = dlg.GetColor();
if(m_brush.Detach())
m_brush.DeleteObject();
m_brush.CreateSolidBrush(m_crBackground);
//example m_list is the object of your ListBox
m_list.Invalidate();
}
}
void CMyDialog::OnTextColor()
{
CColorDialog dlg;
if(dlg.Domodal() == IDOK)
{
m_crText = dlg.GetColor();
m_list.Invalidate();
}
}
and handle the WM_CTLCOLOR message as follows:
HBRUSH CMyDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if(nCtlColor == CTLCOLOR_LISTBOX) //CTLCOLOR_LISTBOX is define at WinUser.h
{
pDC->SetBkMode(TRANSPARENT); //experiment this if u want
pDC->SetTextColor(m_crText);
return (HBRUSH) m_brush.GetSafeHandle();
}
else
return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
}
Thats it, I hope it helps...
If they can, why can't I...
I use Dev-C++ 4.01. I don't use dialog boxes, either. I need code for a regular LISTBOX.
Website(s): http://www16.brinkster.com/trifaze/
E-mail: [email protected]
---------------------------------
C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
DirectX Version: 9.0b
DX SDK: DirectX 8.1 SDK
You can do it by trapping a WM_CTLCOLORLISTBOX message.
zen
And HOW might I "trap" the message?
Website(s): http://www16.brinkster.com/trifaze/
E-mail: [email protected]
---------------------------------
C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
DirectX Version: 9.0b
DX SDK: DirectX 8.1 SDK
All messages affecting your window will be sent to your wndproc. You can trap them or pass them on to the default wndproc. Whenever a window that contains a listbox as a child window is repainted it will be sent a WM_CTLCOLORLISTBOX message, you can then either deal with this message to alter the way in which some aspects of the listbox are drawn or let the default wndproc handle it, in which case you'll get the default behavior.
zen
Could you just give me an example? The listbox handle is listWin;
Website(s): http://www16.brinkster.com/trifaze/
E-mail: [email protected]
---------------------------------
C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
DirectX Version: 9.0b
DX SDK: DirectX 8.1 SDK
Perhaps you might learn something by trying it to work it out for yourself (or if you used a search engine you could probably find some examples that would help).
zen
Or use owner draw listbox's and the WM_DRAWITEM msg.
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill