使用MFC AppWizard建立一 单文档类型 取消工具栏等特点 工程
//ChildView.cpp文件如下
// ChildView.cpp : implementation of the CChildView class
//#include "stdafx.h"
#include "new.h"
#include "ChildView.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CChildViewHHOOK hHook;
CPoint point;
CChildView *pView;LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam ,LPARAM lParam)
{
if(wParam== WM_MOUSEMOVE || wParam==WM_NCMOUSEMOVE)
{
point =( (MOUSEHOOKSTRUCT *)lParam)->pt;
pView->Invalidate();
}
return CallNextHookEx(hHook,nCode,wParam,lParam);
}CChildView::CChildView()
{
pView=this;
hHook=SetWindowsHookEx(WH_MOUSE,MouseProc,0,GetCurrentThreadId() );}CChildView::~CChildView()
{
if(hHook)
{
UnhookWindowsHookEx(hHook);
}
BEGIN_MESSAGE_MAP(CChildView,CWnd )
//{{AFX_MSG_MAP(CChildView)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChildView message handlersBOOL CChildView::PreCreateWindow(CREATESTRUCT& cs)
{
if (!CWnd::PreCreateWindow(cs))
return FALSE; cs.dwExStyle |= WS_EX_CLIENTEDGE;
cs.style &= ~WS_BORDER;
cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,
::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL); return TRUE;
}void CChildView::OnPaint()
{
CPaintDC dc(this); // device context for painting
char str[256];
sprintf(str,"x=%d,y=%d",point.x,point.y);
dc.TextOut(0,0,str);
// TODO: Add your message handler code here
// Do not call CWnd::OnPaint() for painting messages
}
//ChildView.cpp文件如下
// ChildView.cpp : implementation of the CChildView class
//#include "stdafx.h"
#include "new.h"
#include "ChildView.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CChildViewHHOOK hHook;
CPoint point;
CChildView *pView;LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam ,LPARAM lParam)
{
if(wParam== WM_MOUSEMOVE || wParam==WM_NCMOUSEMOVE)
{
point =( (MOUSEHOOKSTRUCT *)lParam)->pt;
pView->Invalidate();
}
return CallNextHookEx(hHook,nCode,wParam,lParam);
}CChildView::CChildView()
{
pView=this;
hHook=SetWindowsHookEx(WH_MOUSE,MouseProc,0,GetCurrentThreadId() );}CChildView::~CChildView()
{
if(hHook)
{
UnhookWindowsHookEx(hHook);
}
BEGIN_MESSAGE_MAP(CChildView,CWnd )
//{{AFX_MSG_MAP(CChildView)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChildView message handlersBOOL CChildView::PreCreateWindow(CREATESTRUCT& cs)
{
if (!CWnd::PreCreateWindow(cs))
return FALSE; cs.dwExStyle |= WS_EX_CLIENTEDGE;
cs.style &= ~WS_BORDER;
cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,
::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL); return TRUE;
}void CChildView::OnPaint()
{
CPaintDC dc(this); // device context for painting
char str[256];
sprintf(str,"x=%d,y=%d",point.x,point.y);
dc.TextOut(0,0,str);
// TODO: Add your message handler code here
// Do not call CWnd::OnPaint() for painting messages
}
Compiling...
ChildView.cpp
G:\Documents and Settings\Administrator\桌面\new\ChildView.cpp(46) : error C2601: '_GetBaseMessageMap' : local function definitions are illegal
G:\Documents and Settings\Administrator\桌面\new\ChildView.cpp(46) : error C2601: 'GetMessageMap' : local function definitions are illegal
G:\Documents and Settings\Administrator\桌面\new\ChildView.cpp(46) : error C2655: 'messageMap' : definition or redeclaration illegal in current scope
g:\documents and settings\administrator\桌面\new\childview.h(43) : see declaration of 'messageMap'
G:\Documents and Settings\Administrator\桌面\new\ChildView.cpp(46) : error C2655: '_messageEntries' : definition or redeclaration illegal in current scope
g:\documents and settings\administrator\桌面\new\childview.h(43) : see declaration of '_messageEntries'
G:\Documents and Settings\Administrator\桌面\new\ChildView.cpp(57) : error C2601: 'PreCreateWindow' : local function definitions are illegal
G:\Documents and Settings\Administrator\桌面\new\ChildView.cpp(70) : error C2601: 'OnPaint' : local function definitions are illegal
G:\Documents and Settings\Administrator\桌面\new\ChildView.cpp(80) : fatal error C1004: unexpected end of file found
Error executing cl.exe.new.exe - 7 error(s), 0 warning(s)
{
if(hHook)
{
UnhookWindowsHookEx(hHook);
}BEGIN_MESSAGE...老大,这不是真的吧
{
if(hHook)
{
UnhookWindowsHookEx(hHook);
}// <-----------------------------------少了个大括号了,大哥!
}
CChildView::~CChildView()
{
if(hHook)
{
UnhookWindowsHookEx(hHook);
}// <-----------------------------------少了个大括号了,大哥!
}
================================以此见得……