PDA

Click to See Complete Forum and Search --> : Need some help with edit boxes


Graff
Oct 15th, 2002, 05:36 PM
On my program I have 24 edit boxes, I want them to change color depending on characters near the beginning of the sentance

ie. if the use types
/hello
it will turn green
//hello
it will turn yellow

Each textbox needs to exibhit this behaviour individually (like one can have /hello and it's green while the other has //hello and it's yellow).

Any suggestions on the best way to go about doing this?

parksie
Oct 15th, 2002, 05:43 PM
Operating System? Windowing method?

Graff
Oct 15th, 2002, 08:57 PM
Erm sorry,

Win XP (but I want it to work with 98+)
VC++ MFC

CornedBee
Oct 16th, 2002, 08:46 AM
Catch the WM_CTLCOLOREDIT message. Use the HWND supplied to get the text of the edit control. Parse it. Use the HDC supplied to set the text color depending on the outcome of your parse.
Works individually for every edit box. Works for every 9x or NT3.1+ WinOS.

Graff
Oct 16th, 2002, 09:46 AM
Thanks

Graff
Oct 17th, 2002, 02:35 PM
Ok new problem, I've done what you suggested however it will only repaint where the cursor currently is rather than the whole text. Here's my code it it will help.

HBRUSH CIMacV3Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr;
//CString strMacro, strType;
//int iID;
CString strMacro, strType;
UpdateData(TRUE);
switch (nCtlColor)
{
case CTLCOLOR_EDIT:
case CTLCOLOR_MSGBOX:
switch (pWnd->GetDlgCtrlID())
{

case IDC_EDIT1:
strMacro = m_strLine1; //strLine1 is the member variable of the edit box
pDC->SetBkColor(m_crBlackColor); // change the background color

if(strMacro.GetLength() >= 2)
{
strType = strMacro.Mid(0,1);
if(strType.Find('/') != -1)
{
strType = strMacro.Mid(0,2);
if(strType.Find("//") != -1)
pDC->SetTextColor(m_crYellow); // "//" text
else
pDC->SetTextColor(m_crGreen); // "/" text
}
else
pDC->SetTextColor(m_crCyan); // default text color
}
else
pDC->SetTextColor(m_crCyan);


hbr = (HBRUSH) m_cbBlackBrush; // apply the brush
break;

// otherwise do default handling of OnCtlColor
default:

hbr=CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
break;
}
break;

// otherwise do default handling of OnCtlColor
default:
hbr=CDialog::OnCtlColor(pDC,pWnd,nCtlColor);
}

return hbr;
}

CornedBee
Oct 17th, 2002, 03:16 PM
What do you mean by "only where the cursor is"?

Graff
Oct 17th, 2002, 03:53 PM
say I type / the slash will turn green then I type another / from there on the message is yellow HOWEVER the first / is still green

CornedBee
Oct 17th, 2002, 04:30 PM
Seems like you have catch the EN_CHANGE of the edit box too and force it to redraw (Invalidate())