|
-
Oct 15th, 2002, 05:36 PM
#1
Thread Starter
Fanatic Member
Need some help with edit boxes
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?
Last edited by Graff; Oct 17th, 2002 at 02:27 PM.
If wishes were fishes we'd all cast nets.
-
Oct 15th, 2002, 05:43 PM
#2
Monday Morning Lunatic
Operating System? Windowing method?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 15th, 2002, 08:57 PM
#3
Thread Starter
Fanatic Member
Erm sorry,
Win XP (but I want it to work with 98+)
VC++ MFC
If wishes were fishes we'd all cast nets.
-
Oct 16th, 2002, 08:46 AM
#4
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 16th, 2002, 09:46 AM
#5
Thread Starter
Fanatic Member
If wishes were fishes we'd all cast nets.
-
Oct 17th, 2002, 02:35 PM
#6
Thread Starter
Fanatic Member
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.
Code:
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;
}
If wishes were fishes we'd all cast nets.
-
Oct 17th, 2002, 03:16 PM
#7
What do you mean by "only where the cursor is"?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 17th, 2002, 03:53 PM
#8
Thread Starter
Fanatic Member
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
If wishes were fishes we'd all cast nets.
-
Oct 17th, 2002, 04:30 PM
#9
Seems like you have catch the EN_CHANGE of the edit box too and force it to redraw (Invalidate())
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|