测试—自定义消息处理
Mydialog.h//*********頭文件
#pragma once
#ifndef Dialog
#define Dialog
// MyDialog 對話框
#include "Resource.h"
#include "afxwin.h"
#include "MyCEditView.h"
#include "MyEditNew.h"
#define MY_MESSAGE (WM_USER+1001)//用戶自定義消息類型號
class MyDialog : public CDialogEx
{
?? ?DECLARE_DYNAMIC(MyDialog)
public:
?? ?MyDialog(CWnd* pParent = NULL); ? // 標準構造函數
?? ?virtual ~MyDialog();
// 對話框數據
?? ?enum { IDD = IDD_DIALOG1 };
protected:
?? ?virtual void DoDataExchange(CDataExchange* pDX); ? ?// DDX/DDV 支持
?? ?DECLARE_MESSAGE_MAP()
public:
?? ?//afx_msg void OnBnClickedOk();
?? ?CEdit tempEDit;
//?? ?CEdit tempEDit2[4];
//?? ?MyCEditView tempEDit3[5];
?? ?afx_msg void OnBnClickedOk();
//?? ?MyCEditView tempEdit2;
//?? ?MyCEditView tempEDit2;
?? ?MyEditNew tempedit4;
?? ?afx_msg void OnBnClickedCancel();
?? ?afx_msg void OnTempButtonClicked();
?? ?afx_msg LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam);
?? ?virtual void OnOK();
?? ?virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
?? ?afx_msg void OnClickedButton1();
};
#endif
//**************************MyDialog.cpp
// MyDialog.cpp : 實現文件
//
#include "stdafx.h"
#include "MFCApplication1.h"
#include "MyDialog.h"
#include "afxdialogex.h"
// MyDialog 對話框
IMPLEMENT_DYNAMIC(MyDialog, CDialogEx)
MyDialog::MyDialog(CWnd* pParent /*=NULL*/)
?? ?: CDialogEx(MyDialog::IDD, pParent)
{
}
MyDialog::~MyDialog()
{
}
void MyDialog::DoDataExchange(CDataExchange* pDX)
{
?? ?CDialogEx::DoDataExchange(pDX);
?? ?DDX_Control(pDX, IDC_EDIT1, tempEDit);
?? ?// ?DDX_Control(pDX, IDC_EDIT6, tempEDit3[3]);
?? ?// ?DDX_Control(pDX, IDC_EDIT2, tempEdit2);
?? ?// ?DDX_Control(pDX, IDC_EDIT2, tempEDit2);
?? ?DDX_Control(pDX, IDC_EDIT2, tempedit4);
}
BEGIN_MESSAGE_MAP(MyDialog, CDialogEx)
?? ?//ON_BN_CLICKED(IDOK, &MyDialog::OnBnClickedOk)
?? ?ON_BN_CLICKED(IDOK, &MyDialog::OnBnClickedOk)
?? ?ON_BN_CLICKED(IDCANCEL, &MyDialog::OnBnClickedCancel)
?? ?ON_BN_CLICKED(12345, &MyDialog::OnTempButtonClicked)
?? ?ON_MESSAGE(MY_MESSAGE, &MyDialog::OnMyMessage)
?? ?ON_BN_CLICKED(IDC_BUTTON1, &MyDialog::OnClickedButton1)
END_MESSAGE_MAP()
// MyDialog 消息處理程序
//void MyDialog::OnBnClickedOk()
//{
//?? ?// TODO: ?在此添加控件通知處理程序代碼
//?? ?CDialogEx::OnOK();
//}
LRESULT MyDialog::OnMyMessage(WPARAM wParam, LPARAM lParam)
{
?? ?CString cstr1;
?? ?CString cstr2;
?? ?cstr1.Format(_T("%d"), wParam);//整型轉字符串
?? ?cstr2.Format(_T("%d"), lParam);//整型轉字符串
?? ?MessageBox(cstr1+cstr2);
?? ?return 0;
}
void MyDialog::OnBnClickedOk()
{
?? ?// TODO: ?在此添加控件通知處理程序代碼
?? ?MyDialog::OnOK();
?? ?//CDialogEx::OnOK();
}
CButton tempButton;
void MyDialog::OnBnClickedCancel()
{
?? ?// TODO: ?在此添加控件通知處理程序代碼
?? ?CRect tempCrect;
?? ?this->GetClientRect(tempCrect);
?? ?int res = tempButton.Create(L"ID_Button", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(tempCrect.right / 2, 0, tempCrect.right / 2 + 100, 0 + 50), this, 12345);
?? ?return;
?? ?CDialogEx::OnCancel();
}
void MyDialog::OnTempButtonClicked()
{
?? ?MessageBox(_T("準備........."));
}
?
void MyDialog::OnOK()
{
?? ?// TODO: ?在此添加專用代碼和/或調用基類
?? ?MessageBox(_T("到這了"));
?? ?CDialogEx::OnOK();
}
LRESULT MyDialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)//message是消息類型,wParam是控件資源ID號,
{
?? ?
?? ?switch (message)
?? ?{
?? ?case WM_COMMAND:
?? ?{
?? ??? ?WPARAM a = wParam;
?? ??? ??? ??? ??? ? ?
?? ??? ??? ??? ??? ? ? if (wParam == 12345)
?? ??? ??? ??? ??? ? ? {
?? ??? ??? ??? ??? ??? ? ? MessageBox(_T("12345"));
?? ??? ??? ??? ??? ? ? }
?? ??? ??? ??? ??? ? ? ?if (wParam == IDOK)
?? ??? ??? ??? ??? ? ? {
?? ??? ??? ??? ??? ??? ??? ?MessageBox(_T("OK"));
?? ??? ??? ??? ??? ??? ??? ?return 0;
?? ??? ??? ??? ??? ? ? }
?? ??? ??? ??? ??? ? ? if (wParam == IDCANCEL)
?? ??? ??? ??? ??? ? ? {
?? ??? ??? ??? ??? ??? ? ? MessageBox(_T("Cancel"));
?? ??? ??? ??? ??? ? ? }
?? ??? ??? ??? ??? ? ? break;
? // ?CString str1 = (LPCTSTR)(wParam);
?? ?//CString str2 = (LPCTSTR)(lParam);
?? ?// MessageBox(_T("到這了"));
? ? //MyDialog::OnBnClickedOk();
?? ??? ??? ??? ??? ? ?
?? ??
?? ?}
?? ?case MY_MESSAGE:
?? ?{
?? ? MessageBox(_T("自定義的一個消息"));
?? ?return CDialogEx::WindowProc(message, wParam, lParam);
?? ?}
?? ?
?? ?default:
?? ??? ?break;
?? ?}
?? ?// TODO: ?在此添加專用代碼和/或調用基類
?? ?return CDialogEx::WindowProc(message, wParam, lParam);
}
void MyDialog::OnClickedButton1()
{
?? ?// TODO: ?在此添加控件通知處理程序代碼
?? ?::SendMessage(this->m_hWnd, MY_MESSAGE, 9890, 3454);
}
?
?
總結
以上是生活随笔為你收集整理的测试—自定义消息处理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [熵编码] 指数哥伦布编码
- 下一篇: tcpmp 编译 源代码分析