如何用VC生成最小的MFC程序,赐教

解决方案 »

  1.   

    1,ctrl + N
    选择mfc(exe)
    输入一个项目名字2,选择“基于对话框程序”,点“finish”就可以了
      

  2.   

    看看programming windows with mfc这本书,里面有一个程序只有一个app类和一个CWnd的派生类,这才是最小的。然后继续学习,可以清楚看到MFC程序是怎么构造出来的。
    hello.h:
    class CMyApp : public CWinApp
    {
    public:
        virtual BOOL InitInstance ();
    };class CMainWindow : public CFrameWnd
    {
    public:
        CMainWindow ();protected:
        afx_msg void OnPaint ();
        DECLARE_MESSAGE_MAP ()
    };
    hello.cpp:
    #include <afxwin.h>
    #include <math.h>
    #define SEGMENTS 500
    #define PI 3.1415926#include "Hello.h"CMyApp myApp;/////////////////////////////////////////////////////////////////////////
    // CMyApp member functionsBOOL CMyApp::InitInstance ()
    {
        m_pMainWnd = new CMainWindow;
       m_pMainWnd->ShowWindow (m_nCmdShow);
        m_pMainWnd->UpdateWindow ();
        return TRUE;
    }/////////////////////////////////////////////////////////////////////////
    // CMainWindow message map and member functionsBEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd)
        ON_WM_PAINT ()
    END_MESSAGE_MAP ()CMainWindow::CMainWindow ()
    {
        Create (NULL, _T ("The Hello Application"),WS_OVERLAPPED | WS_CAPTION |
    WS_SYSMENU | WS_MINIMIZEBOX | WS_THICKFRAME);
    }void CMainWindow::OnPaint ()
    {
        CPaintDC dc (this);
        
        CRect rect;
        GetClientRect (&rect);    dc.DrawText (_T ("Hello, MFC"), -1, &rect,
            DT_SINGLELINE | DT_CENTER | DT_VCENTER);// CRect rect;
    //   GetClientRect (&rect);
        int nWidth = rect.Width ();
        int nHeight = rect.Height ();

    //   CPaintDC dc (this);
        CPoint aPoint[SEGMENTS];

        for (int i=0; i<SEGMENTS; i++) {
            aPoint[i].x = (i * nWidth) / SEGMENTS;
            aPoint[i].y = (int) ((nHeight / 2) *
                (1 - (sin ((2 * PI * i) / SEGMENTS))));
        }
        dc.Polyline (aPoint, SEGMENTS);

    }
      

  3.   

    以上就是全部代码,而且里面还有我的一些小垃圾代码(注释部分),呵呵。除了显示Hello MFC还有一个正弦波。
      

  4.   

    看看深入浅出mfc有个演示mfc的小程序,很精采。
      

  5.   

    深入浅出MFC的演示程序你指的哪个?我没看完这本书,只记得他的演示程序不是真正的MFC,而只是类名和MFC相同。你说说在哪一章立面,我去看看。