CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2009
    Location
    Vietnam
    Posts
    15

    Create control class from CWnd-derived

    Hello,
    I am writting a class derived from CWnd. However, I do not find a good point to start. I think that the simplest case is using CWnd to write a CButton. Has anyone done it or Do you know any resources for this problem.
    Thank you very much!
    Best,

  2. #2
    Join Date
    Mar 2004
    Location
    KL, Malaysia
    Posts
    63

    Re: Create control class from CWnd-derived

    Quote Originally Posted by GBM25_11 View Post
    I am writting a class derived from CWnd. However, I do not find a good point to start. I think that the simplest case is using CWnd to write a CButton. Has anyone done it or Do you know any resources for this problem.
    Why not consider writing some not-yet-existing controls since MFC already has its own CButton class.

  3. #3
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Create control class from CWnd-derived

    Well, the problem is understanding Windows and than MFC. What you wrote is a contradiction:
    Use either CWnd oe CButton class to crete window you want.
    You cannot use CWnd class to create CButton object.

    CWnd class is used to create just about any window you want. You choose Window class from either: from Windows set of control classes or registering your own window class.
    You can use CWnd class to create button window but MFC variety of wrappers, has CButton class (derived from CWnd) you can use.

    If you want to use CWnd class to create button, pass button class name as parameter to CreateWindow or CreateWindowEx.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  4. #4
    Join Date
    Feb 2009
    Location
    Vietnam
    Posts
    15

    Re: Create control class from CWnd-derived

    Quote Originally Posted by JohnCz View Post
    Well, the problem is understanding Windows and than MFC. What you wrote is a contradiction:
    Use either CWnd oe CButton class to crete window you want.
    You cannot use CWnd class to create CButton object.

    CWnd class is used to create just about any window you want. You choose Window class from either: from Windows set of control classes or registering your own window class.
    You can use CWnd class to create button window but MFC variety of wrappers, has CButton class (derived from CWnd) you can use.

    If you want to use CWnd class to create button, pass button class name as parameter to CreateWindow or CreateWindowEx.
    Hello, I am sorry because using a wrong name. I used the word "CButton", which is not very appropriate. I mean deriving a class CMyButton from CWnd, which has almost all of the characteristics of CButton.
    Thank you for your comments.

  5. #5
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Create control class from CWnd-derived

    First thing to become a good programmer is learning how to translate your thoughts into terms everybody can understand; define common basic terms that can be used to carry a discussion knowing that we are talking about the same thing.
    Having said so: Why not to use CButton class as a base class for CMyButton?
    Is using CWnd as a base class for CMyButton an exercise?
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  6. #6
    Join Date
    Feb 2009
    Location
    Vietnam
    Posts
    15

    Re: Create control class from CWnd-derived

    Yes, I would like to study from the simplest project for a more complex application.
    Thank you for your care!

  7. #7
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Create control class from CWnd-derived

    I can appreciate this, but in order to do so, I would suggest some reading about Windows programming and MFC.
    Try creating Win32 application to get familiar with windows classes, main message loop, window procedure, windows messages and windows API.
    Than try MFC that wraps most of the windows APIs.

    I have attached sample project for starters.
    Attached Files Attached Files
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured