Call of OnCreate in a CTreeCtrl derived class
-
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
-
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
Have you associated CMyTreeCtrl object with item placed on dialog in editor ?
Prasad MS MVP - VC++
-
Have you associated CMyTreeCtrl object with item placed on dialog in editor ?
Prasad MS MVP - VC++
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. -
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.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++
-
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++
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 -
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
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:
-
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:
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
-
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
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
-
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
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:
-
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:
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
-
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
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: