CFormView Child of CDialog Causes Heap Corruption |
Post Reply |
Author | |
AZDavidPhx
Newbie Joined: 14 August 2010 Status: Offline Points: 3 |
Post Options
Thanks(0)
Posted: 14 August 2010 at 2:33pm |
Somewhat new to MFC development and stumped.
I am trying to embed a CFormView as a child window into the client area of a CDialog. My experiment is as follows (snippets / pseudo code) class ButtonButtonPanel : public CFormView private: CButton button1; CButton button2; class ButtonPanelDialog : public CDialog private: ButtonPanel panel; BOOL ButtonPanel::Create( CWnd* pParent ) { CRect rect ; pParent->GetClientRect( rect ) ; rect.bottom = 75 ; return CFormView::Create( NULL, NULL, WS_CHILD | WS_VISIBLE, rect, pParent, 0, NULL ) ; } BOOL ButtonPanelDialog::OnInitDialog( void ) { __super::OnInitDialog( ) ; buttonPanel.Create( this ) ; return TRUE ; } ; int main( ) { ButtonPanelDialog dialog ; dialog.DoModal( ) ; return 0 ; } Everything works. The call to DoModal pops up the dialog which contains the panel with the 2 buttons on it. When I close the dialog. It crashes saying the heap has been corrupted. Have no clue why. There is obviously something that I am not understanding. Would greatly appreciate it if someone could help me cure my ignorance. Thanks a lot. -David |
|
AZDavidPhx
Newbie Joined: 14 August 2010 Status: Offline Points: 3 |
Post Options
Thanks(0)
|
Here is the actual code:
// ConsoleApp.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "ConsoleApp.h" #include "Resource.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // The one and only application object CWinApp theApp; using namespace std; class ButtonPanel : public CFormView { public: ButtonPanel( void ) ; ~ButtonPanel( void ) ; virtual BOOL Create( CWnd* pParent ) ; protected: virtual void DoDataExchange( CDataExchange* pDX ) ; private: CButton button1 ; CButton button2 ; } ; ButtonPanel::ButtonPanel( void ) :CFormView( IDD_BUTTON_PANEL ) { } ; ButtonPanel::~ButtonPanel( void ) { } ; BOOL ButtonPanel::Create( CWnd* pParent ) { CRect rect ; pParent->GetClientRect( rect ) ; rect.bottom = 75 ; return CFormView::Create( NULL, NULL, WS_CHILD | WS_VISIBLE, rect, pParent, 0, NULL ) ; } void ButtonPanel::DoDataExchange( CDataExchange* pDX ) { __super::DoDataExchange( pDX ) ; DDX_Control( pDX, IDC_BUTTON1, button1 ) ; DDX_Control( pDX, IDC_BUTTON2, button2 ) ; } ; class ButtonPanelDialog : public CDialog { public: ButtonPanelDialog( void ) ; ~ButtonPanelDialog( void ) ; virtual BOOL OnInitDialog( void ) ; private: ButtonPanel buttonPanel ; } ; ButtonPanelDialog::ButtonPanelDialog( void ) : CDialog( IDD_DIALOG ), buttonPanel( ) { } ; ButtonPanelDialog::~ButtonPanelDialog( void ) { } ; BOOL ButtonPanelDialog::OnInitDialog( void ) { __super::OnInitDialog( ) ; buttonPanel.Create( this ) ; return TRUE ; } ; int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; // initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs _tprintf(_T("Fatal Error: MFC initialization failed\n")); nRetCode = 1; } else { ButtonPanelDialog dialog ; dialog.DoModal( ) ; } return nRetCode; } |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |