关闭对话框时,指定的钩子函数没有运行而是正常关闭了对话框,请问我该怎么办??恳请大虾帮助!!
代码如下:
#include <windows.h>
#include "resource.h"
//自定义函数的声明:
LRESULT CALLBACK About1(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK HookProc(int nCode,WPARAM wParam,LPARAM lParam);int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
HHOOK hHook=SetWindowsHookEx(WH_GETMESSAGE,(HOOKPROC)HookProc,hInstance,GetCurrentProcessId());
if(hHook!=NULL)
{
MessageBox(0,"钩子安装失败!",NULL,0);
return 0;
}
MessageBox(0,"钩子已安装!",NULL,0);
DialogBox(hInst, (LPCTSTR)IDD_DIALOGBOX/*指向对话框资源*/, 0,
(DLGPROC)About1/*回调函数名*/);
return 0;
}LRESULT CALLBACK About1(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
if (LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return true;
}
}
return 0;
}
//钩子函数定义:
LRESULT CALLBACK HookProc(int nCode,WPARAM wPARAM,LPARAM lPARAM)
{
MessageBox(0,"钩子函数成功运行!",NULL,0);
return 0;
}
解决了马上加分。
代码如下:
#include <windows.h>
#include "resource.h"
//自定义函数的声明:
LRESULT CALLBACK About1(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK HookProc(int nCode,WPARAM wParam,LPARAM lParam);int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
HHOOK hHook=SetWindowsHookEx(WH_GETMESSAGE,(HOOKPROC)HookProc,hInstance,GetCurrentProcessId());
if(hHook!=NULL)
{
MessageBox(0,"钩子安装失败!",NULL,0);
return 0;
}
MessageBox(0,"钩子已安装!",NULL,0);
DialogBox(hInst, (LPCTSTR)IDD_DIALOGBOX/*指向对话框资源*/, 0,
(DLGPROC)About1/*回调函数名*/);
return 0;
}LRESULT CALLBACK About1(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
if (LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return true;
}
}
return 0;
}
//钩子函数定义:
LRESULT CALLBACK HookProc(int nCode,WPARAM wPARAM,LPARAM lPARAM)
{
MessageBox(0,"钩子函数成功运行!",NULL,0);
return 0;
}
解决了马上加分。
解决方案 »
- 知道怎么获取mainframe的对象指针呢
- 刚学线程,不知道这代码错在哪里,请指点。
- 请问哪里可以下载《深入浅出MFC》简体中文版?
- 类似大头贴的样子,有底图上面在放一张图,各位大侠给些意见。
- 哪里有ASP通过ATL访问SQL数据库的例子?
- 看看侃侃吧
- 等东方来,100分加给你!
- 怎样可以快速的找到树控件的节点
- ========>如何在非模态对话框中响应系统键和加速键?<=================
- 一个对话框,style=popup,border=resizing,建了一个无模式对话框,老是有任务条,怎么去掉它??
- 问个Excel里日期转换为十进制的问题,能答出来的请看看
- 大虾帮忙,如何让多个单文档显示成选项卡形式
HHOOK hHook=SetWindowsHookEx(WH_GETMESSAGE,(HOOKPROC)HookProc,hInstance,GetCurrentThreadId());
(DLGPROC)About1/*回调函数名*/);
{
MessageBox(0,"钩子安装失败!",NULL,0);
return 0;
} 是不是错了,hHook==NULL才是失败,不是NULL应该是成功呀。还有把GetCurrentProcessId()改成 0 试试
[email protected]
dwThreadId
[in] Specifies the identifier of the thread with which the hook procedure is to be associated. If this parameter is zero, the hook procedure is associated with all existing threads running in the same desktop as the calling thread. 如果设成0那就是对所有与当前线程同一个桌面的线程都挂上了 +_+
If the function succeeds, the return value is the handle to the hook procedure. If the function fails, the return value is NULL. To get extended error information, call GetLastError.
请问是不是,钩子安装成功的话,应该在点击DialogBox所指对话框的关闭按钮时,对话框不会关闭而是弹出钩子所指定的MessageBox消息框啊?(我的不知道怎么回事点击一下就直接关上了,GetCurrentProcessId(),hHook!=NULL,hinst都修改过了。)
这个进程不是只有一个线程吗?而且按你说的,我
该如何钩取WindowsPro呢?