// TestMFCDlg.cpp : implementation file
//
#include "stdafx.h"
#include "TestMFC.h"
#include "TestMFCDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTestMFCDlg dialog
enum {UM_TEST = WM_USER+132};
CTestMFCDlg::CTestMFCDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestMFCDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestMFCDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTestMFCDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestMFCDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
//BEGIN_MESSAGE_MAP(CTestMFCDlg, CDialog)
//#define BEGIN_MESSAGE_MAP(CTestMFCDlg, CDialog)
const AFX_MSGMAP* CTestMFCDlg::GetMessageMap() const
{
return &CTestMFCDlg::messageMap;
}
AFX_COMDAT AFX_DATADEF const AFX_MSGMAP CTestMFCDlg::messageMap =
{
&CDialog::messageMap,
&CTestMFCDlg::_messageEntries[0]
};
AFX_COMDAT const AFX_MSGMAP_ENTRY CTestMFCDlg::_messageEntries[] =
{
// ON_MESSAGE(UM_TEST,OnTestMsg)
{ UM_TEST, 0, 0, 0, AfxSig_lwl, \
(AFX_PMSG)(AFX_PMSGW)(LRESULT (AFX_MSG_CALL CWnd::*)(WPARAM, LPARAM))&OnTestMsg },
//{{AFX_MSG_MAP(CTestMFCDlg)
{ WM_PAINT, 0, 0, 0, AfxSig_vv, \
(AFX_PMSG)(AFX_PMSGW)(void (AFX_MSG_CALL CWnd::*)(void))&OnPaint },
{ WM_MOUSEMOVE, 0, 0, 0, AfxSig_vwp, \
(AFX_PMSG)(AFX_PMSGW)(void (AFX_MSG_CALL CWnd::*)(UINT, CPoint))&OnMouseMove },
{ WM_LBUTTONDOWN, 0, 0, 0, AfxSig_vwp, \
(AFX_PMSG)(AFX_PMSGW)(void (AFX_MSG_CALL CWnd::*)(UINT, CPoint))&OnLButtonDown },
{ WM_COMMAND, (WORD)0, (WORD)IDC_BUTTON1, (WORD)IDC_BUTTON1, AfxSig_vv, (AFX_PMSG)&OnButton1 },
{ WM_COMMAND, (WORD)0, (WORD)IDC_BUTTON2, (WORD)IDC_BUTTON2, AfxSig_vv, (AFX_PMSG)&OnButton2 },
//}}AFX_MSG_MAP
{0, 0, 0, 0, AfxSig_end, (AFX_PMSG)0 }
};
/////////////////////////////////////////////////////////////////////////////
// CTestMFCDlg message handlers
//WM_INITDIALOG
BOOL CTestMFCDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetWindowText("测试");
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTestMFCDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
dc.Ellipse(10,10,200,160);
}
//DEL void CTestMFCDlg::OnMouseMove(UINT nFlags, CPoint point)
//DEL {
//DEL CString str;
//DEL str.Format("x=%d,y=%d",point.x,point.y);
//DEL
//DEL if(MK_CONTROL & nFlags)
//DEL str += " 按下了Ctrl";
//DEL if(MK_SHIFT & nFlags)
//DEL str += " 按下了Shift";
//DEL if(MK_LBUTTON & nFlags)
//DEL str += " 按下了左键";
//DEL if(MK_RBUTTON & nFlags)
//DEL str += " 按下了右键";
//DEL SetWindowText(str);
//DEL
//DEL CDialog::OnMouseMove(nFlags, point);
//DEL }
void CTestMFCDlg::OnMouseMove(UINT nFlags, CPoint point)
{
CDialog::OnMouseMove(nFlags, point);
}
void CTestMFCDlg::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 CTestMFCDlg::OnButton1()
{
// CWnd* p = FindWindow(NULL,"无标题 - 记事本");
// if(p)
// p ->PostMessage(WM_CLOSE);
int nRet = SendMessage(WM_LBUTTONDOWN,MK_LBUTTON|MK_CONTROL|MK_SHIFT,0x00230015);
}
void CTestMFCDlg::OnButton2()
{
int nRet = PostMessage(UM_TEST,3,5);
}
LRESULT CTestMFCDlg::OnTestMsg(WPARAM w, LPARAM l)
{
AfxMessageBox("测试非系统消息");
return 5*(w+l);
}
#if !defined(AFX_TESTMFCDLG_H__09ADBD9A_94AE_4188_BDB3_5E0EB687DC9F__INCLUDED_)
#define AFX_TESTMFCDLG_H__09ADBD9A_94AE_4188_BDB3_5E0EB687DC9F__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/////////////////////////////////////////////////////////////////////////////
// CTestMFCDlg dialog
class CTestMFCDlg : public CDialog
{
// Construction
public:
LRESULT OnTestMsg(WPARAM w,LPARAM l);//用于接收非系统消息
CTestMFCDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data 关联变量
//{{AFX_DATA(CTestMFCDlg)
enum { IDD = IDD_TESTMFC_DIALOG };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// ClassWizard generated virtual function overrides //虚函数回调函数
//{{AFX_VIRTUAL(CTestMFCDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions 消息映射回调函数
//{{AFX_MSG(CTestMFCDlg)
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnButton1();
afx_msg void OnButton2();
//}}AFX_MSG
//DECLARE_MESSAGE_MAP()
private:
static const AFX_MSGMAP_ENTRY _messageEntries[];
protected:
static AFX_DATA const AFX_MSGMAP messageMap;
virtual const AFX_MSGMAP* GetMessageMap() const;
};