日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

测试—自定义消息处理

發布時間:2023/12/18 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 测试—自定义消息处理 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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

}
?

?

總結

以上是生活随笔為你收集整理的测试—自定义消息处理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。