MFC开发
https://www.cnblogs.com/Alliswell-WP/p/CPlusPlus_MFC_01.html
#pragma once #include <afxwin.h> class MyApp :public CWinApp { public: virtual BOOL InitInstance(); }; class MyFrame :public CFrameWnd { public: MyFrame(); //声明宏 提供消息映射机制 DECLARE_MESSAGE_MAP();//消息映射宏,声明必须用在类声明中,即 .h 文件中 afx_msg void OnLButtonDown(UINT, CPoint);//鼠标声明,value //afx_msg void OnChar(UINT, UINT, UINT);//键盘声明 afx_msg void OnChar(UINT nChar,UINT nRepCnt,UINT nFlags); afx_msg void OnPaint();//绘画 };
#include "gui.h" /** //mfc文档 //https://docs.microsoft.com/zh-cn/cpp/mfc/reference/cwnd-class?view=msvc-170#onlbuttondown */ MyApp app; BOOL MyApp::InitInstance() { MyFrame* frame = new MyFrame; frame->ShowWindow(SW_SHOWNORMAL); frame->UpdateWindow(); m_pMainWnd = frame; //保存框架的对象指针 return TRUE; } //分界宏 BEGIN_MESSAGE_MAP(MyFrame, CFrameWnd) ON_WM_LBUTTONDOWN()//鼠标左键按下 key ON_WM_CHAR()//键盘按下 ON_WM_PAINT() END_MESSAGE_MAP() MyFrame::MyFrame() { Create(NULL, TEXT("mfc"));//创建窗口 } void MyFrame::OnLButtonDown(UINT, CPoint point) {//鼠标按下 /* TCHAR buf[1024];//TCHAR 是MFC中的字符数组 wsprintf(buf,TEXT("x=%d,y=%d"),point.x,point.y);//转译 MessageBox(buf);//区别于底层的MessageBox,MFC中实则是MessageBox method 在MSDN中可查 */ CString str; str.Format(TEXT("x=%d,,,y=%d"), point.x, point.y);//格式化 MessageBox(str); //mfc中的字符串 CString //CString str; //str.Format(TEXT("x=%d,,,y=%d"), point.x, point.y);//格式化 //MessageBox(str); } void MyFrame::OnChar(UINT key, UINT nRepCnt, UINT nFlags) {//键盘按下 CString str; str.Format(TEXT("按下了 %c 键"), key); MessageBox(str); } // void MyFrame::OnPaint(){//绘画 CPaintDC dc(this);//this指定绘图设备 //帮助文档,在CDC里找其他能画的图形 dc.TextOutA(100, 100, (CString)TEXT("为了部落")); dc.Ellipse(10, 10, 100, 100);//画椭圆,两点锁定矩形内切圆 }
void MyFrame::OnLButtonDown(UINT, CPoint point) {//鼠标按下 /* TCHAR buf[1024];//TCHAR 是MFC中的字符数组 wsprintf(buf,TEXT("x=%d,y=%d"),point.x,point.y);//转译 MessageBox(buf);//区别于底层的MessageBox,MFC中实则是MessageBox method 在MSDN中可查 */ TCHAR buff[1024]; wsprintf(buff, TEXT("x=%d,,y=%d"), point.x, point.y); MessageBox(buff); //mfc中的字符串 CString //CString str; //str.Format(TEXT("x=%d,,,y=%d"), point.x, point.y);//格式化 //MessageBox(str); }