使用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
}

解决方案 »

  1.   

    --------------------Configuration: new - Win32 Debug--------------------
    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)
      

  2.   

    CChildView::~CChildView()
    {
    if(hHook)
    {
    UnhookWindowsHookEx(hHook);
    }BEGIN_MESSAGE...老大,这不是真的吧
      

  3.   

    CChildView::~CChildView()
    {
    if(hHook)
    {
    UnhookWindowsHookEx(hHook);
              }//  <-----------------------------------少了个大括号了,大哥!
    }
      

  4.   

    niying(逆颖) ( ) 信誉:100  2006-6-7 11:25:12  得分: 0  
     
     
       
    CChildView::~CChildView()
    {
    if(hHook)
    {
    UnhookWindowsHookEx(hHook);
              }//  <-----------------------------------少了个大括号了,大哥!
    }
      
     
    ================================以此见得……
      

  5.   

    手误是常事,但我从来不会发现不了,更不会把错的代码粘上来。你的错误说明你对VC的编译环境比较陌生,如果是这个程度的话想把hook程序调试好绝非易事。