基础问题

至善者善之敌 2010-06-02 11:36:33
两个对话框类,内容完全一样,可是当其中一个使用CListCtrl m_sendnote;就会程序出错,很是郁闷,

对话框A.h:

lass CReceive_Note : public CDialog
{
// Construction
public:
CReceive_Note(CWnd* pParent = NULL); // standard constructor
DECLARE_DYNCREATE(CReceive_Note)
// Dialog Data
//{{AFX_DATA(CReceive_Note)
enum { IDD = IDD_RECEIVENOTE };
//}}AFX_DATA
CListCtrl m_receivenote;
void InitListCtrl();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CReceive_Note)
public:
// virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:

// Generated message map functions
//{{AFX_MSG(CReceive_Note)
afx_msg void OnPaint();
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()


};

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

#endif // !defined(AFX_RECEIVE_NOTE_H__74D495D8_E246_48CD_A514_BC4781D4B774__INCLUDED_)




对话框A.cpp:

// Receive_Note.cpp : implementation file
//

#include "stdafx.h"
#include "BarDemo.h"
#include "Receive_Note.h"



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

/////////////////////////////////////////////////////////////////////////////
// CReceive_Note dialog
IMPLEMENT_DYNCREATE(CReceive_Note, CDialog)

CReceive_Note::CReceive_Note(CWnd* pParent /*=NULL*/)
: CDialog(CReceive_Note::IDD, pParent)
{
//{{AFX_DATA_INIT(CReceive_Note)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}


void CReceive_Note::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CReceive_Note)
DDX_Control(pDX, IDC_LIST1, m_receivenote);
//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CReceive_Note, CDialog)
//{{AFX_MSG_MAP(CReceive_Note)
ON_WM_PAINT()
ON_WM_CREATE()
ON_WM_SHOWWINDOW()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CReceive_Note message handlers

void CReceive_Note::InitListCtrl()
{///////////////////////////////////////////////////////////////////////////////
// Name: InitListCtrl
// Description:
// Initialize the list control style and the list control header.
// Effect:
// Call by OnInitDialog()
// Parameters: None
// Return: void
// Author: L.F.
// Date: 2005.9.30
///////////////////////////////////////////////////////////////////////////////


DWORD dwExStyle = LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES;
m_receivenote.SetExtendedStyle( dwExStyle );

// m_receivenote.SetBkColor( RGB(0xe6,0xe6,0xfa) );
m_receivenote.SetTextBkColor( RGB( 100, 180, 250 ) );
// m_receivenote.SetTextBkColor( RGB(0xe6,0xe6,0xfa) );


LVCOLUMN lvcol;

lvcol.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
lvcol.fmt = LVCFMT_CENTER;
lvcol.iSubItem = 1;
lvcol.cx = 160;

lvcol.pszText = _T( "到达时间" );
m_receivenote.InsertColumn( 0, & lvcol );

lvcol.pszText = _T( "消息类型" );
m_receivenote.InsertColumn( 1, & lvcol );

lvcol.cx = 420;
lvcol.pszText = _T( "消息内容" );
m_receivenote.InsertColumn( 2, & lvcol );

lvcol.cx = 200;
lvcol.pszText = _T( "其它" );
m_receivenote.InsertColumn( 3, & lvcol );
lvcol.cx = 300;

lvcol.pszText = _T( "" );
m_receivenote.InsertColumn( 4, & lvcol );

CFont m_Font;
VERIFY(m_Font.CreateFont(
//(15,0,0,0,0,FALSE,FALSE,0,0,0,0,0,0,_TEXT("宋体"))); // lpszFacename
// 20,0,0,0,FW_NORMAL,FALSE,FALSE,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH | FF_SWISS,_T("黑体")));
15, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
0, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
"Arial"));

m_receivenote.GetHeaderCtrl()->SetFont(&m_Font);

// CDC* pDC=GetDC();
// pDC-> SelectObject(&m_Font);
m_receivenote.InsertItem(0, "china ");
// m_receivenote.SetFont(&m_Font);
// m_receivenote.InsertItem(0, "china ");


}

void CReceive_Note::OnPaint()
{
CPaintDC dc(this); // device context for painting
// InitListCtrl();
// TODO: Add your message handler code here

// Do not call CDialog::OnPaint() for painting messages
}





BOOL CReceive_Note::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here
InitListCtrl();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}




对话框B:

