创建自定义消息,提示错误。
时间:2011-12-01
来源:互联网
1、创建“不注册的”自定义消息“OnHello”。
2、创建“注册的”自定义消息“OnTestmessage”。
创建完成后代码如下:
1、头文件:
// ClassWarzidDlg.h : header file
//
#pragma once
// CClassWarzidDlg dialog
class CClassWarzidDlg : public CDialogEx
{
// Construction
public:
CClassWarzidDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
enum { IDD = IDD_CLASSWARZID_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
HICON m_hIcon;
// 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()
afx_msg LRESULT OnHello(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnTestmessage(WPARAM wParam, LPARAM lParam);
};
2、对应的类文件
// ClassWarzidDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ClassWarzid.h"
#include "ClassWarzidDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
// CClassWarzidDlg dialog
CClassWarzidDlg::CClassWarzidDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CClassWarzidDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CClassWarzidDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CClassWarzidDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_MESSAGE(hello, &CClassWarzidDlg::OnHello)
错误一:Error 1 error C2065: 'hello' : undeclared identifier c:\users\administrator.pc-20110905onbv\desktop\demo\clr\classwizard\classwarzid\classwarzid\classwarziddlg.cpp 66 1 ClassWarzid
错误二: 2 IntelliSense: identifier "hello" is undefined c:\users\administrator.pc-20110905onbv\desktop\demo\clr\classwizard\classwarzid\classwarzid\classwarziddlg.cpp 66 2 ClassWarzid
ON_REGISTERED_MESSAGE(TestMessage, &CClassWarzidDlg::OnTestmessage)
错误三: 3 IntelliSense: identifier "TestMessage" is undefined c:\users\administrator.pc-20110905onbv\desktop\demo\clr\classwizard\classwarzid\classwarzid\classwarziddlg.cpp 67 2 ClassWarzid
END_MESSAGE_MAP()
// CClassWarzidDlg message handlers
BOOL CClassWarzidDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
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
}
void CClassWarzidDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}
// 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 CClassWarzidDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CClassWarzidDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
afx_msg LRESULT CClassWarzidDlg::OnHello(WPARAM wParam, LPARAM lParam)
{
return 0;
}
afx_msg LRESULT CClassWarzidDlg::OnTestmessage(WPARAM wParam, LPARAM lParam)
{
return 0;
}
问题一:这些自定义消息使用“Class Wizard向导”创建的,怎么还会提示错误信息???
问题二:这些错误是什么原因造成的?应该怎样修正???
问题三:“注册的自定义消息”和“没有注册的自定义消息”的差别和联系???
作者: starrychat 发布时间: 2011-12-01
作者: starryplayer 发布时间: 2011-12-01
-----------------------------
之前需定义
C/C++ code
#define hello WM_USER + 0x0001
但一般都大写,如
C/C++ code
#define MSG_HELLO WM_USER + 0x0001
ON_MESSAGE(MSG_HELLO, &CClassWarzidDlg::OnHello)
作者: crybird 发布时间: 2011-12-01
中的标示符hello有定义吗?
作者: VisualEleven 发布时间: 2011-12-01
参见2楼
作者: believe_me 发布时间: 2011-12-01
作者: shen_wei 发布时间: 2011-12-01
作者: oyljerry 发布时间: 2011-12-01
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28