最简单的MFC

Posted GIS开发

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了最简单的MFC相关的知识,希望对你有一定的参考价值。

#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的主要内容,如果未能解决你的问题,请参考以下文章

最简单的MFC

在 MFC 项目中删除对某些 ActiveX 库的依赖的最简单方法是啥?

代码片段 - Golang 实现简单的 Web 服务器

一个简单的MFC 问题

C++ 代码片段(积累)

MFC静态文本框