class CSend_Note : public CDialog
{
// Construction
public:
CSend_Note(CWnd* pParent = NULL); // standard constructor
DECLARE_DYNCREATE(CSend_Note)
// Dialog Data
//{{AFX_DATA(CSend_Note)
enum { IDD = IDD_SENDNOTE };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
CListCtrl m_sendnote;
void InitListCtrl();

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSend_Note)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL


// Implementation
protected:

// Generated message map functions
//{{AFX_MSG(CSend_Note)
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};


对话框B.cpp:

// Send_Note.cpp : implementation file
//

#include "stdafx.h"
#include "BarDemo.h"
#include "Send_Note.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSend_Note dialog
IMPLEMENT_DYNCREATE(CSend_Note, CDialog)

CSend_Note::CSend_Note(CWnd* pParent /*=NULL*/)
: CDialog(CSend_Note::IDD, pParent)
{
//{{AFX_DATA_INIT(CSend_Note)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}


void CSend_Note::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSend_Note)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSend_Note, CDialog)
//{{AFX_MSG_MAP(CSend_Note)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSend_Note message handlers

BOOL CSend_Note::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here

InitListCtrl();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}

void CSend_Note::InitListCtrl()
{///////////////////////////////////////////////////////////////////////////////
// Name: InitListCtrl
// Description:
// Initialize the list control style and the list control header.
// Effect:
// Call by OnInitDialog()
// Parameters: None
// Return: void
// Author: L.F.
// Date: 2005.9.30
///////////////////////////////////////////////////////////////////////////////


DWORD dwExStyle = LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES;
m_sendnote.SetExtendedStyle( dwExStyle );

// m_receivenote.SetBkColor( RGB(0xe6,0xe6,0xfa) );
m_sendnote.SetTextBkColor( RGB( 100, 180, 250 ) );
// m_receivenote.SetTextBkColor( RGB(0xe6,0xe6,0xfa) );


LVCOLUMN lvcol;

lvcol.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
lvcol.fmt = LVCFMT_CENTER;
lvcol.iSubItem = 1;
lvcol.cx = 160;

lvcol.pszText = _T( "到达时间" );
m_sendnote.InsertColumn( 0, & lvcol );

lvcol.pszText = _T( "消息类型" );
m_sendnote.InsertColumn( 1, & lvcol );

lvcol.cx = 420;
lvcol.pszText = _T( "消息内容" );
m_sendnote.InsertColumn( 2, & lvcol );

lvcol.cx = 200;
lvcol.pszText = _T( "其它" );
m_sendnote.InsertColumn( 3, & lvcol );
lvcol.cx = 300;

lvcol.pszText = _T( "" );
m_sendnote.InsertColumn( 4, & lvcol );

CFont m_Font;
VERIFY(m_Font.CreateFont(
//(15,0,0,0,0,FALSE,FALSE,0,0,0,0,0,0,_TEXT("宋体"))); // lpszFacename
// 20,0,0,0,FW_NORMAL,FALSE,FALSE,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH | FF_SWISS,_T("黑体")));
15, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
0, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
"Arial"));

m_sendnote.GetHeaderCtrl()->SetFont(&m_Font);

// CDC* pDC=GetDC();
// pDC-> SelectObject(&m_Font);
m_sendnote.InsertItem(0, "china ");
// m_receivenote.SetFont(&m_Font);
// m_receivenote.InsertItem(0, "china ");


}

void CSend_Note::OnPaint()
{
CPaintDC dc(this); // device context for painting

// TODO: Add your message handler code here

// Do not call CDialog::OnPaint() for painting messages
}




对话框B中只要使用m_sendnote;了就运行报错,WHY?

...全文
104 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
至善者善之敌 2010-06-02
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 hzy694358 的回复:]
void CReceive_Note::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CReceive_Note)
DDX_Control(pDX, IDC_LIST1, m_receivenote);
//}}AFX_DATA_MAP
}
这个函数明显是不同的,……
[/Quote]

呵呵问题已经找到,不过还是谢谢你认真的解答!
hzy694358 2010-06-02
  • 打赏
  • 举报
回复
void CReceive_Note::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CReceive_Note)
DDX_Control(pDX, IDC_LIST1, m_receivenote);
//}}AFX_DATA_MAP
}
这个函数明显是不同的,你竟然说同,这不忽悠人吗
bdzwj 2010-06-02
  • 打赏
  • 举报
回复
对话框资源不同, 检查资源ID信息

16,550

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