dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Understanding a paragraph from an article

  1. #1
    Join Date
    Aug 2006
    Posts
    515

    Understanding a paragraph from an article

    I am reading this article http://www.microsoft.com/msj/0699/c/c0699.aspx
    and come across the follwing: (please search a small string to find it).
    Quote Originally Posted by Paul DiLascia
    If you start from scratch, you create your window by calling CWnd::Create or some overloaded version, such as CView::Create or CButton::Create. Or—as in the case of views—MFC calls Create for you. In all these cases, control eventually arrives at CWnd::CreateEx.
    It is confusing to me. Does the authors means even if call CButton::Create(), eventually CWnd::CreateEx() will be called a result? But I thought it is overloaded so the base class doesn't get called!?

    Does the base calls CWnd::Create() or CWnd::CreateEx() get called if I created a button or list which have its own Create() or CreateEx() function?

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,559

    Re: Understanding a paragraph from an article

    An overridden or overloaded function in a derived class can still call the base class implementation of that function.

  3. #3
    Join Date
    Aug 2006
    Posts
    515

    Re: Understanding a paragraph from an article

    Quote Originally Posted by GCDEF View Post
    An overridden or overloaded function in a derived class can still call the base class implementation of that function.
    Right which usually is the case with message handlers but many times we override a function for sole reason not to call the base class function so to modify it. Irrespectively I think in the case of Create() function, it doesn't add up if we Create window in say CButton class and than call a base class to Create the same window again!?

  4. #4
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,574

    Re: Understanding a paragraph from an article

    Quote Originally Posted by zspirit View Post
    but many times we override a function for sole reason not to call the base class function so to modify it.
    That's true in some cases but not true in all cases. Sometimes you override a base class function for the purpose of adding some functionality. In other words, doing whatever the base class does, then doing something extra that's needed in the derived class but isn't needed in the base class. There are no hard and fast rules (except for constructors).

    To be honest it doesn't matter whether a button's Create() function calls CWnd's Create() function or not. All that matters is that the button's Create() function will create a valid button. If it needs to call Create() in the base class it will do so - but that shouldn't be of any consequence as far as your use of CButton is concerned. It isn't something you need to worry about.
    "A problem well stated is a problem half solved. - Charles F. Kettering

  5. #5
    Join Date
    Aug 2006
    Posts
    515

    Re: Understanding a paragraph from an article

    Quote Originally Posted by John E View Post
    To be honest it doesn't matter whether a button's Create() function calls CWnd's Create() function or not. All that matters is that the button's Create() function will create a valid button. If it needs to call Create() in the base class it will do so - but that shouldn't be of any consequence as far as your use of CButton is concerned. It isn't something you need to worry about.
    I am creating a light weight GUI library which wrap up win32 style APIs so wanted to look at how it works. But the code inside CButton explains it. Thanks.
    Code:
    BOOL CButton::Create(LPCTSTR lpszCaption, DWORD dwStyle,
            const RECT& rect, CWnd* pParentWnd, UINT nID)
    {
        CWnd* pWnd = this;
        return pWnd->Create(_T("BUTTON"), lpszCaption, dwStyle, rect, pParentWnd, nID);
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)