MFC消息机制

// MFCWin32.cpp : 定义应用程序的入口点。
//

#include "stdafx.h"
#include "MFCWin32.h"
#include "resource.h"
#include "MainDlg.h"
// MFC架构  CwinApp派生类
//必须在全局定义一个对象
//在CwinApp必须要有InitInstance虚函数重写函数
//以InitInstance作为主函数
//消息映射机制
//使用类向导建立一个Cwind派生类
//在窗口派生类中,每一种消息都与一个类成员函数关联
//一个对话框对应一个派生类,然后可以使用消息机制
class CMyApp:public CWinApp
{
	virtual BOOL InitInstance()
	{
		//AfxMessageBox("由win32工程转化成mfc工程");
		//CDialog dlg(IDD_DIALOG1);
		 CMainDlg dlg;
		dlg.DoModal();
		return TRUE;
	}
};
CMyApp theApp;


//int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR IpCndLine,int nCndShow)
//{
//	MessageBox(NULL,"Win32软件启动","win32软件",0);
//	
//	return 0;
//}
///

// MainDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "MFCWin32.h"
#include "MainDlg.h"
#include "afxdialogex.h"


// CMainDlg 对话框

IMPLEMENT_DYNAMIC(CMainDlg, CDialog)
	//构造函数初始化列表
CMainDlg::CMainDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMainDlg::IDD, pParent)
{

}

CMainDlg::~CMainDlg()
{
}

void CMainDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CMainDlg, CDialog)
	//ON_WM_INITMENU()
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()


// CMainDlg 消息处理程序


//void CMainDlg::OnInitMenu(CMenu* pMenu)
//{
//	CDialog::OnInitMenu(pMenu);
//
//	// TODO: 在此处添加消息处理程序代码
//}


void CMainDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	CString str;
	str.Format("x=%d,y=%d",point.x,point.y);
	if(MK_CONTROL&nFlags)
		str+="按下ctrl";
	if(MK_SHIFT&nFlags)
		str+="按下shift";
	//AfxMessageBox(str);
	CDialog::OnLButtonDown(nFlags, point);
}

void CMainDlg::OnMouseMove(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值

	CString str;
	str.Format("x=%d,y=%d",point.x,point.y);
	if(MK_CONTROL&nFlags)
		str+="按下ctrl";
	if(MK_SHIFT&nFlags)
		str+="按下shfit";
	if(MK_LBUTTON&nFlags)
	 str+="按下左键";
	if(MK_RBUTTON&nFlags)
		str+="按下右键";
	SetWindowText(str);
	CDialog::OnMouseMove(nFlags, point);
}


BOOL CMainDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	SetWindowText("InitDialog");
	HICON hIcon=LoadIcon(AfxGetInstanceHandle(),(LPCSTR)IDI_ICON2);
	SetIcon(hIcon,FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值