Re: Adding Edit Control to MainFrame.



"Saint Atique" <unix9n@xxxxxxxxx> wrote in message news:1db59444-17d4-4bc1-bc7a-1adcf3b75b9b@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm trying to add an Edit Control to MainFrame. I'm creating an
instance of CEdit in the paint message like this:

void SAFrame::OnPaint() {
CFrameWnd::OnPaint();

CEdit *PEdit = new CEdit;

PEdit->Create(ES_MULTILINE | WS_CHILD | WS_VISIBLE | WS_TABSTOP |
WS_BORDER,
CRect(10, 50, 150, 70), this, 0x1552);
}

But the control is not displayed. I think you have better ideas.


Don't call CFrameWnd::OnPaint() from within SAFrame::OnPaint(). It is not necessary and causes an error because EndPaint() is called before you have a chance to paint.

Move the code to create the edit control into SAFrame::OnCreate() which is called once, not every time the window is painted.

Rename PEdit to m_edit and make it a member of SAFrame. (Not a pointer, but a CEdit instance). Child windows like this are meant to have member instances and not pointers (due to the way the object is destroyed).

-- David

.



Relevant Pages

  • Re: Adding Edit Control to MainFrame.
    ... void SAFrame::OnPaint{ ... CEdit *PEdit = new CEdit; ... if this is a document/view app you will not see the edit control because the client area of the CMainframe is always hidden behind the view window. ...
    (microsoft.public.vc.mfc)
  • CEdit and ugly border
    ... void MyDialog::OnInitialUpdate ... CEdit* pEdit = new CEdit; ... The control is created, but it has an ugly black border. ...
    (microsoft.public.vc.mfc)
  • Custom CEdit Text Control
    ... This is the custom class .h file which inherits from CEdit. ... This is the custom class cpp file which inherits from CEdit. ... // Set the custom control member variables. ... //return the brush used for background this sets control background ...
    (microsoft.public.vc.mfc)
  • Re: Custom CEdit Text Control
    ... CEdit control. ... This is the custom class .h file which inherits from CEdit. ... You do not create the brush here. ... The purpose of a constructor is to initialize everything that needs to be initialized. ...
    (microsoft.public.vc.mfc)
  • Re: MFC Dialog + CEdit question
    ... I found that it works a lot better to use a CListBox as the logging window for error ... (on the whole, I've come to the conclusion that CEdit is a very, very poor choice for this ... I post a user-defined message from the error log control to the CMainFrame; ... >_thought_ I had to subclass it to get the mouse click .. ...
    (microsoft.public.vc.mfc)