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

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


Changing CEdit color in DialogBar

Thomas Matelich -- matelich@pacsim.com
Wednesday, February 05, 1997

Environment: VC++ 4.2b, Win 95, NT 4.0

I have an edit control in a dialog bar and I want it to be read-only with a
white background.  I have tried handling WM_CTLCOLOR from the dialog bar and
my mainframe.  In both cases, CTLCOLOR_EDIT and CTLCOLOR_MSGBOX were not
sent to the class, only

I also tried deriving a class from CEdit, handling the message there, and
subclassing the control, WM_CTLCOLOR never made it there (although I may
have done it wrong).

Any help would be greatly appreciated

Thomas O Matelich
matelich@pacsim.com




George Pavlou -- georgep@MPGN.COM
Friday, February 07, 1997

You need to handle the CTLCOLOR_STATIC  !!

See my reply on same problem posted on 2/6/97 with subject:
Re: Problem with readonly CEdit on bitmapped Dialog

George

 |-------------------------------------------------------------------------|

   George Pavlou                       Tantalus, Inc.            
   PC Software Specialist            Key West, FL
   georgep@tansoft.com             www.mpgn.com 
 |-------------------------------------------------------------------------|


----------
> From: Thomas Matelich 
> To: mfc-l@netcom.com
> Subject: Changing CEdit color in DialogBar
> Date: Wednesday, February 05, 1997 2:06 PM
> 
> Environment: VC++ 4.2b, Win 95, NT 4.0
> 
> I have an edit control in a dialog bar and I want it to be read-only with
a
> white background.  I have tried handling WM_CTLCOLOR from the dialog bar
and
> my mainframe.  In both cases, CTLCOLOR_EDIT and CTLCOLOR_MSGBOX were not
> sent to the class, only
> 
> I also tried deriving a class from CEdit, handling the message there, and
> subclassing the control, WM_CTLCOLOR never made it there (although I may
> have done it wrong).
> 
> Any help would be greatly appreciated
> 
> Thomas O Matelich
> matelich@pacsim.com
> 



Josep -- JosepSA@Datanet.es
Wednesday, January 15, 1997

Environment: VC++ 4.2b, Win 95.

 You must not have any problem by handling WM_CTLCOLOR from dialog bar. S=
o
Try it again and search for an error in the process (may be you are in a
wrong class).

Here you are an example that works correctly.

first define a handle of your desired brush:

class CYourDialogBar
{
       //
      HBRUSH m_hYourDesiredBrush;	// desired brush
};

and initialize it:

CYourDialogBar()
{
    //	=09
    m_hYourDesiredBrush=3D(HBRUSH) GetStockObject(WHITE_BRUSH);
}

then handle WM_CTLCOLOR from CYourDialogBar:

HBRUSH CYourDialogBar::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)=20
{
    HBRUSH hbr;

    if(nCtlColor !=3D CTLCOLOR_EDIT) 	// Edit control ?????
        hbr=3Dm_hYourDesiredBrush;            // Yes !!!!!!!!

    else  				// all other=20
       hbr =3D CDialogBar::OnCtlColor(pDC, pWnd, nCtlColor);=20
	=09
    return hbr;
}

	If you need a complete example ask me for it.
    =20

Josep S=E0nchez Alba

JosepSA@datanet.es

----------
> From: Thomas Matelich 
> To: mfc-l@netcom.com
> Subject: Changing CEdit color in DialogBar
> Date: mi=E9rcoles 5 de febrero de 1997 20:06
>=20
> Environment: VC++ 4.2b, Win 95, NT 4.0
>=20
> I have an edit control in a dialog bar and I want it to be read-only wi=
th
a
> white background.  I have tried handling WM_CTLCOLOR from the dialog ba=
r
and
> my mainframe.  In both cases, CTLCOLOR_EDIT and CTLCOLOR_MSGBOX were no=
t
> sent to the class, only
>=20
> I also tried deriving a class from CEdit, handling the message there, a=
nd
> subclassing the control, WM_CTLCOLOR never made it there (although I ma=
y
> have done it wrong).
>=20
> Any help would be greatly appreciated
>=20
> Thomas O Matelich
> matelich@pacsim.com



Ho Pham -- hop@allensysgroup.com
Monday, February 10, 1997

I have CEdit controls on a CView and the best way to change the color
is to trap the =WM_CTLCOLOR (reflected message) event and change the color
there. You also need to a solid brush (::CreateSolidBrush() in the ctor) for your
CEdit then use it to pass back when CtlColor is called.
Notice the function is CtlColor() not OnCtlColor().

Here how I do it:

HBRUSH CEditText::CtlColor(CDC* pDC, UINT nCtlColor) 
{
	// TODO: Change any attributes of the DC here
	
	// TODO: Return a non-NULL brush if the parent's handler should not be called

	//pDC->SetBkColor (RGB (0x00, 0x00, 0xFF));
	pDC->SetTextColor (RGB(0xFF, 0x00, 0x00));

	return m_pBrush;
}

----------------------------------------------------
Ho Pham
hop@allensysgroup.com

-----------------------------------------------------------
George Pavlou wrote:
> 
> You need to handle the CTLCOLOR_STATIC  !!
> 
> See my reply on same problem posted on 2/6/97 with subject:
> Re: Problem with readonly CEdit on bitmapped Dialog
> 
> George
> 
>  |-------------------------------------------------------------------------|
> 
>    George Pavlou                       Tantalus, Inc.
>    PC Software Specialist            Key West, FL
>    georgep@tansoft.com             www.mpgn.com
>  |-------------------------------------------------------------------------|
> 
> ----------
> > From: Thomas Matelich 
> > To: mfc-l@netcom.com
> > Subject: Changing CEdit color in DialogBar
> > Date: Wednesday, February 05, 1997 2:06 PM
> >
> > Environment: VC++ 4.2b, Win 95, NT 4.0
> >
> > I have an edit control in a dialog bar and I want it to be read-only with
> a
> > white background.  I have tried handling WM_CTLCOLOR from the dialog bar
> and
> > my mainframe.  In both cases, CTLCOLOR_EDIT and CTLCOLOR_MSGBOX were not
> > sent to the class, only
> >
> > I also tried deriving a class from CEdit, handling the message there, and
> > subclassing the control, WM_CTLCOLOR never made it there (although I may
> > have done it wrong).
> >
> > Any help would be greatly appreciated
> >
> > Thomas O Matelich
> > matelich@pacsim.com
> >




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