I have started to learn some MFC and am trying to get to grips with the document/view architecture. In Jeff Prosise’s book, he gives examples of creating different types of views such as CEditViews etc. What I would like to do however is create a GUI like that of an MSN messenger chat window. So I want a couple of edit boxes and a push button. I can’t find any examples of how to create a view that combines a number of different types of controls. I have tried creating a standard document and view application (using the AppWizard), adding an edit box and a push button to the view object and then setting them up in the view’s OnCreate () function as follows:
Code:
class CEncryptedMessengerView : public CView
{
protected: // create from serialization only
CEncryptedMessengerView();
DECLARE_DYNCREATE(CEncryptedMessengerView)
// Attributes
public:
CEncryptedMessengerDoc* GetDocument();
CEdit InputBox;
CButton SendButton;
...............................
afx_msg int OnCreate (LPCREATESTRUCT lpCreateStruct);
DECLARE_MESSAGE_MAP()
};
That’s the relevant part of the view class. The OnCreate() function then looks like:
Code:
int CEncryptedMessengerView::OnCreate (LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate (lpCreateStruct))
return 0;
CRect edit_rect, rect;
GetClientRect(&edit_rect);
edit_rect.top = (edit_rect.Height () / 4) * 3;
edit_rect.right = (edit_rect.Width () / 4) * 3;
InputBox.Create(ES_AUTOHSCROLL, edit_rect, this, ID_ENTRY_WINDOW);
GetClientRect (&rect);
rect.top = (rect.Height () / 4) * 3;
rect.left = (rect.Width () / 4) * 3;
rect.DeflateRect (rect.Width () / 4, rect.Height () / 6);
SendButton.Create ("Send", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, rect, this, IDC_BUTTON);
return 1;
}
This doesn’t work. It compiles and runs ok but there is no sign of the controls.
Now this method might be entirely wrong and I may not understand the system correctly but I can’t find any examples or explanations of how to accomplish what I want.
Can anyone help me out with an explanation about this and maybe some example code please?
Thanks