Subdialogaufruf kackt ab, weiss net warum
-
OnInitDialog von B wird nicht mehr aufgerufen, weil es ihn bereits VOR dem DoModal weghängt.
Bei von mir o.a. Lösung gibst du bei Erstellen von Dialog B einen Zeiger auf A mit. Dann hast du von B über GetParent() Zugriff auf A und kannst im OnInitDialog dein Control füllen und ANSCHLIESSEND anzeigen.
-
ich habe folgendes herausgefunden:
ich habe den bereits geposteten code von BOOL B::OnInitDialog()
wie folgt erweiter:BOOL CScopeSelectDlg::OnInitDialog(){ CDialog::OnInitDialog(); MessageBox("1","",MB_OK); m_Tree.Create( WS_VISIBLE | WS_TABSTOP | WS_CHILD | WS_BORDER | TVS_HASBUTTONS | TVS_HASLINES | TVS_DISABLEDRAGDROP, CRect(10, 10, 300, 100), this, IDC_WATREE); MessageBox("2","",MB_OK); m_TreeImg.Create(IDB_BITMAP, 16, 2, RGB (255, 255, 255)); MessageBox("3","",MB_OK); m_Tree.SetImageList(&m_TreeImg, TVSIL_NORMAL); MessageBox("4","",MB_OK); return TRUE; }Ich weiss das sind nicht gerade die besten debug-vorgehen :)) aber eine weiter hilfreiche info waere vielleicht, dass ich nur die MessageBox "1" des obigen Aufrufs zu sehen bekomme. D.h. das mit dem m_Tree.Create(...) kackt ab.
woran kann das liegen?
grussle
-
Ist m_Tree vielleicht NULL ?
Hast du das da:
void B::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(B) DDX_Control(pDX, IDC_IDC_WATREE, m_Tree); //}}AFX_DATA_MAP }und ein Control auf deinem Dialog damit verbunden (mit Resourceneditor gemacht)
dann kannst du dir das Create sparen
-
So, ich hab dir ein Beispiel gebastelt, was bei wunderbar funzt.
//******************************************************************* // A Dialog Headerfile //******************************************************************* #ifndef _A_H_ #define _A_H_ //******************************************************************* //******************************************************************* class A : public CDialog { public: A(CWnd* pParent = NULL); CString m_strHomer; CString m_strMarge; CString m_strBart; CString m_strLisa; CString m_strMaggie; enum { IDD = IDD_DLG_DIALOG }; protected: afx_msg void OnButton1(); DECLARE_MESSAGE_MAP() }; //******************************************************************* #endif //******************************************************************* //******************************************************************* //*******************************************************************//******************************************************************* // A Dialog cppfile //******************************************************************* #include "stdafx.h" #include "B.h" #include "A.h" //******************************************************************* // konstruktor //******************************************************************* A::A(CWnd* pParent) CDialog(A::IDD, pParent) { m_strHomer ="Homer"; m_strMarge ="Marge"; m_strBart ="Bart"; m_strLisa ="Lisa"; m_strMaggie="Maggie"; } //******************************************************************* // messagemap //******************************************************************* BEGIN_MESSAGE_MAP(A, CDialog) ON_BN_CLICKED(IDC_BUTTON1, OnButton1) END_MESSAGE_MAP() //******************************************************************* // button gedrückt //******************************************************************* void A::OnButton1() { B dlg; dlg.DoModal(); } //******************************************************************* //******************************************************************* //*******************************************************************//******************************************************************* // B Dialog Header file //******************************************************************* #ifndef _B_H_ #define _B_H_ //******************************************************************* //******************************************************************* class B : public CDialog { public: CTreeCtrl m_Tree; B(CWnd* pParent = NULL); enum { IDD = IDD_DIALOG1 }; protected: virtual void DoDataExchange(CDataExchange* pDX); afx_msg void OnButton1(); virtual BOOL OnInitDialog(); }; //******************************************************************* #endif //******************************************************************* //******************************************************************* //*******************************************************************//******************************************************************* // B - Dialog cpp file //******************************************************************* #include "stdafx.h" #include "A.h" #include "B.h" //******************************************************************* // konstruktor //******************************************************************* B::B(CWnd* pParent) : CDialog(B::IDD, pParent) { } //******************************************************************* // ddx //******************************************************************* void B::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_TREE1, m_Tree); } //******************************************************************* // initialisiert den dialog //******************************************************************* BOOL B::OnInitDialog() { CDialog::OnInitDialog(); m_Tree.InsertItem(((A*)GetParent())->m_strHomer, NULL,TVI_LAST); m_Tree.InsertItem(((A*)GetParent())->m_strMarge, NULL,TVI_LAST); m_Tree.InsertItem(((A*)GetParent())->m_strBart, NULL,TVI_LAST); m_Tree.InsertItem(((A*)GetParent())->m_strLisa, NULL,TVI_LAST); m_Tree.InsertItem(((A*)GetParent())->m_strMaggie,NULL,TVI_LAST); return TRUE; } //******************************************************************* //******************************************************************* //*******************************************************************
-
vielen vieleeen dank :))
ich habe wie von euch vorgeschlagen das fuellen des CTreeCtrl Elements in die OnInitDialog von Klasse B verschoben. Das Create kann ich mir in der Tat sparen, da ich das Tree-Element mit Ressourcen-Editor erstellt hatte (Warum ein zweites Create dann gleich abkackt ist mir nicht ganz geheuer).
Nun funzt alles wunderbar.
Ich danke allen vielmals

grussle