>_<:Here are the template of mini-MFC include:
- CPen,CBrush,Front,Paint Line and some other graph.
- OnPaint message,OnLeftButtonDown message,you can through it know more
Hello.h
1 #include2 class CMyApp:public CWinApp 3 { 4 public: 5 virtual BOOL InitInstance(); 6 }; 7 class CMainWindow:public CFrameWnd 8 { 9 public:10 CMainWindow();11 protected:12 afx_msg void OnPaint();13 afx_msg void OnLButtonDown(UINT m_nFlags,CPoint point);14 DECLARE_MESSAGE_MAP();15 };
Hello.cpp
1 #include2 #include 3 #include"Hello.h" 4 #define SEGMENTS 500 5 #define PI 3.1415926 6 7 int PenStyle[7]={PS_SOLID,PS_DASH,PS_DOT,PS_DASHDOT,PS_DASHDOTDOT,PS_NULL,PS_INSIDEFRAME};//实线\宽\窄\宽+窄\宽+2窄\没有\实线不外伸 8 int PenNum=0; 9 int BrushStye[6]={HS_BDIAGONAL,HS_FDIAGONAL,HS_CROSS,HS_HORIZONTAL,HS_DIAGCROSS,HS_VERTICAL};//45\135\90交叉\0\45交叉\90 10 int BrushNum=0; 11 12 CMyApp myApp; 13 // 14 //CMyApp member function 15 BOOL CMyApp::InitInstance() //初始化函数 16 { 17 m_pMainWnd=new CMainWindow; 18 m_pMainWnd->ShowWindow(m_nCmdShow); 19 m_pMainWnd->UpdateWindow(); 20 return TRUE; 21 } 22 / 23 //CMainWindow message map and member function 24 BEGIN_MESSAGE_MAP(CMainWindow,CFrameWnd) //消息映射 25 ON_WM_PAINT() 26 ON_WM_LBUTTONDOWN() 27 END_MESSAGE_MAP() 28 29 CMainWindow::CMainWindow() //创建窗口 30 { 31 Create(NULL,_T("The Hello"),WS_OVERLAPPED,CRect(20,40,640,440));//CFrameWnd下的成员函数8个参数,6个默认 32 } //这个参数产生垂直滚动条 33 34 void CMainWindow::OnPaint() 35 { 36 37 CRect rect; 38 GetClientRect(&rect); 39 40 /*72点,Arial,并带有下拉阴影生成的“Hello MFC" 41 CFont font; 42 font.CreatePointFont(720,_T("Arial"));//创建72点,Arial字体 43 44 CPaintDC dc(this); 45 dc.SelectObject(&font); 46 dc.SetBkMode(TRANSPARENT);//背景模式 设为透明 47 48 CString string=_T("Hello MFC"); 49 50 rect.OffsetRect(16,16);//从窗口中心向右向下偏移几个像素点的位置 51 dc.SetTextColor(RGB(192,192,192)); 52 dc.DrawText(string,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER); 53 54 rect.OffsetRect(-16,-16); 55 dc.SetTextColor(RGB(0,0,0)); 56 dc.DrawText(string,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);//单行、水平、竖直居中的文本 57 */ 58 59 /*LOFGFONT 自定义字体 呈现出旋转效果 60 CPaintDC dc(this); 61 dc.SetViewportOrg(rect.Width()/2,rect.Height()/2); 62 dc.SetBkMode(TRANSPARENT); 63 64 for(int i=0;i<3600;i+=360){ 65 LOGFONT lf;//自己创建一种字体 66 ::ZeroMemory (&lf,sizeof(lf)); 67 lf.lfHeight=180; //26个像素点 68 lf.lfWeight=FW_BOLD; //粗黑 69 //lf.lfItalic=TRUE; //倾斜 70 lf.lfEscapement=i; //配合使用每次旋转36度 71 lf.lfOrientation=i; 72 ::lstrcpy(lf.lfFaceName,_T("Arial")); 73 CFont font; 74 font.CreatePointFontIndirect(&lf); 75 76 CFont* pOldFont=dc.SelectObject(&font); 77 dc.TextOutA(0,0,CString(_T("Hello,MFC"))); 78 dc.SelectObject(pOldFont); 79 } 80 */ 81 } 82 83 void CMainWindow::OnLButtonDown(UINT m_nFlags,CPoint point)//点击鼠标左键画图 84 { 85 //CClientDC dc(this); 86 CPaintDC dc(this); 87 CRect rect; 88 GetClientRect(&rect); 89 dc.Rectangle(rect); 90 91 92 //dc.SetViewportOrg(rect.Width()/2,rect.Height()/2); 93 94 95 //dc.SetROP2(R2_BLACK);//绘图模式:颜色操作;2.1.3 96 //dc.MoveTo(rect.left,rect.top); 97 //dc.LineTo(rect.right,rect.bottom); 98 99 //POINT aPoint[5]={0,0,0,100,100,100,100,0,0,0};100 //dc.Polyline(aPoint,5); //将一系列点用线段连起来101 102 //POINT bPoint[4]={0,100,100,100,100,0};103 //dc.MoveTo(0,0);104 //dc.PolylineTo(bPoint,4); //从当前位置开始将一系列的点用线段连起来,并将当前位置移折致折线的终点105 106 //int nWidth=rect.Width(); //画正弦曲线107 //int nHeight=rect.Height();108 109 //CPoint aPoint[SEGMENTS];110 //for(int i=0;i