Home > Software engineering >  After adding DataTimePicker MFC controls, compiled by running errors, but "exe UnHandled except
After adding DataTimePicker MFC controls, compiled by running errors, but "exe UnHandled except

Time:10-06

description
I use MFC AppWizard to create an SDI application test, did not check the ActiveX control, the other for the default Settings, and then add member variables to CTestView class cstrings m_strName, CTestDialog create dialog box class, and use the wizard to add a member variable CTime m_dataTime (to be automatic add (DDX),
After CTestView: : ontouch * pDC (CDC) created in DLG CTestDialog object, using DoModal generation window, on m_strName assignment, compiled through, but the operation error,
Found in the Debug, after call DoModal, originally save m_strName address part of the memory (4 bytes) content will be modified, lead to can't find m_strName value (new address cross-border, the original address to content did not change),
and when I am alone EditBox control won't appear this kind of problem, so I want to know what has happened to the middle, what is the difference and how to correctly use DataTimePicker controls,

code section
TestView. H
 
//testView. H: interface of the CTestView class
//
/////////////////////////////////////////////////////////////////////////////

#if ! Defined (AFX_TESTVIEW_H__85D7C03F_39A6_4535_80A5_5E109333D12B__INCLUDED_)
# define AFX_TESTVIEW_H__85D7C03F_39A6_4535_80A5_5E109333D12B__INCLUDED_

# if _MSC_VER & gt; 1000
# pragma once
# endif//_MSC_VER & gt; 1000


The class CTestView: public CView
{
Protected://create the from serialization only
CTestView ();
DECLARE_DYNCREATE (CTestView)

//the Attributes
Public:
CTestDoc * GetDocument ();
Cstrings m_strName;

//Operations
Public:

//Overrides
//ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL (CTestView)
Public:
Virtual void ontouch * pDC (CDC);//overridden to draw this view
Virtual BOOL PreCreateWindow (CREATESTRUCT& Cs);
Protected:
Virtual BOOL OnPreparePrinting (CPrintInfo * pInfo);
Virtual void OnBeginPrinting (CDC * pDC, CPrintInfo * pInfo);
Virtual void OnEndPrinting (CDC * pDC, CPrintInfo * pInfo);
//}} AFX_VIRTUAL

//Implementation
Public:
Virtual ~ CTestView ();
# ifdef _DEBUG
Virtual void AssertValid () const;
Virtual void Dump (CDumpContext& Dc) const;
# endif

Protected:

//Generated message map functions provides
Protected:
//{{AFX_MSG (CTestView)
//NOTE - the ClassWizard will add and remove member functions provides here.
//DO NOT EDIT what you see in these blocks of generated code!
//}} AFX_MSG
DECLARE_MESSAGE_MAP ()
};

# # ifndef _DEBUG//debug version in testView. CPP
The inline CTestDoc * CTestView: : GetDocument ()
{return (CTestDoc *) m_pDocument; }
# endif

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
//Microsoft Visual c + + will insert additional declarations immediately before the previous line.

# endif//! Defined (AFX_TESTVIEW_H__85D7C03F_39A6_4535_80A5_5E109333D12B__INCLUDED_)


TestView. CPP
 
//testView. CPP: implementation of the CTestView class
//

# include "stdafx. H"
# include "test. H"

# include "testDoc. H"
# include "testView. H"

# ifdef _DEBUG
# define new DEBUG_NEW
# undef THIS_FILE
The static char THIS_FILE []=__FILE__;
# endif

/////////////////////////////////////////////////////////////////////////////
//CTestView

IMPLEMENT_DYNCREATE (CTestView, CView)

BEGIN_MESSAGE_MAP (CTestView, CView)
//{{AFX_MSG_MAP (CTestView)
//NOTE - the ClassWizard will add and remove the mapping macros here.
//DO NOT EDIT what you see in these blocks of generated code!
//}} AFX_MSG_MAP
//Standard printing commands
ON_COMMAND (ID_FILE_PRINT, CView: : OnFilePrint)
ON_COMMAND (ID_FILE_PRINT_DIRECT, CView: : OnFilePrint)
ON_COMMAND (ID_FILE_PRINT_PREVIEW, CView: : OnFilePrintPreview)
END_MESSAGE_MAP ()

/////////////////////////////////////////////////////////////////////////////
//CTestView construction/destruction

CTestView: : CTestView ()
{
//TODO: add construction code here
M_strName="0000";
}

CTestView: : ~ CTestView ()
{
}

BOOL CTestView: : PreCreateWindow (CREATESTRUCT& Cs)
{
//TODO: Modify the Window class or styles here by modifying the
//the CREATESTRUCT cs

Return the CView: : PreCreateWindow (cs);
}

/////////////////////////////////////////////////////////////////////////////
//CTestView drawing

Void CTestView: : ontouch * pDC (CDC)
{
CTestDoc * pDoc=GetDocument ();
ASSERT_VALID (pDoc);
//TODO: add the draw code for native data here
CTestDialog DLG.
DLG. DoModal ();
M_strName="11111";
}

/////////////////////////////////////////////////////////////////////////////
//CTestView printing

BOOL CTestView: : OnPreparePrinting (CPrintInfo * pInfo)
{
//the default preparation
Return DoPreparePrinting (pInfo);
}

Void CTestView: : OnBeginPrinting (CDC, pDC */* */pInfo CPrintInfo */* */)
{
//TODO: add extra initialization before printing
}

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related