Click here to Skip to main content
12,301,983 members (58,168 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++ C Win32 MFC
Hi,
I have an edit control which takes input as text. But how to draw user defined shapes onto it.

Please help.
Posted 1-Nov-12 1:36am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Derive a custom control from a CEdit and then implement OnPaint

You'll get something like the following where you will use your paint dc for drawing shapes...

class CShapeEdit : public CEdit
{
    DECLARE_DYNAMIC(CShapeEdit)
 
public:
    CShapeEdit();
    virtual ~CShapeEdit();
 
protected:
    DECLARE_MESSAGE_MAP()
    afx_msg void OnPaint();
};
 
BEGIN_MESSAGE_MAP(CShapeEdit, CEdit)
    ON_WM_PAINT()
END_MESSAGE_MAP()
 
IMPLEMENT_DYNAMIC(CShapeEdit, CEdit)
 
CShapeEdit::CShapeEdit()
{
}
 
CShapeEdit::~CShapeEdit()
{
}
 
void CShapeEdit::OnPaint()
{
	CPaintDC dc(this); // device context for painting
	// TODO: Add your message handler code here
	// Do not call CEdit::OnPaint() for painting messages
}

Now in your dialog class, which hosts the custom edit control, you add a member variable

CShapeEdit m_ShapeEdit;

In the implementation of your dialog class bind it to the UI using DDX

DDX_Control(pDX, IDC_SHAPE_EDIT, m_ShapeEdit);

Then later on cause it to redraw itself with

m_ShapeEdit.RedrawWindow();

Now you have a canvas with which to explore the Win32 GDI!!!!
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

If it is enough to draw only on the some left and/or right parts of the control,
you could use CYourEdit::SetMargins(uiLeftUntouchedPixels, uiRightUntouchedPixels)
to prevent the CEdit-content painting there, even in the edit-caret mode.
Then you could also add(at or after the creating) the WS_CLIPCHILDREN style to CYourEdit control
and place some owner-drawn CYourShapeStatic child-control(s) onto the "freed" area(s) Smile | :)

Zerr0cool wrote:
I want to draw rectangles, circles in the Edit control where the user types in.

Try to set your control in the transparent mode as shown here[^]
and then to draw the shapes on the parent's surface, "behind" the control Smile | :)
  Permalink  
v3
Comments
Zerr0cool 1-Nov-12 9:25am
   
I want to draw rectangles, circles in the Edit control where the user types in.
JackDingler 1-Nov-12 13:52pm
   
Perhaps you want to create a custom font and apply that?
Zerr0cool 1-Nov-12 13:57pm
   
Its not about custom font. When a user enters a text say circle then I want to display circle and so on inside the edit control.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160530.1 | Last Updated 7 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100