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);
}