设为首页 加入收藏

TOP

最简单的MFC程序
2014-11-23 20:26:20 】 浏览:322
Tags:简单 MFC 程序
建立一个Win32空项目后,然后手工打造的最简单的MFC程序:

  1: //stdafx.h

  2: #pragma once

  3: #include

  4: #include

  5: #include

  6: #include 1: //stdafx.cpp

  2: #include "stdafx.h" 1: //MainApp.h

  2: #pragma once

  3: class CMainApp : public CWinAppEx

  4: {

  5: public:

  6: virtual BOOL InitInstance();

  7: }; 1: //MainApp.cpp

  2: #include "stdafx.h"

  3: #include "MainApp.h"

  4: #include "MainWindow.h"

  5:

  6: CMainApp mianApp;

  7:

  8: BOOL CMainApp::InitInstance()

  9: {

  10: CWinAppEx::InitInstance();

  11:

  12: SetRegistryKey(TEXT("Hello MFC app."));

  13:

  14: m_pMainWnd = new CMainWindow();

  15: m_pMainWnd->ShowWindow(SW_SHOW);

  16: m_pMainWnd->UpdateWindow();

  17: return TRUE;

  18: } 1: //MainWindow.h

  2: #pragma once

  3: class CMainWindow : public CFrameWndEx

  4: {

  5: public:

  6: CMainWindow(void);

  7:

  8: DECLARE_MESSAGE_MAP()

  9:

  10: afx_msg void OnPaint();

  11: afx_msg void OnLButtonDown(UINT nFlags, CPoint point);

  12: }; 1: //MainWindow.cpp

  2: #include "stdafx.h"

  3: #include "MainWindow.h"

  4:

  5: CMainWindow::CMainWindow(void)

  6: {

  7: Create(NULL,TEXT("Main window"));

  8: }

  9:

  10: BEGIN_MESSAGE_MAP(CMainWindow, CFrameWndEx)

  11: ON_WM_PAINT()

  12: ON_WM_LBUTTONDOWN()

  13: END_MESSAGE_MAP()

  14:

  15: void CMainWindow::OnPaint()

  16: {

  17: CPaintDC dc(this); // device context for painting

  18: // TODO: Add your message handler code here

  19: CRect rc;

  20: GetClientRect(&rc);

  21: dc.DrawText(TEXT("It is a simple MFC application!"),&rc,DT_VCENTER|DT_SINGLELINE|DT_CENTER);

  22: }

  23:

  24: void CMainWindow::OnLButtonDown(UINT nFlags, CPoint point)

  25: {

  26: // TODO: Add your message handler code here and/or call default

  27: AfxMessageBox(TEXT("Left mouse button clicked!"));

  28: CFrameWndEx::OnLButtonDown(nFlags, point);

  29: }

ScreenShot00078

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇VC自杀程序编程思路 下一篇VC之获得系统安装的反病毒软件[Us..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目