MFC编程实例

  • C5_906941
    了解作者
  • 3.1MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-13 09:11
    上传日期
MFC编程实例,提供给初学者学习MFC的代码
MFC+编程实例.zip
  • MFC+编程实例
  • A34
  • RES
  • TOOLBAR.BMP
    1.1KB
  • WZD.ICO
    1.1KB
  • WZD.RC2
    395B
  • WZDDOC.ICO
    1.1KB
  • WIZARD
  • README.WZD
    869B
  • CHILDFRM.CPP
    1.5KB
  • WZDDOC.H
    1.4KB
  • WZDDOC.CPP
    1.6KB
  • Wzd.dsp
    4.5KB
  • RESOURCE.H
    637B
  • MAINFRM.H
    1.5KB
  • WZD.DSW
    531B
  • CHILDFRM.H
    1.4KB
  • WZD.H
    1.3KB
  • WZD.CPP
    4.2KB
  • WZD.RC
    13.6KB
  • MAINFRM.CPP
    2.5KB
  • STDAFX.H
    987B
  • STDAFX.CPP
    201B
  • 说明.txt
    12B
  • Wzd.mak
    5.6KB
  • Wzd.001
    4.5KB
  • WZDVIEW.CPP
    2.6KB
  • WZDVIEW.H
    1.7KB
  • A60
  • RES
  • TOOLBAR.BMP
    1.1KB
  • WZD.ICO
    1.1KB
  • WZD.RC2
    395B
  • WZDDOC.ICO
    1.1KB
  • WIZARD
  • README.WZD
    1.4KB
  • CHILDFRM.CPP
    1.5KB
  • WZDDOC.H
    1.4KB
  • WZDDOC.CPP
    1.6KB
  • Wzd.dsp
    4.5KB
  • RESOURCE.H
    778B
  • MAINFRM.H
    1.5KB
  • WZD.DSW
    531B
  • CHILDFRM.H
    1.4KB
  • WZD.H
    1.3KB
  • WZD.CPP
    4.2KB
  • WZD.RC
    13.8KB
  • MAINFRM.CPP
    2.5KB
  • STDAFX.H
    987B
  • STDAFX.CPP
    201B
  • 说明.txt
    15B
  • Wzd.mak
    5.6KB
  • Wzd.001
    4.5KB
  • WZDVIEW.CPP
    3KB
  • WZDVIEW.H
    1.9KB
  • A18
  • RES
  • TOOLBAR.BMP
    1.1KB
  • WZD.ICO
    1.1KB
  • WZD.RC2
    395B
  • WZDDOC.ICO
    1.1KB
  • WIZARD
  • README.WZD
    1.3KB
  • CHILDFRM.CPP
    1.5KB
  • WZDDOC.H
    1.4KB
  • WZDDOC.CPP
    1.6KB
  • Wzd.dsp
    4.5KB
  • RESOURCE.H
    778B
  • MAINFRM.H
    1.5KB
  • WZD.DSW
    531B
  • CHILDFRM.H
    1.4KB
  • Wzd.clw
    2.9KB
  • WZD.H
    1.3KB
  • WZD.CPP
    4.2KB
  • WZD.RC
    13.7KB
  • MAINFRM.CPP
    2.5KB
  • STDAFX.H
    987B
  • STDAFX.CPP
    201B
  • 说明.txt
    16B
  • Wzd.mak
    5.6KB
  • Wzd.001
    4.5KB
  • WZDVIEW.CPP
    3.3KB
  • WZDVIEW.H
    1.7KB
  • A52
  • RES
  • TOOLBAR.BMP
    1.1KB
  • WZD.ICO
    1.1KB
  • WZD.RC2
    395B
  • WZDDOC.ICO
    1.1KB
  • WIZARD
  • README.WZD
    657B
  • WZDDLG.CPP
    1012B
  • CHILDFRM.CPP
    1.5KB
  • WZDDOC.H
    1.4KB
  • WZDDOC.CPP
    1.6KB
  • Wzd.dsp
    4.6KB
  • RESOURCE.H
    820B
  • MAINFRM.H
    1.5KB
  • WZD.DSW
    531B
  • CHILDFRM.H
    1.4KB
