⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hello.cpp

📁 WindowsProgrammingFoundation C++学习很好的书籍 希望能够起到帮助
💻 CPP
字号:
#include <afxwin.h>	//使用MFC类库的头文件

#include "hello.h"

//全局对象(变量)在任何其它代码执行以前被创建。
CMyApp myApp;

/////////////////////////////////////////////////////////////////////////
// CMyApp member functions

BOOL CMyApp::InitInstance ()
{
    m_pMainWnd = new CMainWindow;//CWinThread::m_pMainWnd,Use this data member to store a pointer to your thread’s main window object. 
    m_pMainWnd->ShowWindow (m_nCmdShow);
    m_pMainWnd->UpdateWindow (); //WM_PAINT
    return TRUE;
}

/////////////////////////////////////////////////////////////////////////
// CMainWindow message map and member functions

BEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd)//消息映射开始,消息映射像其他的类成员函数一样,可以通过继承来传递。其中需要基类名,这样框架就可以在必要时查找基类的消息映射。
    ON_WM_PAINT ()//消息映射条目,ON_WM_PAINT是一个在MFC头文件Afxmsg_.h中定义的宏,它将处理WM_PAINT消息的条目添加到消息映射中
	ON_WM_LBUTTONDOWN ()
	ON_WM_MOUSEMOVE ()
	ON_WM_LBUTTONUP ()
END_MESSAGE_MAP ()//消息映射结束

CMainWindow::CMainWindow ()
{
    Create (NULL, _T ("The Hello Application"));
//第一个为NULL,使用MFC自行注册一个名为“AfxFrameOrView42d”的窗口类。 
//	Create(NULL,_T ("The Hello Application"),WS_OVERLAPPEDWINDOW,CRect(100,100,500,500));
}


void CMainWindow::OnPaint()//添加成员函数来处理消息,需要参考MSDN,以决定一个消息处理程序接收何种类型的参数以及返回何种类型的值
{
    CPaintDC dc (this);
	dc.Ellipse(0,0,200,200);
}


void CMainWindow::OnLButtonDown(UINT nFlags,CPoint point)//nFlags包含指定鼠标和ctrl和shift键的状态标记,point标识了鼠标点击的位置。
{
	CClientDC dc (this);
    CRect rect;
    GetClientRect (&rect);
    dc.TextOut(point.x,point.y,_T ("Hello, MFC"));	
}

void CMainWindow::OnMouseMove( UINT nFlags, CPoint point )
{
	if (nFlags==MK_LBUTTON) {
		CClientDC dc(this);
		//Invalidate();
		//UpdateWindow();
		dc.TextOut(point.x,point.y,"Hello,MFC!");
	}
}

void CMainWindow::OnLButtonUp( UINT nFlags, CPoint point )
{
		Invalidate();
		UpdateWindow();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -