mfc message - yamaumima/hello.github.io GitHub Wiki
class CMyApp:public CWinApp
{
virtual BOOL InitInstance()
{
CMainDlg dlg;
dlg.DoModal();
//DialogBox(
// AfxMessageBox("由Win32工程转换而成MFC软件工程");
return TRUE;
}
};
CMyApp theApp;
BEGIN_MESSAGE_MAP(CMainDlg, CDialog)
//{{AFX_MSG_MAP(CMainDlg)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMainDlg message handlers
//WM_INITDIALOG 在对话框还未显示出来时,做准备工作
BOOL CMainDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetWindowText("InitDialog");
HICON hIcon = LoadIcon(AfxGetInstanceHandle(),(LPCSTR)IDI_ICON1);
SetIcon(hIcon,FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CMainDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
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)
{
CString str;
str.Format("x=%d,y=%d",point.x,point.y);
if(MK_CONTROL & nFlags)
str += " 按下了Ctrl";
if(MK_SHIFT & nFlags)
str += " 按下了Shift";
if(MK_LBUTTON & nFlags)
str += " 按下了左键";
if(MK_RBUTTON & nFlags)
str += " 按下了右键";
SetWindowText(str);
CDialog::OnMouseMove(nFlags, point);
}
void CMainDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
dc.Ellipse(10,10,200,150);
}
MK_CONTROL Set if the CTRL key is down.
-
MK_LBUTTON Set if the left mouse button is down.
-
MK_MBUTTON Set if the middle mouse button is down.
-
MK_RBUTTON Set if the right mouse button is down.
-
MK_SHIFT Set if the SHIFT key is down. ————————————————
point
Specifies the x- and y-coordinate of the cursor. These coordinates are always relative to the upper-left corner of the window. ————————————————
原文链接:https://blog.csdn.net/u012881904/article/details/48420019
原文链接:https://blog.csdn.net/u012881904/article/details/48420019