在vs2005+之上 好像基类没有CRecordView类,要想建立一个基于CRecordView的类,我暂时没有找到好的方法,只能手动添加了。。。
这里的SSS是你要创建的类的名字;
#if !defined(AFX_SSS_H__4F498E08_A53F_46D5_B438_AD50C0E3A6F1__INCLUDED_)
#define AFX_SSS_H__4F498E08_A53F_46D5_B438_AD50C0E3A6F1__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// SSS.h : header file
//
/
// SSS record view SSS就是你要创建的dialog对话框的名字
#include "SysUserSet.h //SysUserSet是关联了dialog所关联的数据库的类。
class SSS : public CRecordView
{
protected:
SSS(); // protected constructor used by dynamic creation
DECLARE_DYNCREATE(SSS)
// Form Data
public:
//{{AFX_DATA(SSS)
enum { IDD = IDD_SYS };//此处应为dialgog的IDD
CSysUserSet* m_pSet;
//}}AFX_DATA
// Attributes
public:
// Operations
public:
CSysUserSet* GetRecordset();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(SSS)
// NOTE - the ClassWizard will add and remove member functions here.
public:
virtual CRecordset* OnGetRecordset();
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual void OnInitialUpdate();
//}}AFX_VIRTUAL
// Implementation
protected:
virtual ~SSS();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
// Generated message map functions
//{{AFX_MSG(SSS)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_SSS_H__4F498E08_A53F_46D5_B438_AD50C0E3A6F1__INCLUDED_)
// SSS.cpp : implementation file
//
#include "stdafx.h"
#include "TestApp.h"
#include "SSS.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/
// SSS
IMPLEMENT_DYNCREATE(SSS, CRecordView)
SSS::SSS()
: CRecordView(SSS::IDD)
{
//{{AFX_DATA_INIT(SSS)
m_pSet = NULL;
//}}AFX_DATA_INIT
}
SSS::~SSS()
{
if (m_pSet)
delete m_pSet;
}
void SSS::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(SSS)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(SSS, CRecordView)
//{{AFX_MSG_MAP(SSS)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/
// SSS diagnostics
#ifdef _DEBUG
void SSS::AssertValid() const
{
CRecordView::AssertValid();
}
void SSS::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
#endif //_DEBUG
/
// SSS message handlers
CRecordset* SSS::OnGetRecordset()
{
if (m_pSet != NULL)
return m_pSet;
m_pSet = new CSysUserSet(NULL);
m_pSet->Open();
return m_pSet;
}
CSysUserSet* SSS::GetRecordset()
{
CSysUserSet* pData = (CSysUserSet*) OnGetRecordset();
ASSERT(pData == NULL || pData->IsKindOf(RUNTIME_CLASS(CSysUserSet)));
return pData;
}
void SSS::OnInitialUpdate()
{
BeginWaitCursor();
GetRecordset();
CRecordView::OnInitialUpdate();
if (m_pSet->IsOpen())
{
CString strTitle = m_pSet->m_pDatabase->GetDatabaseName();
CString strTable = m_pSet->GetTableName();
if (!strTable.IsEmpty())
strTitle += _T(":") + strTable;
GetDocument()->SetTitle(strTitle);
}
EndWaitCursor();
}