关于MFC Extension dll的一个有关问题,自己弄了一天了,也没有成功,希望各位大家帮忙,小弟跪谢了,真的是已经差了很多资料了,小弟
关于MFC Extension dll的一个问题,自己弄了一天了,也没有成功,希望各位大家帮忙,小弟跪谢了,真的是已经差了很多资料了,小弟在线等!
1.工程名字:Mousehook.
2.添加头文件:Mousehook.h,代码如下:
class AFX_EXT_CLASS CMouseHook: public CObject
{
public:
CMouseHook();
virtual ~CMouseHook();
public:
BOOL StartHook(HWND hWnd);
BOOL StopHook();
}
3.修改Mousehook.cpp文件。
添加头文件:"Mousehook.h".
定义各类句柄:
#pragma data_seg("mydata")
HWND glhPrevTarWnd=NULL;
HWND glhDisplayWnd=NULL;
HHOOK glhHook=NULL;
HINSTANCE glhInstance=NULL;
#pragma data_seg()
全局函数声明:
HWND XYZWindowFromPoint(HWND hwndParent,
POINT point,
UINT uFlags=CWP_SKIPINVISIBLE
);
LRESULT CALLBACK MouseProc(int nCode,WPARAM wparam, LPARAM lparam)
{
LPMOUSEHOOKSTRUCT pMouseHook=(MOUSEHOOKSTRUCT FAR *)lparam;
if(nCode>=0)
{
HWND glhTargetWnd=XYZWindowFromPoint(NULL,pMouseHook->pt);
if(glhTargetWnd!=glhPrevTarWnd)
{
char szCaption[256];
GetWindowText(glhTargetWnd,szCaption,100);
if(IsWindow(glhDisplayWnd))
{
SendMessage(glhDisplayWnd,
WM_SETTEXT,
0,
(LPARAM)(LPCTSTR)szCaption);
}
glhPrevTarWnd=glhTargetWnd;
}
}
return CallNextHookEx(glhHook,nCode,wparam,lparam);
}
4.安装钩子函数:
BOOL CMouseHook::StartHook(HWND hWnd)
{
BOOL bResult=FALSE;
glhHook=SetWindowsHookEx(WH_MOUSE,
MouseProc,
glhInstance,
0);
if(glhHook!=NULL)
{
bResult=TRUE;
}
glhDisplayWnd=hWnd;
return bResult;
}
卸载钩子函数:
BOOL CMouseHook::StopHook()
{
BOOL bResult=FALSE;
if(glhHook)
{
bResult=UnhookWindowsHookEx(glhHook);
if(bResult)
{
glhPrevTarWnd=NULL;
glhDisplayWnd=NULL;
glhHook=NULL;
}
}
return bResult;
}
窗口函数实现代码:
HWND XYZWindowFromPoint(HWND hwndParent,
POINT point,
UINT uFlags
)
{
if(hwndParent!=NULL)
{
return ::ChildWindowFromPointEx(hwndParent,point,uFlags);
}
RECT rect,rectSearch;
HWND pWnd,hWnd,hSearchWnd;
hWnd=::WindowFromPoint(point);
if(hWnd!=NULL)
{
::GetWindowRect(hWnd,&rect);
pWnd=::GetParent(hWnd);
if(pWnd!=NULL)
{
hSearchWnd=hWnd;
do
{
hSearchWnd=::GetWindow(hSearchWnd,GW_HWNDNEXT);
::GetWindowRect(hSearchWnd,&rectSearch);
if(::PtInRect(&rectSearch,point)&& ::GetParent(hSearchWnd)==
pWnd && ::IsWindowVisible(hSearchWnd))
{
if(((rectSearch.right-rectSearch.left)*
(rect.bottom-rect.top))<((rect.right-rect.left)*(rect.bottom-rect.top)))
{
hWnd=hSearchWnd;
::GetWindowRect(hWnd,&rect);
}
}
}while(hSearchWnd!=NULL);
}
}
return hWnd;
}
下面是编译时出现的错误:MouseHook.cpp
D:\MouseHook\MouseHook.cpp(10) : error C2628: 'CMouseHook' followed by 'char' is illegal (did you forget a ';'?)
D:\MouseHook\MouseHook.cpp(10) : error C2538: new : cannot specify initializer for arrays
D:\MouseHook\MouseHook.cpp(48) : error C2665: 'new' : none of the 3 overloads can convert parameter 2 from type 'class CMouseHook []'
Error executing cl.exe.
MouseHook.dll - 3 error(s), 0 warning(s)
希望各位大侠一定要帮忙,小弟多谢了先,我用的是VC6.0,最好给我做个工程,给我发个完整的工程,谢谢了。只要这么多分全给了,我的邮箱是AndyLi_gang@126.com
小弟在线等。
------解决方案--------------------
编译器都给了你足够的提示 还有什么? 自己Debug吧
------解决方案--------------------
1.工程名字:Mousehook.
2.添加头文件:Mousehook.h,代码如下:
class AFX_EXT_CLASS CMouseHook: public CObject
{
public:
CMouseHook();
virtual ~CMouseHook();
public:
BOOL StartHook(HWND hWnd);
BOOL StopHook();
}
3.修改Mousehook.cpp文件。
添加头文件:"Mousehook.h".
定义各类句柄:
#pragma data_seg("mydata")
HWND glhPrevTarWnd=NULL;
HWND glhDisplayWnd=NULL;
HHOOK glhHook=NULL;
HINSTANCE glhInstance=NULL;
#pragma data_seg()
全局函数声明:
HWND XYZWindowFromPoint(HWND hwndParent,
POINT point,
UINT uFlags=CWP_SKIPINVISIBLE
);
LRESULT CALLBACK MouseProc(int nCode,WPARAM wparam, LPARAM lparam)
{
LPMOUSEHOOKSTRUCT pMouseHook=(MOUSEHOOKSTRUCT FAR *)lparam;
if(nCode>=0)
{
HWND glhTargetWnd=XYZWindowFromPoint(NULL,pMouseHook->pt);
if(glhTargetWnd!=glhPrevTarWnd)
{
char szCaption[256];
GetWindowText(glhTargetWnd,szCaption,100);
if(IsWindow(glhDisplayWnd))
{
SendMessage(glhDisplayWnd,
WM_SETTEXT,
0,
(LPARAM)(LPCTSTR)szCaption);
}
glhPrevTarWnd=glhTargetWnd;
}
}
return CallNextHookEx(glhHook,nCode,wparam,lparam);
}
4.安装钩子函数:
BOOL CMouseHook::StartHook(HWND hWnd)
{
BOOL bResult=FALSE;
glhHook=SetWindowsHookEx(WH_MOUSE,
MouseProc,
glhInstance,
0);
if(glhHook!=NULL)
{
bResult=TRUE;
}
glhDisplayWnd=hWnd;
return bResult;
}
卸载钩子函数:
BOOL CMouseHook::StopHook()
{
BOOL bResult=FALSE;
if(glhHook)
{
bResult=UnhookWindowsHookEx(glhHook);
if(bResult)
{
glhPrevTarWnd=NULL;
glhDisplayWnd=NULL;
glhHook=NULL;
}
}
return bResult;
}
窗口函数实现代码:
HWND XYZWindowFromPoint(HWND hwndParent,
POINT point,
UINT uFlags
)
{
if(hwndParent!=NULL)
{
return ::ChildWindowFromPointEx(hwndParent,point,uFlags);
}
RECT rect,rectSearch;
HWND pWnd,hWnd,hSearchWnd;
hWnd=::WindowFromPoint(point);
if(hWnd!=NULL)
{
::GetWindowRect(hWnd,&rect);
pWnd=::GetParent(hWnd);
if(pWnd!=NULL)
{
hSearchWnd=hWnd;
do
{
hSearchWnd=::GetWindow(hSearchWnd,GW_HWNDNEXT);
::GetWindowRect(hSearchWnd,&rectSearch);
if(::PtInRect(&rectSearch,point)&& ::GetParent(hSearchWnd)==
pWnd && ::IsWindowVisible(hSearchWnd))
{
if(((rectSearch.right-rectSearch.left)*
(rect.bottom-rect.top))<((rect.right-rect.left)*(rect.bottom-rect.top)))
{
hWnd=hSearchWnd;
::GetWindowRect(hWnd,&rect);
}
}
}while(hSearchWnd!=NULL);
}
}
return hWnd;
}
下面是编译时出现的错误:MouseHook.cpp
D:\MouseHook\MouseHook.cpp(10) : error C2628: 'CMouseHook' followed by 'char' is illegal (did you forget a ';'?)
D:\MouseHook\MouseHook.cpp(10) : error C2538: new : cannot specify initializer for arrays
D:\MouseHook\MouseHook.cpp(48) : error C2665: 'new' : none of the 3 overloads can convert parameter 2 from type 'class CMouseHook []'
Error executing cl.exe.
MouseHook.dll - 3 error(s), 0 warning(s)
希望各位大侠一定要帮忙,小弟多谢了先,我用的是VC6.0,最好给我做个工程,给我发个完整的工程,谢谢了。只要这么多分全给了,我的邮箱是AndyLi_gang@126.com
小弟在线等。
------解决方案--------------------
编译器都给了你足够的提示 还有什么? 自己Debug吧
------解决方案--------------------