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

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


LimitText & SetBkColor

Uusitalo Kari -- u130557@cs.tut.fi
Tuesday, December 03, 1996


	Environment: VC++ 4.0, Win95, NT4.0

	Hello,

	I have a couple questions:

	- I need to change the background color of a CEdit object.
	When I use SetBkColor-method, only that portion of the
	background where are characters is changed. The rest of the
	background is still white. How can I change the background
	color of the whole control?

	- When using CComboBox objects, is there a way to define
	the EditBox part of the control to be as read-only? I know that
	there is the LimitText-method, but one can't define the limit to
	be zero.

	Thank you very much.

	Kari.
	email: u130557@cs.tut.fi



Mike Blaszczak -- mikeblas@nwlink.com
Thursday, December 05, 1996

[Mini-digest: 5 responses]

At 14:28 12/3/96 +0200, Uusitalo Kari wrote:
>	Environment: VC++ 4.0, Win95, NT4.0
>	I have a couple questions:

It's really easiest for everyone if you post only one question
(or, at least, only tightly related questions) in a single post.

>	- I need to change the background color of a CEdit object.
>	When I use SetBkColor-method, only that portion of the
>	background where are characters is changed. The rest of the
>	background is still white. How can I change the background
>	color of the whole control?

You need to paint the background of the control.  In your
OnCtlColor() handler, return a brush for the colour you want. 
This is very well documneted.

>	- When using CComboBox objects, is there a way to define
>	the EditBox part of the control to be as read-only? I know that
>	there is the LimitText-method, but one can't define the limit to
>	be zero.

In the resource editor, set the type of the box to a "Drop List" instead
of a "Dropdown".  That is, give your box the CBS_DROPDOWNLIST style
instead of the CBS_DROPDOWN style.

>	Thank you very much.

Your questions have nothing to do for MFC and aren't appropriate for this
mailing list. Your questions are trivially answered by examining the
documentation.  Please, please, take a moment to use the resources
avaialble to you, right in front of you, instead of sending mail to a
couple of thousand people to ask for help.

.B ekiM
http://www.nwlink.com/~mikeblas/
I'm afraid I've become some sort of speed freak.
These words are my own. I do not speak on behalf of Microsoft.

-----From: "Cunningham Graham, IK 23" 

>----------
>From: 	Uusitalo Kari[SMTP:u130557@cs.tut.fi]
>Sent: 	Dienstag, 3. Dezember 1996 13:28
>To: 	mfc-l@netcom.com
>Cc: 	u130557@cs.tut.fi
>Subject: 	LimitText & SetBkColor
>
>
>	Environment: VC++ 4.0, Win95, NT4.0
>
>	Hello,
>
>	I have a couple questions:
>
>	- I need to change the background color of a CEdit object.
>	When I use SetBkColor-method, only that portion of the
>	background where are characters is changed. The rest of the
>	background is still white. How can I change the background
>	color of the whole control?

>I use the CtlColor override to do this and it seems to work ok for me.
>
>//---------------------------------------------------------------------------
>HBRUSH CGridEdit::CtlColor(CDC* pDC, UINT nCtlColor) 
>//---------------------------------------------------------------------------
>{
>	pDC->SetBkColor(m_clrBkgnd);
>	pDC->SetTextColor(m_clrText);
>	return HBRUSH(m_brBkgnd);
>}
>
>	- When using CComboBox objects, is there a way to define
>	the EditBox part of the control to be as read-only? I know that
>	there is the LimitText-method, but one can't define the limit to
>	be zero.
I think you can do this by setting the style to be CBS_DROPDOWNLIST

>	Thank you very much.
>
>	Kari.
>	email: u130557@cs.tut.fi
>
-----From: joew@statsoft.com (Joe Willcoxson)

>
>	Environment: VC++ 4.0, Win95, NT4.0
>	- I need to change the background color of a CEdit object.
>	When I use SetBkColor-method, only that portion of the
>	background where are characters is changed. The rest of the
>	background is still white. How can I change the background
>	color of the whole control?

If you read the documentation, OnCtlColor needs to return an HBRUSH.  I
suggest you have a CBrush member object in the parent of the CEdit control.
Call CreateSolidBrush in the constructor of the parent.  Return that CBrush
during OnCtlColor for CTLCOLOR_EDIT and CTLCOLOR_MSGBOX, just like the
documentation says.

>	- When using CComboBox objects, is there a way to define
>	the EditBox part of the control to be as read-only? I know that
>	there is the LimitText-method, but one can't define the limit to
>	be zero.


You can get the handle of the edit by calling:

#define IDC_WINDOWS_COMBO_EDIT
CEdit* pEdit = (CEdit*)  pYourCombo->GetDlgItem(IDC_WINDOWS_COMBO_EDIT);

This is in the MFC FAQ!  Look for it at http://www.stingsoft.com
--
Joe Willcoxson (joew@statsoft.com), Senior Software Engineer
Visit us: http://www.statsoft.com, Visit me: http://users.aol.com/chinajoe
#define STD_DISCLAIMER "I speak only for myself"
"Lotteries are a tax on people who do not understand statistics."


-----From: David Little 

Try handling the WM_CTLCOLOR message, and return a brush in the selected =
color. On the combo-box, why don't you just "eat" the WM_CHAR messages?  =
You could do it in the PreTranslateMessage and not even have to =
subclass....

----------
From: 	Uusitalo Kari[SMTP:u130557@cs.tut.fi]
Sent: 	Tuesday, December 03, 1996 8:28 AM
To: 	MFC Mailing List
Cc: 	Uusitalo Kari
Subject: 	LimitText & SetBkColor


	Environment: VC++ 4.0, Win95, NT4.0

	Hello,

	I have a couple questions:

	- I need to change the background color of a CEdit object.
	When I use SetBkColor-method, only that portion of the
	background where are characters is changed. The rest of the
	background is still white. How can I change the background
	color of the whole control?

	- When using CComboBox objects, is there a way to define
	the EditBox part of the control to be as read-only? I know that
	there is the LimitText-method, but one can't define the limit to
	be zero.

	Thank you very much.

	Kari.
	email: u130557@cs.tut.fi

-----From: "P. Senthil" 

Uusitalo Kari wrote:
>     ---------------------------------------------------------------
> 
>         Environment: VC++ 4.0, Win95, NT4.0
> 
>         Hello,
> 
>         I have a couple questions:
> 
>         - I need to change the background color of a CEdit object.
>         When I use SetBkColor-method, only that portion of the
>         background where are characters is changed. The rest of the
>         background is still white. How can I change the background
>         color of the whole control?
> 
>         - When using CComboBox objects, is there a way to define
>         the EditBox part of the control to be as read-only? I know that
>         there is the LimitText-method, but one can't define the limit to
>         be zero.
> 
>         Thank you very much.
> 
>         Kari.
>         email: u130557@cs.tut.fi

If you want a read-only property in the combo box, then use a drop list
style.

P. Senthil

mail : senthilp@geocities.com
www  : www.geocities.com/SiliconValley/Heights/6504




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