码迷,mamicode.com
首页 > 编程语言 > 详细

最简单的MFC

时间:2016-09-14 23:20:20      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

#include <SDKDDKVer.h>
#include <afxwin.h>         
#include <afxext.h>        
#include <iostream>
#include <sstream>

class MyFrameWnd : public CFrameWnd
{
public:
	MyFrameWnd()
		:CFrameWnd()
	{
		Create(0, TEXT("Hello"));
		
		m_Menu.CreateMenu();
		
		m_Menu.AppendMenu(MF_STRING, 0, _T("文件"));
		
		SetMenu(&m_Menu);
	}
protected:
	void OnPaint()
	{
		CPaintDC dc(this);
		dc.MoveTo(0, 0);
		dc.LineTo(200, 200);
	}

	void OnLButtonDown(UINT flag, CPoint point)
	{
		std::stringstream ss;
		ss << point.x << "," << point.y << "\n";
		::OutputDebugStringA(ss.str().c_str());
	}



	static const AFX_MSGMAP* PASCAL GetThisMessageMap()
	{
		typedef MyFrameWnd ThisClass;						   
		typedef CFrameWnd TheBaseClass;
		static const AFX_MSGMAP_ENTRY _messageEntries[] =  
		{
			{ WM_PAINT, 0, 0, 0, AfxSig_vv, (AFX_PMSG)(AFX_PMSGW)(static_cast< void (AFX_MSG_CALL CWnd::*)(void) > ( &ThisClass :: OnPaint)) },
			
			{ WM_LBUTTONDOWN, 0, 0, 0, AfxSig_vwp, (AFX_PMSG)(AFX_PMSGW)(static_cast< void (AFX_MSG_CALL CWnd::*)(UINT, CPoint) > (&ThisClass :: OnLButtonDown)) },
			{0, 0, 0, 0, AfxSig_end, (AFX_PMSG)0 }
		};

		static const AFX_MSGMAP messageMap = 
		{ &TheBaseClass::GetThisMessageMap, &_messageEntries[0] }; 

		return &messageMap;
	}

	virtual const AFX_MSGMAP* GetMessageMap() const
	{
		return GetThisMessageMap();
	}
private:
	CMenu  m_Menu;
};



class MyApp : public CWinApp
{
public:
	MyApp()
		:CWinApp()
	{

	}

	~MyApp()
	{

	}

	BOOL InitInstance()
	{
		CWinApp::InitInstance();
		MyFrameWnd * frame = new MyFrameWnd;
		m_pMainWnd =  frame;
		m_pMainWnd->ShowWindow(m_nCmdShow);
		m_pMainWnd->UpdateWindow();
		return true;
	}

};

MyApp theApp;

 

最简单的MFC

标签:

原文地址:http://www.cnblogs.com/nmgxbc/p/5873887.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!