
How to change the background color of an edit box
Jim,
I was hoping you would have a comment. When I originally built
that activex control I created a white, black, red, green and
blue CBrush in the constructor and then deleted them in the
destructor. This was fine except that I did not want to be
restricted to those colors. Now I can set my brushcolor property
(OLE_COLOR) to 0xff0000 or whatever and get any color. I agree
that it is not a good idea to keep creating HBRUSH's over and
over. But I'm still looking for the documentation to find out
exactly why or at least find a problem with it. For example,
what happens to the HBRUSH when the OnOcmCtlColorEdit function
is exited? Do the HBRUSH's stay in memory and eventually cause
the computer to lock up? I was hoping the HBRUSH's would just go
away when the function exits. Maybe I could try deleting the
HBRUSH after it is attached to the CBrush. So far I haven't
noticed any bad effects.
However, there are bigger problems with my activex control. I
use the COleControl function RecreateControlWindow( ) to call
PreCreateWindow() so that I can change the text alignment
in the edit box:
BOOL CTextboxCtrl::PreCreateWindow(CREATESTRUCT& cs)
{
cs.lpszClass = _T("EDIT");
if ((m_WindowStyle >= 0) && (m_WindowStyle <= 2 ))
{
switch (m_WindowStyle)
{
case 0:
cs.style |= ES_LEFT | WS_TABSTOP | ES_AUTOHSCROLL;
break;
case 1:
cs.style |= ES_RIGHT | WS_TABSTOP | ES_AUTOHSCROLL;
break;
case 2:
cs.style |= ES_CENTER | WS_TABSTOP | ES_AUTOHSCROLL;
break;
default:
cs.style |= ES_LEFT | WS_TABSTOP | ES_AUTOHSCROLL;
}
}
else
AfxMessageBox("'TextAlign' valid selections are:\n0 Left Aligned\n1 Right Aligned\n2 Center Aligned");
if (m_Disable == 1)
cs.style |= WS_DISABLED;
else if (m_Disable == 0)
{}
else
AfxMessageBox("'Disable' valid selections are:\n0 Disabled\n1 Enabled");
return COleControl::PreCreateWindow(cs);
Quote:
}
This works fine in Windows NT. In Windows 95 this code has no
effect on the edit box and niether does the code for changing
the background color. Do you have any idea what's going on here?
I am using this edit control in an HTML page. Originally I used
the textbox contained in FM20.DLL but then I found out the dll
is not redistributable so I decided to make my own control. The
big picture here is that I designed a form using html and am
displaying it in a dialog based container application with a
webbrowser control. Communication between the container and the
html page is done with COM via an invisible activex control in
the html page and by programming the DOM. And another thing,
FM20.DLL was distributed with IE3 but is not being distributed
with IE4.
Thanks,
Joe.
Quote:
>> LRESULT CTextboxCtrl::OnOcmCtlColorEdit(WPARAM wParam, LPARAM lParam)
>> {
>> HBRUSH hNewBrush = ::CreateSolidBrush(TranslateColor (m_BrushColorIndex, NULL));
>> m_WhiteBrush.Attach(hNewBrush);
>> ::SetBkColor((HDC)wParam, TranslateColor (m_BrushColorIndex, NULL));
>> ::SelectObject((HDC)wParam, (HBRUSH)m_WhiteBrush);
>> ::SetTextColor((HDC)wParam, TranslateColor (m_TextColorIndex, NULL));
>> return 0;
>> }
>Joe,
>Have you had any problems with this control? The way the code is, you'll be
>creating a new brush every time the function is called, which can be a bunch
>of times. I've always made the brush a member of the class and initialized it
>when the control is created, then just return the class member each time.
>Jim [VC/MFC MVP]
>To send mail, change spam-me-not to msn
-----------------** -- Posted from CodeGuru -- **-----------------
http://www.codeguru.com/ The website for Visual C++ programmers.