// TODO: Add your message handler code here char str[256]; sprintf(str,"x=%d,y=%d",point.x,point.y); dc.TextOut(0,0,str); // Do not call CWnd::OnPaint() for painting messages }
: cannot convert parameter 2 from 'long (int,unsigned int,long)' to 'long (__stdcall *)(int,unsigned int,long)'
CChildView::MouseProc(this,int nCode,WPARAM wParam,LPARAM lParam)
其实还有一个隐含的参数,this.
因些会和要的原型不匹配,.
普通成员函数在类没有实例化前还没有确定的地址。
LRESULT CALLBACK MouseProc(
int nCode, // hook code
WPARAM wParam, // message identifier
LPARAM lParam // mouse coordinates
);CALLBACK 声明的是回调函数,这种函数由系统通过其函数指针来调用,因此必须是全局或静态函数,不能作为类成员。
所有的钩子函数都是回调函数。
// ChildView.cpp : implementation of the CChildView class
//#include "stdafx.h"
#include "mousehook.h"
#include "ChildView.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CChildView
LRESULT CALLBACK MouseProc(int nCode,WPARAM wParam,LPARAM lParam)
{
//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
// TODO: Add your message handler code here
char str[256];
sprintf(str,"x=%d,y=%d",point.x,point.y);
dc.TextOut(0,0,str);
// Do not call CWnd::OnPaint() for painting messages
}
VC天堂网
www.vcheaven.net
====================
LRESULT WINAPI MouseProc(int nCode,WPARAM wParam,LPARAM lParam)