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

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


Setting text color in a CDC

David Lantsman -- davidlan@il.lucky.net
Sunday, December 08, 1996

Environment: Visual C++ 4.0 Windows 95

Hello,

I have an ownerdraw combo box and I want some of the stings to appear black
and some to be gray. How can I change the color of only *some* text in a
CDC - some words are black and some are gray - and not all the text as
SetTextColor does?

Goodbye,
	David Lantsman
--

===================================
Sent by David Lantsman
    mailto:davidlan@luckynet.co.il

Visit me at: http://www.luckynet.co.il/~davidlan
===================================




Mark Foley -- meftech@concentric.net
Tuesday, December 10, 1996

[Mini-digest: 3 responses]

David Lantsman wrote:
> 
> Environment: Visual C++ 4.0 Windows 95
> 
> Hello,
> 
> I have an ownerdraw combo box and I want some of the stings to appear black
> and some to be gray. How can I change the color of only *some* text in a
> CDC - some words are black and some are gray - and not all the text as
> SetTextColor does?
> 
> Goodbye,
>         David Lantsman
> --
> 
> ===================================
> Sent by David Lantsman
>     mailto:davidlan@luckynet.co.il
> 
> Visit me at: http://www.luckynet.co.il/~davidlan
> ===================================You must implement an owner draw combo box. If you are already doing this
then your DrawItem() must be supplied with a LPDRAWITEMSTRUCT lpDIS 
parameter that includes information that will allow you to identify and
subsequently color the appropriate text. I have done this with a listbox
where I wanted certqain text to be highlighted in red.
-----From: mathias.olausson@lig.linnedata.se (Mathias Olausson)

Derive a CWnd::OnDrawItem( ) function to handle the drawing (or a CComboBox::DrawItem() if
you have subclassed the combobox). Then use the info in the DRAWITEMSTRUCT to decide
which color you should set for a specific line. You might for instance store colorinfo in the
CComboBox by setting pMyCB->SetItemData( line, RGB(255,0,0) ); and this data will then
be available in OnDrawItem and DRAWITEMSTRUCT.itemData.

Hope this helps,
Mathias Olausson
mathias.olausson@lig.linnedata.se
-----From: Dicky Singh 

see comments embedded in your message below

----------
From: 	Jan Kodet
Sent: 	Monday, December 09, 1996 2:30 AM
To: 	mfc-l@netcom.com
Subject: 	Setting text color in a Dialog edit field

     Environment: Win95, VC++ 4.2b (have MSDN :)
     
     I would like to set the text colour for one (or several, for that 
     matter) edit field in my dialogue (subclassed from CDialog).

********
 If you want to change the color you could do it in WM_CTLCOLOR handler
e.g.
HBRUSH CEditColorDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	pDC->SetTextColor(RGB(255, 0, 0));
	// TODO: Return a different brush if the default is not desired
	return hbr;
}
********
     
     What I'm trying to accomplish is to edit several objects at the same 
     time. If one of the initial values for all objects was the same, the 
     text colour for this field would be standard black. If, however, a 
     values differed, I'd point this out by setting the text colour for this 
     edit field to e.g. grey (if you've seen it in other applications, you 
     know what I mean). 
are you referring to disabled edit controls?  If so use EnableWindow(FALSE);
     
     So far, I haven't managed to find out what to send to whom. Any ideas?
     
     Cheers,
     
     /JMK
     jan.kodet@eu.pnu.com

-Dicky Singh, Dicky@landmark.COM
Dragon Team Developer
8000 Towers Crescent Dr.  VA 22043




| Вернуться в корень Архива |