background color of CEdit control 
Author Message
 background color of CEdit control

I use Visual C++ 6.0.

I'm developing a design program. I have a class that rapresents a
rectangle. This class have a CEdit object called m_MyEdit.
How I can control the backgroung color of m_MyEdit?

The MFC help say that I must rewrite the virtual handler OnCtlColor,
but if I make a new Class CMyEdit, which was inherited from CEdit, and
I run the debug, I never go inside this OnCtlColor function.
Is the message pass to the base class CEdit and not to my class
CMyEdit?
Do I have to use SubClassDlgItem?

The help suggests to use SubClassDlgItem in OnCreate function of View
class. But this is the case in which I know how many items I attach to
this view, and it not is the my case. In fact the user can draws this
CMyEdit controls during the program running.

How I can risolve this problem?

And what about to create a CEdit control with a trasparent color (the
user can moves the object also over the Cedit control)?



Sun, 22 May 2005 22:36:36 GMT  
 background color of CEdit control

Quote:
> I use Visual C++ 6.0.

> I'm developing a design program. I have a class that rapresents a
> rectangle. This class have a CEdit object called m_MyEdit.
> How I can control the backgroung color of m_MyEdit?

Handle the WM_CTLCOLOR/CTLCOLOR_EDIT message.

Quote:
> The MFC help say that I must rewrite the virtual handler OnCtlColor,
> but if I make a new Class CMyEdit, which was inherited from CEdit, and
> I run the debug, I never go inside this OnCtlColor function.
> Is the message pass to the base class CEdit and not to my class
> CMyEdit?

You should use the ClassWizard to add a message handler for the
reflected (=WM_CTLCOLOR) message to your CMyEdit class. See the
following URL...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmf...

Quote:
> Do I have to use SubClassDlgItem?

You should use the ClassWizard to map a control member variable of your
CMyEdit class to the EDIT control if at all possible. But you can use
SubclassDlgItem.

Quote:
> The help suggests to use SubClassDlgItem in OnCreate function of View
> class. But this is the case in which I know how many items I attach to
> this view, and it not is the my case. In fact the user can draws this
> CMyEdit controls during the program running.

> How I can risolve this problem?

If you are creating them dynamically, you should call the Create or
CreateEx member function through an instantiated instance of a CMyEdit
class. In this case you do not need to SubclassDlgItem or map a control
member variable.

Quote:
> And what about to create a CEdit control with a trasparent color (the
> user can moves the object also over the Cedit control)?

No not really, although I did manage to implement a version that seems
to work beautifully on Win2000/XP, it does not work well on any of the
16-bit platforms, nor has it ever been used in production code.

--
Jeff Partch [VC++ MVP]



Sun, 22 May 2005 22:59:23 GMT  
 background color of CEdit control
Did you make sure the edit control is declared in your header file as a CMyEdit variable?
If not, it won't have any of its methods called. You don't need to use SubclassDlgItem
because that is automatically done for you when you create the variable.

If the user is creating them dyanmically, you have to create them as objects of type
CMyEdit, not CEdit, e.g.,

        CMyEdit * edit = new CMyEdit;
        edit->Create(...);
                                joe


Quote:
>I use Visual C++ 6.0.

>I'm developing a design program. I have a class that rapresents a
>rectangle. This class have a CEdit object called m_MyEdit.
>How I can control the backgroung color of m_MyEdit?

>The MFC help say that I must rewrite the virtual handler OnCtlColor,
>but if I make a new Class CMyEdit, which was inherited from CEdit, and
>I run the debug, I never go inside this OnCtlColor function.
>Is the message pass to the base class CEdit and not to my class
>CMyEdit?
>Do I have to use SubClassDlgItem?

>The help suggests to use SubClassDlgItem in OnCreate function of View
>class. But this is the case in which I know how many items I attach to
>this view, and it not is the my case. In fact the user can draws this
>CMyEdit controls during the program running.

>How I can risolve this problem?

>And what about to create a CEdit control with a trasparent color (the
>user can moves the object also over the Cedit control)?

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Mon, 23 May 2005 00:18:46 GMT  
 background color of CEdit control
I use your suggests and now all is ok. Now I can control the
background color of my CEdit control.

Quote:
> > And what about to create a CEdit control with a trasparent color (the
> > user can moves the object also over the Cedit control)?

> No not really, although I did manage to implement a version that seems
> to work beautifully on Win2000/XP, it does not work well on any of the
> 16-bit platforms, nor has it ever been used in production code.

But is not possible to use simply the following instructions:

 SetBkColor( TRANSPARENT );
 SetTextColor( RGB(0,0,0) );

I prove these but they don't work: the background color become dark
not transparent.

Is it depend by my incorrect use of these instructions or becouse is
not possible to do transparent CEdit object?



Mon, 23 May 2005 14:19:47 GMT  
 background color of CEdit control

Quote:
> But is not possible to use simply the following instructions:

>  SetBkColor( TRANSPARENT );
>  SetTextColor( RGB(0,0,0) );

> I prove these but they don't work: the background color become dark
> not transparent.

> Is it depend by my incorrect use of these instructions or becouse is
> not possible to do transparent CEdit object?

TRANSPARENT should not be used as a COLORREF, it is one of two mode
constants to be used in calls to SetBkMode. To my knowledge, there is no
reliable and straightforward way to implement a transparent CEdit

--
Jeff Partch [VC++ MVP]



Mon, 23 May 2005 14:33:57 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Background color in CEdit Control ?

2. How to change the background color of CEdit control?

3. Changing the default background color of disabled control (CEdit)

4. How to change background color of a dynamically created CEdit control

5. Change background color of disabled CEdit controls

6. Changing the Background Color of Individual CEdit controls in a CDialogBar

7. Colored background and text in a CEdit control

8. Changing color of background of a CEdit control

9. How do you set the background color of a CEdit control

10. set the text color and the background color of a Control Cbutton

11. Win2K: static background color vs. CFormView background color

12. Background & Text color CEdit

 

 
Powered by phpBB® Forum Software