内容介绍
// WzdView.cpp : implementation of the CWzdView class // #include "stdafx.h" #include "Wzd.h" #include "WzdDoc.h" #include "WzdView.h" #include "WzdRSet.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CWzdView IMPLEMENT_DYNCREATE(CWzdView, CView) BEGIN_MESSAGE_MAP(CWzdView, CView) //{{AFX_MSG_MAP(CWzdView) ON_COMMAND(ID_TEST_WZD, OnTestWzd) //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CWzdView construction/destruction CWzdView::CWzdView() { // TODO: add construction code here } CWzdView::~CWzdView() { } BOOL CWzdView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CWzdView drawing void CWzdView::OnDraw(CDC* pDC) { CWzdDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here } ///////////////////////////////////////////////////////////////////////////// // CWzdView printing BOOL CWzdView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CWzdView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CWzdView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CWzdView diagnostics #ifdef _DEBUG void CWzdView::AssertValid() const { CView::AssertValid(); } void CWzdView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CWzdDoc* CWzdView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWzdDoc))); return (CWzdDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CWzdView message handlers void CWzdView::OnTestWzd() { // create record set object CWzdRecordset wzdSet(GetDocument()->GetDatabase()); // open all records in table wzdSet.Open(); // scroll through records while (! wzdSet.IsEOF()) { // values can be accessed from record set member variables: // wzdSet.m_CustomerID // wzdSet.m_CompanyName // wzdSet.m_ContactName // etc. wzdSet.MoveNext(); } //find a record (without opening the record set that way) if (wzdSet.FindFirst("[Country]='UK'")) { while (wzdSet.FindNext("[Country]='UK'")) { } } // if we can't update or append records, leave now if (!wzdSet.CanUpdate() || !wzdSet.CanAppend()) return; // add a record try { // add new record wzdSet.AddNew(); // initialize each field wzdSet.m_CustomerID="ABCDX"; wzdSet.m_CompanyName="ABC Inc."; //etc. // update database wzdSet.Update(); } catch (CDaoException *e) { // AddNew failed AfxMessageBox(e->m_pErrorInfo->m_strDescription); e->Delete(); } // edit a record wzdSet.MoveFirst(); try { wzdSet.Edit(); // update affected fields wzdSet.m_CompanyName="ABCEF Inc."; wzdSet.m_ContactName="Frank"; //etc. // update database wzdSet.Update(); } catch (CDaoException *e) { // Edit failed AfxMessageBox(e->m_pErrorInfo->m_strDescription); e->Delete(); } // delete a record try { // delete record to which we're currently opened wzdSet.Delete(); } catch (CDaoException *e) { // Delete failed AfxMessageBox(e->m_pErrorInfo->m_strDescription); e->Delete(); } // close record set wzdSet.Close(); /////////////////////////////////// // RECORD FILTERING /////// /////////////////////////////////// // open record set with a simple "WHERE" SQL filter wzdSet.m_strFilter = "[Country]='UK'"; // sort record set with a simple "ORDER BY" SQL specification wzdSet.m_strSort = "[ContactName]"; wzdSet.Open(); if(wzdSet.IsEOF()) { AfxMessageBox("Cannot find records."); } // scroll through records as above... while (! wzdSet.IsEOF()) { wzdSet.MoveNext(); } wzdSet.Close(); // open a record set with a complete SQL SELECT statement wzdSet.m_strFilter = ""; // appended to the following! wzdSet.m_strSort = ""; wzdSet.Open(AFX_DB_USE_DEFAULT_TYPE, "SELECT [CustomerID], [CompanyName], [ContactName], \ [ContactTitle], [Address], [City], [Region], [PostalCode], [Country], [Phone], [Fax] \ FROM [Customers] WHERE [Country] = 'Mexico'"); if (wzdSet.IsEOF()) { AfxMessageBox("Cannot find records."); } // scroll through records as above... while (! wzdSet.IsEOF()) { wzdSet.MoveNext(); } wzdSet.Close(); //////////////////////////////////// // MULTIPLE TABLE TRANSACTIONS ///// //////////////////////////////////// // NOTE: when performing related operations on more then one database // table at a time, an error in any one of these transactions should undo // or "rollback" all of the changes made // Create a transaction we can rollback GetDocument()->GetDatabase()->m_pWorkspace->BeginTrans(); try { // perform transactions on several database tables/records wzdSet.Open(); wzdSet.Update(); // Success GetDocument()->GetDatabase()->m_pWorkspace->CommitTrans(); } catch (CDaoException *e) { // An exception occurred, rollback the transaction GetDocument()->GetDatabase()->m_pWorkspace->Rollback(); AfxMessageBox(e->m_pErrorInfo->m_strDescription); e->Delete(); } // since this was allocated on stack, returning will also close record set wzdSet.Close(); }
评论
    相关推荐
    • MFC入门
      MFC入门是pdf格式的,压缩包中含有pdf的浏览器
    • MFC五子棋
      MFC五子棋MFC五子棋MFC五子棋MFC五子棋MFC五子棋MFC五子棋MFC五子棋
    • mfc指南
      基础的mfc 参考手册 入门资料
    • mfc大全
      It's very good!
    • 中文MFC
      中文的MFC类库详解,供大家编程用
    • MFC入门
      MFC入门必备知识 比较简单的介绍
    • mfc教程
      mfc教程。mfc教程
    • MFC easysize
      运用该文件,可以是MFC界面部件自适应变化,满足窗体拉伸等需求变化
    • mfc学习
      这个是个学习vc的mfc编程的例子
    • MFC教程
      MFC教程MFC教程MFC教程MFC教程