程序改错,MFC应用程序,功能在试图窗口中,单击鼠标右键,调用自定义后消息函数,输出文本信息
我是根据电子文档自学的。根据他的提示添加了WM_RBUTTONDOWN消息映射,可是编译的时候老是提示‘;’错误,可是我并没有写冒号。这是为什么呢??以下是View.h和...
我是根据电子文档自学的。根据他的提示添加了WM_RBUTTONDOWN 消息映射,可是编译的时候老是提示‘;’错误,可是我并没有写冒号。这是为什么呢??以下是View.h和view.cpp文件,各位学过vc的帮忙看一下,问题在哪儿。
我会在修改过的地方加上*
//.h文件只增加了开头和结尾两处,中间没修改的我省略了一些,不然字太多
*#define WM_MYMESSAGE WM_USER+1;
#if !defined(AFX_TEXTDBVIEW_H__1E802AC3_B2FD_417B_907F_4AE552C6BE2F__INCLUDED_)
#define AFX_TEXTDBVIEW_H__1E802AC3_B2FD_417B_907F_4AE552C6BE2F__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef _DEBUG // debug version in textDBView.cpp
。。。。。。。。//类定义省略
inline CTextDBDoc* CTextDBView::GetDocument()
{ return (CTextDBDoc*)m_pDocument; }
#endif
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_TEXTDBVIEW_H__1E802AC3_B2FD_417B_907F_4AE552C6BE2F__INCLUDED_)
*afx_msg LRESULT OnMyMessage(WPARAM wParam,LPARAM lParam);
//.cpp文件,省略其中没修改的部分
包含的头文件省略
。。。。
IMPLEMENT_DYNCREATE(CTextDBView, CView)
BEGIN_MESSAGE_MAP(CTextDBView, CView)
//{{AFX_MSG_MAP(CTextDBView)
ON_WM_RBUTTONDOWN()
//}}AFX_MSG_MAP
// Standard printing commands
*就是这一句编译出错 ON_MESSAGE(WM_MYMESSAGE,OnMyMessage)
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
。。。。构造函数和析构函数省略
void CTextDBView::OnDraw(CDC* pDC)
{
CTextDBDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
BOOL CTextDBView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
*添加这个函数
LRESULT CTextDBView::OnMyMessage(WPARAM wParam,LPARAM lParam)
{
CClientDC dc(this);
CFont NewFont,*OldFont;
NewFont.CreatePointFont(150,"黑体",NULL);
OldFont=dc.SelectObject(&NewFont);
dc.TextOut(50,100,"自定义消息WM_MYMESSAGE 的处理函数被调用!");
dc.SelectObject(OldFont);
return 0;
}
void CTextDBView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTextDBView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
#ifdef _DEBUG
void CTextDBView::AssertValid() const
{
CView::AssertValid();
}
void CTextDBView::Dump(CDumpContext& dc) const
。。。
CTextDBDoc* CTextDBView::GetDocument() // non-debug version is inline
。。。
#endif //_DEBUG
void CTextDBView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
* SendMessage(WM_MYMESSAGE);
CView::OnRButtonDown(nFlags, point);
} 展开
我会在修改过的地方加上*
//.h文件只增加了开头和结尾两处,中间没修改的我省略了一些,不然字太多
*#define WM_MYMESSAGE WM_USER+1;
#if !defined(AFX_TEXTDBVIEW_H__1E802AC3_B2FD_417B_907F_4AE552C6BE2F__INCLUDED_)
#define AFX_TEXTDBVIEW_H__1E802AC3_B2FD_417B_907F_4AE552C6BE2F__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef _DEBUG // debug version in textDBView.cpp
。。。。。。。。//类定义省略
inline CTextDBDoc* CTextDBView::GetDocument()
{ return (CTextDBDoc*)m_pDocument; }
#endif
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_TEXTDBVIEW_H__1E802AC3_B2FD_417B_907F_4AE552C6BE2F__INCLUDED_)
*afx_msg LRESULT OnMyMessage(WPARAM wParam,LPARAM lParam);
//.cpp文件,省略其中没修改的部分
包含的头文件省略
。。。。
IMPLEMENT_DYNCREATE(CTextDBView, CView)
BEGIN_MESSAGE_MAP(CTextDBView, CView)
//{{AFX_MSG_MAP(CTextDBView)
ON_WM_RBUTTONDOWN()
//}}AFX_MSG_MAP
// Standard printing commands
*就是这一句编译出错 ON_MESSAGE(WM_MYMESSAGE,OnMyMessage)
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
。。。。构造函数和析构函数省略
void CTextDBView::OnDraw(CDC* pDC)
{
CTextDBDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
BOOL CTextDBView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
*添加这个函数
LRESULT CTextDBView::OnMyMessage(WPARAM wParam,LPARAM lParam)
{
CClientDC dc(this);
CFont NewFont,*OldFont;
NewFont.CreatePointFont(150,"黑体",NULL);
OldFont=dc.SelectObject(&NewFont);
dc.TextOut(50,100,"自定义消息WM_MYMESSAGE 的处理函数被调用!");
dc.SelectObject(OldFont);
return 0;
}
void CTextDBView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTextDBView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
#ifdef _DEBUG
void CTextDBView::AssertValid() const
{
CView::AssertValid();
}
void CTextDBView::Dump(CDumpContext& dc) const
。。。
CTextDBDoc* CTextDBView::GetDocument() // non-debug version is inline
。。。
#endif //_DEBUG
void CTextDBView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
* SendMessage(WM_MYMESSAGE);
CView::OnRButtonDown(nFlags, point);
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询