Results 1 to 9 of 9

Thread: Need some help with edit boxes

  1. #1

    Thread Starter
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668

    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.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  3. #3

    Thread Starter
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668
    Erm sorry,

    Win XP (but I want it to work with 98+)
    VC++ MFC
    If wishes were fishes we'd all cast nets.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  5. #5

    Thread Starter
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668
    Thanks
    If wishes were fishes we'd all cast nets.

  6. #6

    Thread Starter
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668
    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.

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  8. #8

    Thread Starter
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668
    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.

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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
  •  



Click Here to Expand Forum to Full Width