如何用VC生成最小的MFC程序_新手上路 如何用VC生成最小的MFC程序,赐教 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1,ctrl + N选择mfc(exe)输入一个项目名字2,选择“基于对话框程序”,点“finish”就可以了 看看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); } 以上就是全部代码,而且里面还有我的一些小垃圾代码(注释部分),呵呵。除了显示Hello MFC还有一个正弦波。 看看深入浅出mfc有个演示mfc的小程序,很精采。 深入浅出MFC的演示程序你指的哪个?我没看完这本书,只记得他的演示程序不是真正的MFC,而只是类名和MFC相同。你说说在哪一章立面,我去看看。 VC中关于文件映像问题. 问个端口监听的问题 WTL Ownerdraw CAsyncSocket类的问题 键盘消息 ado获得bookmark 然后delete的问题 请问可以说一下MFC框架中运用了虚函数的例子吗? 初级问题高手来看看 给点帮助! 做地图编辑的时候,如何实现像autoCAD一样的实时缩放和移图? 怎么让richedit看起来像个编辑器?----------已经没分了:( 请问哪位大侠有TIF图象格式的详细汉语说明的? 请问用vc如何在tiff文件中添加一页加入自己的cover
选择mfc(exe)
输入一个项目名字2,选择“基于对话框程序”,点“finish”就可以了
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);
}