none
mfc and IMPLEMENT_DYNAMIC RRS feed

  • Question

  • I have noticed that one way to inherit a class in mfc is to use IMPLEMENT_DYNAMIC.  

    Let's say,  

    IMPLEMENT_DYNAMIC(CMainDialog, CDialog).

    What if I also wanted to implement interface IDropTarget.  How can I specify this?

    Thanks in advance

    Monday, March 23, 2015 1:08 AM

Answers

  • I have noticed that one way to inherit a class in mfc is to use IMPLEMENT_DYNAMIC.  

    Let's say,  

    IMPLEMENT_DYNAMIC(CMainDialog, CDialog).

    What if I also wanted to implement interface IDropTarget.  How can I specify this?

    Thanks in advance

    IMPLEMENT_DYNAMIC is not a way to inherit classes in MFC, but rather a way to hook up the message map when you have created a derived MFC class using ordinary C++ inheritance.

    Are you talking about multiple inheritance (MI)? Although MI can be used in MFC, I believe that only one base class can be derived form CCmdTarget, and that must be the first class in the base class list.


    David Wilkinson | Visual C++ MVP

    • Marked as answer by Shu 2017 Wednesday, April 1, 2015 12:53 PM
    Tuesday, March 24, 2015 10:23 AM
  • Hi rgelfand,

    For implementing the IDropTarget interface you can use the syntax as like follows

    Syntax :

    class CDropTargetImpl : public IDropTarget

    Please use this article which explains how to implement IDropTarget

      Sample -

    Thanks,
    Bhash

    • Marked as answer by Shu 2017 Wednesday, April 1, 2015 12:53 PM
    Tuesday, March 24, 2015 11:29 AM

All replies

  • Hi rgelfand,

    I am moving your thread into the Visual C++Forum for dedicated support. Thanks for your understanding.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, March 24, 2015 5:23 AM
  • I have noticed that one way to inherit a class in mfc is to use IMPLEMENT_DYNAMIC.  

    Let's say,  

    IMPLEMENT_DYNAMIC(CMainDialog, CDialog).

    What if I also wanted to implement interface IDropTarget.  How can I specify this?

    Thanks in advance

    IMPLEMENT_DYNAMIC is not a way to inherit classes in MFC, but rather a way to hook up the message map when you have created a derived MFC class using ordinary C++ inheritance.

    Are you talking about multiple inheritance (MI)? Although MI can be used in MFC, I believe that only one base class can be derived form CCmdTarget, and that must be the first class in the base class list.


    David Wilkinson | Visual C++ MVP

    • Marked as answer by Shu 2017 Wednesday, April 1, 2015 12:53 PM
    Tuesday, March 24, 2015 10:23 AM
  • Hi rgelfand,

    For implementing the IDropTarget interface you can use the syntax as like follows

    Syntax :

    class CDropTargetImpl : public IDropTarget

    Please use this article which explains how to implement IDropTarget

      Sample -

    Thanks,
    Bhash

    • Marked as answer by Shu 2017 Wednesday, April 1, 2015 12:53 PM
    Tuesday, March 24, 2015 11:29 AM
  • Generates the C++ code necessary for a dynamic CObject-derived class with run-time access to the class name and position within the hierarchy.

    C++ by itself does not have a feature for dynamic runtime class information. But Microsoft solved this problem by providing a CRuntimeClass.

    This structure can be used for dynamic runtime class information.

    DECLARE_DYNAMIC and IMPLEMENT_DYNAMIC macros are used to deduct information of classes at runtime. The class must have driven from CObject to use this feature.

    The header file should use DECLARE_DYNAMIC macro inside the class for making it aware of CRuntimeClass structure.

    The source file (.cpp) should call IMPLEMENT_DYNAMIC(DerivedClass, RootClass) for using CRuntimeClass. It completes the basic formalities of runtime class information.

    for gathering more information I would like to visit these links which gives deep information and description about this topic.

    1. https://msdn.microsoft.com/en-us/library/es8sbsx5.aspx
    2. DECLARE_DYNAMIC
    3. Stack Overflow answers
    4. ucancode.net article



    Wednesday, December 13, 2017 7:58 AM