• MFC中添加自己定义的消息


    由于自己要做一个拼音输入模块,比如我按下a键后,让它产生一个消息,在消息处理函数里去搜寻a所对应的汉字。由于系统似乎没有提供相应的消息,所以我自己定义了一个!

    具体做法如下:

    集成开发环境vs2005

    基于MFC对话框的程序

    首先在xxxdlg.h的开头添加:#define WM_MYMESSAGE WM_USER+100

    然后在xxxdlg.h的头文件中定义

    	// Generated message map functions
    	virtual BOOL OnInitDialog();
    	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    	afx_msg void OnPaint();
    	afx_msg HCURSOR OnQueryDragIcon();
    	DECLARE_MESSAGE_MAP()
    public:
    	afx_msg void OnBnClickedBtnA();
    	afx_msg void OnBnClickedBtnE();
    	afx_msg LRESULT OnMymessage(WPARAM wparam,LPARAM lparam);
    	afx_msg void OnBnClickedBtnQ();
    	afx_msg void OnBnClickedBtnW();
    	afx_msg void OnBnClickedBtnR();
    其中afx_msg LRESULT OnMymessage(WPARAM wparam, LPARAM lparam);是我自己声明的消息处理函数

    然后到xxxdlg.cpp的文件中的消息映射表中添加映射:

    BEGIN_MESSAGE_MAP(CpytestDlg, CDialog)
    	ON_WM_SYSCOMMAND()
    	ON_WM_PAINT()
    	ON_WM_QUERYDRAGICON()
    	ON_MESSAGE(WM_MYMESSAGE, OnMymessage)
    	//}}AFX_MSG_MAP
    	ON_BN_CLICKED(IDC_BTN_A, &CpytestDlg::OnBnClickedBtnA)
    	ON_BN_CLICKED(IDC_BTN_E, &CpytestDlg::OnBnClickedBtnE)
    	ON_BN_CLICKED(IDC_BTN_Q, &CpytestDlg::OnBnClickedBtnQ)
    	ON_BN_CLICKED(IDC_BTN_W, &CpytestDlg::OnBnClickedBtnW)
    	ON_BN_CLICKED(IDC_BTN_R, &CpytestDlg::OnBnClickedBtnR)
    	ON_BN_CLICKED(IDC_BTN_T, &CpytestDlg::OnBnClickedBtnT)

    其中ON_MESSAGE(WM_MYMESSAGE, OnMymessage)就是我们自己的消息映射

    最后则是充实消息响应函数,我自己的如下所示:

    LRESULT CpytestDlg::OnMymessage(WPARAM wParam, LPARAM lParam) 
    { 
    	// TODO: 处理用户自定义消息 
    	int i = 0;
    	for(i=0;i<396;i++)
    	{
    		if(input ==index[i].PY_input)
    		{SetDlgItemText(IDC_EDT_DEMO, *index[i].PY_mb);
    		break;}
    	}
    	return 0; 
    } 

  • 相关阅读:
    2018.09.25python学习第十天part3
    2018.09.25python学习第十天part2
    2018.09.25python学习第十天part1
    2018.09.21python学习第九天part3
    2018.09.21python学习第九天part2
    2018.09.21python学习第九天part1
    2018.09.20python作业
    Alpha 冲刺(3/10)
    Alpha 冲刺(2/10)
    Alpha 冲刺(1/10)
  • 原文地址:https://www.cnblogs.com/lmzjh/p/4263999.html
Copyright © 2020-2023  润新知