Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » Changing background color of disabled editbox Collapse All
Subject Author Date
Suhai Gyorgy Oct 29, 2007 - 6:05 AM

Dear Support,

We’d like to use your CExtEdit class for one of our controls, which would be disabled. But the originally used disabled color seems to be a bit dark, so we’d like to lighten it. I see that this color is set in CExtEditBase::CtlColor. How could we achieve our requirement without copying any code from this method? I see that m_clrBackPrev variable holds the current background color, so I’ve tried this:

COLORREF CMyEdit::OnQueryBackColor() const
{ 
	COLORREF clrOrig = CExtEdit::OnQueryBackColor();
	if( clrOrig == COLORREF(-1L) && m_clrBackPrev != COLORREF(-1L) )
		clrOrig = RGB((GetRValue(m_clrBackPrev)+255)/2, (GetGValue(m_clrBackPrev)+255)/2, (GetBValue(m_clrBackPrev)+255)/2);
	return clrOrig;
}
But it doesn’t work good: as soon as I hover over the editbox, it turns white and stays like that forever.

The class needs to be reusable, so it should work exactly like your class except for the disabled background color. And we’d really like to avoid copying codes from your source, as that would require constant checkup with every upgrade.

Could you please point me to the right direction? Thank you!
Chris

Technical Support Oct 29, 2007 - 1:04 PM

Would you send us a screenshot that illustrates the issue?

Suhai Gyorgy Oct 30, 2007 - 3:04 AM

I’ve sent the screenshot in e-mail.

Technical Support Oct 29, 2007 - 10:28 AM

You can achieve this by overriding the OnQueryBackColor() method in this way

COLORREF OnQueryBackColor() const
{ 		
	COLORREF clrOrig = CExtEdit::OnQueryBackColor();
	
	if( clrOrig == COLORREF(-1L) )
	{
		bool bReadOnly = (GetStyle()&ES_READONLY) != 0 ? true : false;
		bool bDisabled = OnQueryWindowEnabledState() ? false : true;
		COLORREF clrSysBk =
			PmBridge_GetPM()->GetColor( 
				( bReadOnly || bDisabled ) 
					? COLOR_3DFACE 
					: COLOR_WINDOW,
				(CObject*)this 
				);
		clrOrig =
			RGB( 
				(GetRValue(clrSysBk) + 255) / 2, 
				(GetGValue(clrSysBk) + 255) / 2, 
				(GetBValue(clrSysBk) + 255) / 2
				);
	}
	return clrOrig;
	
}

Suhai Gyorgy Oct 29, 2007 - 10:43 AM

Using this code removes the white border which would appear when the editbox does not have the focus and the mouse does not hover over the control. How could I get that back? Thank you!