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,"太学");
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,"太学");
//#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
}
或者直接用成员变量也行啊!
请参考!
m_list.InsertColumn(0,_T("ID号"),LVCFMT_LEFT,40);
m_list.InsertColumn(1,_T("密钥类型"),LVCFMT_LEFT,110); 我做完后运行没有问题了~~~~
你试一下吧
1、用CLASSWISARD添加CListCtrl成员变量m_HSMKeyList,然后就能用了,这个最常用,最简单;
2、声明CListCtrl *m_HSMKeyList指针,然后用时m_HSMKeyList=new CListCtrl;用m_HSMKeyList->操作,用完了再删除或析掉,这个也常用;
3、好象可以m_HSMKeyList.Create(……),这个没怎么用过,感觉有些麻烦。
我的新手,呵呵!
{
m_HSMKeyList.InsertColumn(0,_T("ID号"),LVCFMT_LEFT,40);
m_HSMKeyList.InsertColumn(1,_T("密钥类型"),LVCFMT_LEFT,110);
//m_HSMKeyList.InsertItem(0,"太学");
}
我把 //注释的内容注释之后就不出错了,我不明白是为什么?
如果有错误不可能把函数体内第三句注释掉错误就没了吧?我现在也有些不明白了
//#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,"太学");
}
{
m_HSMKeyList.InsertColumn(0,_T("ID号"),LVCFMT_LEFT,40);
m_HSMKeyList.InsertColumn(1,_T("密钥类型"),LVCFMT_LEFT,110);
//m_HSMKeyList.InsertItem(0,"太学");
} 假如不编译 // 部分不会出错,但是 //释放之后,重新编译执行的时间会出错。现在我想请问各位是创建的项目有问题还是我的电脑有问题呢? 真是搞不明白,也很头痛。
说对了,就是不应该加上 owner Draw .谢谢。