使用SetWindowsHookEx时出错
// ChildView.cpp : implementation of the CChildView class
//
#include "stdafx.h"
#include "MouseHook2.h"
#include "ChildView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChildView
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 handlers
BOOL 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
// TODO: Add your message handler code here
// Do not call CWnd::OnPaint() for painting messages
char str[256];
sprintf(str,"x=%d,y=%d",point.x,point.y);
//构造字符串
dc.TextOut(0,0,str); //显示字符串
}
LRESULT CALLBACK CChildView::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);
//传递钩子信息
}
编译时出错:
C:\Program Files\Microsoft Visual Studio\MyProjects\MouseHook2\ChildView.cpp(20) : error C2664: 'SetWindowsHookExA' : cannot convert parameter 2 from 'long (int,unsigned int,long)' to 'long (__stdcall *)(int,unsigned int,long)'
None of the functions with this name in scope match the target type
这是为什么?