一个比较搞人的钩子问题!

DanielPrc 2001-12-19 10:01:32
谁能截获mouse右键的消息(钩子),并弹出自己绘制的菜单来呢?
第一步截获我成功了,弹出CMenu也成功了,但弹出具有OWNER属性的CMyMenu时失败了,不知哪位高手能成功解决其中的奥秘?
...全文
125 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
DanielPrc 2001-12-19
  • 打赏
  • 举报
回复
呵呵FromHandle(),没这个API函数...

我的qq号是: 361029
goodbetter 2001-12-19
  • 打赏
  • 举报
回复
老兄,把QQ号告诉我,我们聊聊
yny 2001-12-19
  • 打赏
  • 举报
回复
将CWnd *pWin = new CWnd();
pWin->m_hWnd = mp->hwnd;
该为:
CWnd *pWin=FromHandle(mp->hwnd)
DanielPrc 2001-12-19
  • 打赏
  • 举报
回复
还是没人看?
DanielPrc 2001-12-19
  • 打赏
  • 举报
回复
这是动态库里的关键源程序,还望指教
DanielPrc 2001-12-19
  • 打赏
  • 举报
回复
// hodll.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include "hodll.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "mymenu.h"


#pragma data_seg(".SHARDAT")
static HHOOK hkb=NULL;
FILE *f1;
#pragma data_seg()

HINSTANCE hins;
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//

/////////////////////////////////////////////////////////////////////////////
// CHodllApp

BEGIN_MESSAGE_MAP(CHodllApp, CWinApp)
//{{AFX_MSG_MAP(CHodllApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHodllApp construction


LRESULT __declspec(dllexport)__stdcall CALLBACK KeyboardProc(
int nCode,
WPARAM wParam,
LPARAM lParam)
{
if(nCode == HC_ACTION && wParam == WM_RBUTTONDOWN)

{

MOUSEHOOKSTRUCT *mp = (MOUSEHOOKSTRUCT*)lParam;
CMenuXP *pMenu = new CMenuXP;
pMenu->CreatePopupMenu();

pMenu->SetBackColor(RGB(0xf2, 0xf2, 0xf2));
pMenu->SetSelectedBarColor(RGB(0x66, 0x99, 0xff));
pMenu->SetMenuStyle(CMenuXP::STYLE_XP);


pMenu->AppendMyMenu(我的自绘菜单用到的参数);

CWnd *pWin = new CWnd();
pWin->m_hWnd = mp->hwnd;

pMenu->TrackPopupMenu(TPM_LEFTBUTTON,mp->pt.x , mp->pt.y ,pWin);
}


LRESULT RetVal = CallNextHookEx( hkb, nCode, wParam, lParam );

return RetVal;

}
BOOL __declspec(dllexport)__stdcall installhook()
{
f1=fopen("c:\\report.txt","w");
fclose(f1);
hkb=SetWindowsHookEx(WH_MOUSE,(HOOKPROC)KeyboardProc,hins,0);
return TRUE;
}
BOOL __declspec(dllexport) UnHook()
{

BOOL unhooked = UnhookWindowsHookEx(hkb);
// MessageBox(0,"exit","sasa",MB_OK);
return unhooked;
}


BOOL CHodllApp::InitInstance ()
{

AFX_MANAGE_STATE(AfxGetStaticModuleState());
hins=AfxGetInstanceHandle();
return TRUE;

}
BOOL CHodllApp::ExitInstance ()
{
return TRUE;
}

CHodllApp::CHodllApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CHodllApp object

CHodllApp theApp;
goodbetter 2001-12-19
  • 打赏
  • 举报
回复
把这部分程序贴上来看看
DanielPrc 2001-12-19
  • 打赏
  • 举报
回复
很麻烦的功能吗?我真的很急,还望大家相助一把。。。
DanielPrc 2001-12-19
  • 打赏
  • 举报
回复
倒,没人看吗?
DanielPrc 2001-12-19
  • 打赏
  • 举报
回复
静态函数,只能对调用它的exe有用,对其它窗口就没用了...我用了钩子了...
yny 2001-12-19
  • 打赏
  • 举报
回复
对不起,写错了。

是:CWnd *pWin=CWnd::FromHandle(mp->hwnd)

16,550

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