Microsoft Visual C++ Debug Library Debug Assertion Failed! Program : E:\GGG'MFCTest\Debug\MFCTest.exeFile :winctrl2.cpp
Line 547For information on how your program can cause an assertion failure,see the Visual C++ documentatin on asserts.
(Press retry to debug the application)终止 重试 忽略 三个Button 在 OnInitDialog() 中 调用  RefrashID() 函数 此函数返回值 为  void 在 RefrashID 中加入如下代码 : 
m_HSMKeyList.InsertColumn(0,"ID号",LVCFMT_LEFT,40,-1);
m_HSMKeyList.InsertColumn(1,"密钥类型",LVCFMT_LEFT,110,-1);
请教各位帮我看看出错是什么原因呢?谢了!
m_HSMKeyList.InsertItem(0,"太学");

解决方案 »

  1.   

    // MFCTestDlg.cpp : implementation file
    //#include "stdafx.h"
    #include "MFCTest.h"
    #include "MFCTestDlg.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog
    {
    public:
    CAboutDlg();// Dialog Data
    //{{AFX_DATA(CAboutDlg)
    enum { IDD = IDD_ABOUTBOX };
    //}}AFX_DATA // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CAboutDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    //{{AFX_MSG(CAboutDlg)
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
    {
    //{{AFX_DATA_INIT(CAboutDlg)
    //}}AFX_DATA_INIT
    }void CAboutDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CAboutDlg)
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
    // No message handlers
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CMFCTestDlg dialogCMFCTestDlg::CMFCTestDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CMFCTestDlg::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CMFCTestDlg)
    // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }void CMFCTestDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CMFCTestDlg)
    DDX_Control(pDX, IDC_LIST1, m_HSMKeyList);
    DDX_Control(pDX, IDCANCEL, m_CANCEL);
    DDX_Control(pDX, IDOK, m_OK);
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CMFCTestDlg, CDialog)
    //{{AFX_MSG_MAP(CMFCTestDlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CMFCTestDlg message handlersBOOL CMFCTestDlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    } // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon

    // TODO: Add extra initialization here
    RefrashID();
    return TRUE;  // return TRUE  unless you set the focus to a control
    }void CMFCTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
    {
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
    CAboutDlg dlgAbout;
    dlgAbout.DoModal();
    }
    else
    {
    CDialog::OnSysCommand(nID, lParam);
    }
    }// If you add a minimize button to your dialog, you will need the code below
    //  to draw the icon.  For MFC applications using the document/view model,
    //  this is automatically done for you by the framework.void CMFCTestDlg::OnPaint() 
    {
    if (IsIconic())
    {
    CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
    int cxIcon = GetSystemMetrics(SM_CXICON);
    int cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
    dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
    CDialog::OnPaint();
    }
    }// The system calls this to obtain the cursor to display while the user drags
    //  the minimized window.
    HCURSOR CMFCTestDlg::OnQueryDragIcon()
    {
    return (HCURSOR) m_hIcon;
    }void CMFCTestDlg::OnOK() 
    {
    // TODO: Add extra validation here
    MessageBox("OK Button Testing in c \n");

    CDialog::OnOK();
    }void CMFCTestDlg::OnCancel() 
    {
    // TODO: Add extra cleanup here
    MessageBox("Cancel Button Testing in c \n");

    CDialog::OnCancel();
    }//DEL Void CMFCTestDlg::RefrashID()
    //DEL {
    //DEL 
    //DEL }void CMFCTestDlg::RefrashID()
    {
    m_HSMKeyList.DeleteAllItems();

    //m_HSMKeyList.SetExtendedStyle(LVS_EX_FULLROWSELECT);
    //m_HSMKeyList.InsertColumn(0,"字段1",LVCFMT_LEFT,80); //插入列
    // m_HSMKeyList.InsertColumn(1,"字段2",LVCFMT_LEFT,150);
    // m_HSMKeyList.InsertColumn(2,"字段3",LVCFMT_LEFT,100);// int row = m_HSMKeyList.InsertItem(1,"ID1"); //用insertItem 返回行数 //m_HSMKeyList.InsertItem(0,"大学");
    //m_HSMKeyList.SetItemText(0,1,"MP3");// m_HSMKeyList.SetItemText(row,1,"kkk");//用setItemText 设置该行的各列值// m_HSMKeyList.SetItemText(row,2,"aaa");// 设置第二列的值  m_HSMKeyList.InsertColumn(0,"ID号",LVCFMT_LEFT,40,-1);
    m_HSMKeyList.InsertColumn(1,"密钥类型",LVCFMT_LEFT,110,-1); m_HSMKeyList.InsertItem(0,"太学");
    //m_HSMKeyList
    }
      

  2.   

    List Control的属性->styles->view,默认的是Icon,设置为Report就可以了。
      

  3.   

    List Control -> 右銉 -> Properties -> styles -> View 设置成为了 Report  ,但是之前设置过也出问题呀!
      

  4.   

    我知道了,你是不是没有初始化CListCtrl所致?我试过了,弹出来了!
    或者直接用成员变量也行啊!
    请参考!
      

  5.   

    那么如你说那么如何进行  初始化 CListCtrl 呢?
      

  6.   

    我刚给你运行了一下,是有错误。后来我重新给你做了一下就没有问题了,你那样做列表框中什么内容也没有,你要List Control -> 右銉 -> Properties -> styles -> View 设置成为了 Report  后就可以看见内容了,建议你重新做一次。
         m_list.InsertColumn(0,_T("ID号"),LVCFMT_LEFT,40); 
        m_list.InsertColumn(1,_T("密钥类型"),LVCFMT_LEFT,110); 我做完后运行没有问题了~~~~
    你试一下吧
      

  7.   

    这个我也不是太清楚,我一般用三个方法:
    1、用CLASSWISARD添加CListCtrl成员变量m_HSMKeyList,然后就能用了,这个最常用,最简单;
    2、声明CListCtrl *m_HSMKeyList指针,然后用时m_HSMKeyList=new CListCtrl;用m_HSMKeyList->操作,用完了再删除或析掉,这个也常用;
    3、好象可以m_HSMKeyList.Create(……),这个没怎么用过,感觉有些麻烦。
    我的新手,呵呵!
      

  8.   

    我又重新新建 了一个,但是又出现的相同的问题?看如下的错误的代码: void CMFCTestDlg::RefrashID()
    {
     m_HSMKeyList.InsertColumn(0,_T("ID号"),LVCFMT_LEFT,40); 
        m_HSMKeyList.InsertColumn(1,_T("密钥类型"),LVCFMT_LEFT,110); 
    //m_HSMKeyList.InsertItem(0,"太学"); 
    }
    我把 //注释的内容注释之后就不出错了,我不明白是为什么? 
      

  9.   

    从新建了一个什么?是工程还是CListCtrl或CListCtrl的对象?
    如果有错误不可能把函数体内第三句注释掉错误就没了吧?我现在也有些不明白了
      

  10.   

    我加了m_HSMKeyList.InsertItem(0,"太学"); 也没有错误啊~~~~
      

  11.   

    请问LZ三点:第一,你把ListCtrl属性设置为Report了没?第二,你的ListCtrl对象是通过类向导加的吗?第三,你的RefrashID()在哪些地方调用?
      

  12.   

    回答 my_ girlf 的提问: 第一: 我把 ListCtrl 属性设置 为了 Report 第一 : CListCtrl 对象是通过类向导加的第三 : 请看如下的代码: RefrashID() 是在 BOOL CMFCTestDlg::OnInitDialog()中调用的。
      

  13.   

    // MFCTestDlg.cpp : implementation file
    //#include "stdafx.h"
    #include "MFCTest.h"
    #include "MFCTestDlg.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog
    {
    public:
    CAboutDlg();// Dialog Data
    //{{AFX_DATA(CAboutDlg)
    enum { IDD = IDD_ABOUTBOX };
    //}}AFX_DATA // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CAboutDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    //{{AFX_MSG(CAboutDlg)
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
    {
    //{{AFX_DATA_INIT(CAboutDlg)
    //}}AFX_DATA_INIT
    }void CAboutDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CAboutDlg)
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
    // No message handlers
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CMFCTestDlg dialogCMFCTestDlg::CMFCTestDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CMFCTestDlg::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CMFCTestDlg)
    // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }void CMFCTestDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CMFCTestDlg)
    DDX_Control(pDX, IDC_LIST1, m_HSMKeyList);
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CMFCTestDlg, CDialog)
    //{{AFX_MSG_MAP(CMFCTestDlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CMFCTestDlg message handlersBOOL CMFCTestDlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    } // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon

    // TODO: Add extra initialization here
    RefrashID();

    return TRUE;  // return TRUE  unless you set the focus to a control
    }void CMFCTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
    {
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
    CAboutDlg dlgAbout;
    dlgAbout.DoModal();
    }
    else
    {
    CDialog::OnSysCommand(nID, lParam);
    }
    }// If you add a minimize button to your dialog, you will need the code below
    //  to draw the icon.  For MFC applications using the document/view model,
    //  this is automatically done for you by the framework.void CMFCTestDlg::OnPaint() 
    {
    if (IsIconic())
    {
    CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
    int cxIcon = GetSystemMetrics(SM_CXICON);
    int cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
    dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
    CDialog::OnPaint();
    }
    }// The system calls this to obtain the cursor to display while the user drags
    //  the minimized window.
    HCURSOR CMFCTestDlg::OnQueryDragIcon()
    {
    return (HCURSOR) m_hIcon;
    }void CMFCTestDlg::RefrashID()
    {
     m_HSMKeyList.InsertColumn(0,_T("ID号"),LVCFMT_LEFT,40); 
        m_HSMKeyList.InsertColumn(1,_T("密钥类型"),LVCFMT_LEFT,110); 
    //m_HSMKeyList.InsertItem(0,"太学"); 
    }
      

  14.   

    新建了一个工程,加入了对话框加入 CListCtrl 控件。void CMFCTestDlg::RefrashID() 

    m_HSMKeyList.InsertColumn(0,_T("ID号"),LVCFMT_LEFT,40); 
        m_HSMKeyList.InsertColumn(1,_T("密钥类型"),LVCFMT_LEFT,110); 
    //m_HSMKeyList.InsertItem(0,"太学"); 
    } 假如不编译  // 部分不会出错,但是 //释放之后,重新编译执行的时间会出错。现在我想请问各位是创建的项目有问题还是我的电脑有问题呢? 真是搞不明白,也很头痛。
      

  15.   

    你把加载CListCtrl 控件的这个对话框删掉,重新添加一个对话框再试一下。
      

  16.   

    我把代的代码一点不动的COPY到我的机器上编译,没有任何错误。我想是不是在其它地方有问题,请再检查!
      

  17.   

    看看你ListCtrl的属性,是不是选上Owner Draw了,请取消。
      

  18.   


    说对了,就是不应该加上 owner Draw .谢谢。