Thread: Document/View architecture help :: MFC

  1. #1
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    798

    Document/View architecture help :: MFC

    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

  2. #2
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    Your value for CRect.top is wrong. It is left and top and then bottom with right.

    So it is making your edit box 0 pixels wide.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MFC document/view woes
    By VirtualAce in forum Windows Programming
    Replies: 4
    Last Post: 03-15-2005, 07:54 AM
  2. Question about document/view app in MFC
    By hpy_gilmore8 in forum Windows Programming
    Replies: 2
    Last Post: 05-06-2004, 07:51 PM
  3. WIndows programming?
    By hostensteffa in forum Windows Programming
    Replies: 7
    Last Post: 06-07-2002, 08:52 PM
  4. Beginning MFC (Prosise) Part III - Now What? :: C++
    By kuphryn in forum C++ Programming
    Replies: 5
    Last Post: 03-03-2002, 06:58 PM
  5. MFC Document/View - New Milestone :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2002, 03:14 PM