Click here to Skip to main content
Rate this: bad
good
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 at 1-Nov-12 9:25am
   
I want to draw rectangles, circles in the Edit control where the user types in.
JackDingler at 1-Nov-12 13:52pm
   
Perhaps you want to create a custom font and apply that?
Zerr0cool at 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
0 Maciej Los 404
1 OriginalGriff 379
2 CPallini 145
3 Sergey Alexandrovich Kryukov 142
4 Hard_Rockz 115
0 OriginalGriff 5,634
1 Sergey Alexandrovich Kryukov 4,763
2 Peter Leow 2,954
3 Maciej Los 2,614
4 DamithSL 2,465


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