15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Color List box

Richard Stott -- rstott@redshift.com
Thursday, February 13, 1997

Environment: Win95 VC++4.1


I have a dialogbar with three list boxes. I want each to have a
different background color. The following code (adapted from code that
works fine for a single list box) colors the closed boxes OK, but when
they open the background of the dropped down part is white.


In the dialog bar constructor:

	m_BlueComboBrush.CreateSolidBrush(RGB( 0, 255, 255 ));

	m_GreenComboBrush.CreateSolidBrush(RGB( 255, 255, 0 ));



In OnCtlColor:

	

		case CTLCOLOR_LISTBOX:

		case CTLCOLOR_EDIT:

		if( pWnd -> GetDlgCtrlID() == IDC_BOXONE )

		{

			pDC->SetBkColor(RGB( 0, 255, 255  ));

			pDC->SetTextColor(RGB(0, 0, 0));

			pDC -> SetBkMode( TRANSPARENT );

			return (HBRUSH)(m_BlueComboBrush.GetSafeHandle());

		}

		else if( pWnd -> GetDlgCtrlID() == IDC_BOXTWO )

		{

			pDC->SetBkColor(RGB( 255, 255, 0  ));

			pDC->SetTextColor(RGB(0, 0, 0));

			pDC -> SetBkMode( TRANSPARENT );

			return (HBRUSH)(m_GreenComboBrush.GetSafeHandle());

		}

To get color, I need to move the return statement below the conditional
blocks. Then, there is no way to differentiate between boxes. My guess
was that the open boxes are colored by a call to OnCtlColor that does
not include the box control ID, so that the conditional statements are
not being called. I tested this by adding

	else return (HBRUSH)(m_BlueComboBrush.GetSafeHandle());

to the conditional, and found that it is called when the combo box is
clicked on and does color it. I'm wondering why ID information is
unavailable for that call, and if there is some way around the problem?
Or do I need to take an entirely new approach and what it might be.


Thanks!


Dick Stott


	








Greg D. Tighe -- gdt@eng.aisinc.com
Monday, February 17, 1997

> Environment: Win95 VC++4.1
> 
> I have a dialogbar with three list boxes. I want each to have a
> different background color. 
...
> 		case CTLCOLOR_LISTBOX:
> 		case CTLCOLOR_EDIT:
> 		if( pWnd -> GetDlgCtrlID() == IDC_BOXONE )
> 		{
...
> 		}
> 		else if( pWnd -> GetDlgCtrlID() == IDC_BOXTWO )
> 		{
...
> 		}
> 
> To get color, I need to move the return statement below the conditional
> blocks. Then, there is no way to differentiate between boxes. 

Try calling this->GetDlgCtrlID() instead (of course, you can omit the 
"this->" if you like.)

The pWnd parameter is the window requesting the color, not 
(necessarily) the window which is processing the WM_CTLCOLOR message. 
 I wasn't sure this was the problem at first since you referred to 
your controls as "list boxes" at the top of your message, but when 
you later referred to them as "combo boxes" then your problem made 
more sense.

	-Greg Tighe
	Applied Intelligent Systems, Inc.
	Ann Arbor, MI
	gdt@aisinc.com




Become an MFC-L member | Вернуться в корень Архива |