class CPhonesListBox:public ClistBox之后出现了问题我没找到,帮忙找找谢谢了,急呀!!!!
tm_wb 2005-09-07 09:19:58 我在做一个简单的电话号簿的程序练习框架是用MFC AppWizard 生成的
我我这样定义客户区类
class CPhonesListBox:public ClistBox然后
class CChildView:public CPhonesListBox我想把客户区做成列表框样式的
但是在对话框接受到名字和号码之后并没有把名字和号码加入客户区内
大家帮帮我
代码很多最好大家留下邮箱
不过我还是把我认为有问题的地方粘出来,大家帮忙看看,如果认为不是这些地方有问题我会把剩余地方粘出来,谢谢
PhonesListBox.h
/////////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_PHONESLISTBOX_H__F58B1338_C25E_4C92_8329_EFFE34CA0D33__INCLUDED_)
#define AFX_PHONESLISTBOX_H__F58B1338_C25E_4C92_8329_EFFE34CA0D33__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// PhonesListBox.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CPhonesListBox window
class CPhonesListBox : public CListBox
{
// Construction
public:
CPhonesListBox();
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CPhonesListBox)
//}}AFX_VIRTUAL
// Implementation
public:
void NewEntry();
virtual ~CPhonesListBox();
// Generated message map functions
protected:
CFont m_font;
//{{AFX_MSG(CPhonesListBox)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnEditItem();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_PHONESLISTBOX_H__F58B1338_C25E_4C92_8329_EFFE34CA0D33__INCLUDED_)
///////////////////////////////////////////////////////////////////////////////
PhonesListBox.cpp
///////////////////////////////////////////////////////////////////////////////
// PhonesListBox.cpp : implementation file
//
#include "stdafx.h"
#include "Phones.h"
#include "PhonesListBox.h"
#include "PhoneEdit.h"
#include "EditDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPhonesListBox
CPhonesListBox::CPhonesListBox()
{
}
CPhonesListBox::~CPhonesListBox()
{
}
BEGIN_MESSAGE_MAP(CPhonesListBox, CListBox)
//{{AFX_MSG_MAP(CPhonesListBox)
ON_WM_CREATE()
ON_CONTROL_REFLECT(LBN_DBLCLK,OnEditItem)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPhonesListBox message handlers
int CPhonesListBox::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CListBox::OnCreate(lpCreateStruct) == -1)
return -1;
m_font.CreatePointFont(80,_T("MS Sans Serif"));
SetFont(&m_font,FALSE);
SetTabStops(128);
return 0;
}
void CPhonesListBox::OnEditItem()
{
CEditDialog dlg;
CString strItem;
int nIndex=GetCurSel();
GetText(nIndex,strItem);
int nPos=strItem.Find(_T('\t'));
dlg.m_strName=strItem.Left(nPos);
dlg.m_strPhone=strItem.Right(strItem.GetLength()-nPos-1);
if(dlg.DoModal()==IDOK)
{
strItem=dlg.m_strName+_T("\t")+dlg.m_strPhone;
DeleteString(nIndex);
AddString(strItem);
}
SetFocus();
}
void CPhonesListBox::NewEntry()
{
CEditDialog dlg;
if(dlg.DoModal()==IDOK)
{
CString strItem=dlg.m_strName+_T("\t")+dlg.m_strPhone;
AddString(strItem);
}
SetFocus();
}
///////////////////////////////////////////////////////////////////////////