Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Call of OnCreate in a CTreeCtrl derived class

Call of OnCreate in a CTreeCtrl derived class

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionlearning
11 Posts 4 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M madmax0001

    Hello, I have a problem regarding a CTreeCtrl derived class. I have added a message handler for WM_CREATE: int CMyTreeCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) I placed a CTreeCtrl item on the dialog in the resource aditor and afterwards I have change the class from CTreeCtrl to CMyTreeCtrl. This works. But the problem is, that the OnCreate member function is never called... What did I miss? Regards MM

    P Offline
    P Offline
    prasad_som
    wrote on last edited by
    #2

    Have you associated CMyTreeCtrl object with item placed on dialog in editor ?


    Prasad MS MVP -  VC++

    M 1 Reply Last reply
    0
    • P prasad_som

      Have you associated CMyTreeCtrl object with item placed on dialog in editor ?


      Prasad MS MVP -  VC++

      M Offline
      M Offline
      madmax0001
      wrote on last edited by
      #3

      Yes, I have done this in the header file: //{{AFX_DATA(CMyMgrDlg) enum { IDD = IDD_MY_MGR_DLG }; CMyTreeCtrl m_treeCtrl2; //}}AFX_DATA The object is created and I can call other functions I have added to CMyTreeCtrl. When I create the object manually without a dialog resource it works: m_treeCtrl2.Create(WS_CHILD|WS_VISIBLE|WS_BORDER|TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS|TVS_TRACKSELECT|TVS_SHOWSELALWAYS, rect, this, 1234); But I don't want to create all objects manually, I want to use the resource editor to do this.

      P 1 Reply Last reply
      0
      • M madmax0001

        Yes, I have done this in the header file: //{{AFX_DATA(CMyMgrDlg) enum { IDD = IDD_MY_MGR_DLG }; CMyTreeCtrl m_treeCtrl2; //}}AFX_DATA The object is created and I can call other functions I have added to CMyTreeCtrl. When I create the object manually without a dialog resource it works: m_treeCtrl2.Create(WS_CHILD|WS_VISIBLE|WS_BORDER|TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS|TVS_TRACKSELECT|TVS_SHOWSELALWAYS, rect, this, 1234); But I don't want to create all objects manually, I want to use the resource editor to do this.

        P Offline
        P Offline
        prasad_som
        wrote on last edited by
        #4

        When I said "assoicated", it means using DDX_ macro. You need to use dialog data exchange macros to associated dialong control with class variable.


        Prasad MS MVP -  VC++

        M 1 Reply Last reply
        0
        • P prasad_som

          When I said "assoicated", it means using DDX_ macro. You need to use dialog data exchange macros to associated dialong control with class variable.


          Prasad MS MVP -  VC++

          M Offline
          M Offline
          madmax0001
          wrote on last edited by
          #5

          Yes, I forgot to mention this. My code looks like this: void CMyMgrDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMyMgrDlg) DDX_Control(pDX, IDC_CHAIN_TREE, m_treeCtrl2); //}}AFX_DATA_MAP } I have edited nothing here. This code was generated automatically. Regards

          1 Reply Last reply
          0
          • M madmax0001

            Hello, I have a problem regarding a CTreeCtrl derived class. I have added a message handler for WM_CREATE: int CMyTreeCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) I placed a CTreeCtrl item on the dialog in the resource aditor and afterwards I have change the class from CTreeCtrl to CMyTreeCtrl. This works. But the problem is, that the OnCreate member function is never called... What did I miss? Regards MM

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #6

            This isn't going to work. The control in a dialog resource template is created before you get a chance to catch the WM_CREATE for the control, which ends up going to the default window procedure for the control class. DDX isn't going to help either, since the first DDX operation done is subclassing the control, which is done way after the control is created. You have two options AFAIK - 1) Create a custom window class which wraps the windows control window class.  This class needs to be registered with Windows.  The control on the dialog resource needs to be this type/class.  Then your window proc will get called for the control before you pass messages on to the control's window proc.  This would be window superclassing. 2) Create the control at runtime instead of letting Windows create it from the dialog template. Note that whatever you need to do in this WM_CREATE handler, you may be able to do in the dialog class' OnInitDialog(), which is easier than either of the options above. Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            M 1 Reply Last reply
            0
            • M Mark Salsbery

              This isn't going to work. The control in a dialog resource template is created before you get a chance to catch the WM_CREATE for the control, which ends up going to the default window procedure for the control class. DDX isn't going to help either, since the first DDX operation done is subclassing the control, which is done way after the control is created. You have two options AFAIK - 1) Create a custom window class which wraps the windows control window class.  This class needs to be registered with Windows.  The control on the dialog resource needs to be this type/class.  Then your window proc will get called for the control before you pass messages on to the control's window proc.  This would be window superclassing. 2) Create the control at runtime instead of letting Windows create it from the dialog template. Note that whatever you need to do in this WM_CREATE handler, you may be able to do in the dialog class' OnInitDialog(), which is easier than either of the options above. Mark

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              M Offline
              M Offline
              madmax0001
              wrote on last edited by
              #7

              Hello Mark, thank you very much for your help. I have now changed my class and now I do my initialization by calling a special function in my OnInitDialog. Regards

              J 1 Reply Last reply
              0
              • M madmax0001

                Hello Mark, thank you very much for your help. I have now changed my class and now I do my initialization by calling a special function in my OnInitDialog. Regards

                J Offline
                J Offline
                Julberto Danray
                wrote on last edited by
                #8

                madmax0001, There is yet a third option for you. You can override the virtual function PreSubclassWindow() in your CTreeCtrl-derived class. You can do you initialization there. Julberto

                M 1 Reply Last reply
                0
                • J Julberto Danray

                  madmax0001, There is yet a third option for you. You can override the virtual function PreSubclassWindow() in your CTreeCtrl-derived class. You can do you initialization there. Julberto

                  M Offline
                  M Offline
                  Mark Salsbery
                  wrote on last edited by
                  #9

                  Julberto Danray wrote:

                  PreSubclassWindow

                  That's cool if it works, but how does the the CWnd object get associated with the control before it is created? Mark

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                  J 1 Reply Last reply
                  0
                  • M Mark Salsbery

                    Julberto Danray wrote:

                    PreSubclassWindow

                    That's cool if it works, but how does the the CWnd object get associated with the control before it is created? Mark

                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                    J Offline
                    J Offline
                    Julberto Danray
                    wrote on last edited by
                    #10

                    I'm assuming the the control is being subclassed via SubclassDlgItem() or DDX_Control(). In either case PreSubClassWindow() will be called. This is a very convenient way to initialize your subclassed controls because it does not require any special treatment from the dialog that contains the control. Julberto

                    M 1 Reply Last reply
                    0
                    • J Julberto Danray

                      I'm assuming the the control is being subclassed via SubclassDlgItem() or DDX_Control(). In either case PreSubClassWindow() will be called. This is a very convenient way to initialize your subclassed controls because it does not require any special treatment from the dialog that contains the control. Julberto

                      M Offline
                      M Offline
                      Mark Salsbery
                      wrote on last edited by
                      #11

                      Right, but the OP is trying to catch WM_CREATE, which has occurred long before the first DDX_Control() call.  Mark

                      Mark Salsbery Microsoft MVP - Visual C++ :java:

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups