- UID
- 2184
- 积分
- 1230
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-29
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
鼠标钩子程序例子,我这个程序是在objectARX 2004的例子的框架下修改来的,目的是捕获鼠标滚轮和中键的消息,并设置相应的系统变量的值,程序中用到了USERI4和USERI5两个系统变量,lisp程序通过检查这两个变量的值来获得鼠标的状态。本来想利用函数AcedPutSym()设置修改一个lisp变量的值,但没能成功,不知道是为什么,所以改为修改系统变量的值。
程序如下:
代码:

- [FONT=courier new]
- //////////////////////////////////////////////////////////////
- //
- // Includes
- //
- //////////////////////////////////////////////////////////////
- #define _AFX_NOFORCE_LIBS // we do not want to link to MFC DLLs or libs
- #ifdef _DEBUG
- #define WAS_DEBUG
- #undef _DEBUG
- #endif
- #include "afxwin.h" // need this because rxmfcapi.h needs windows header.
- #ifdef WAS_DEBUG
- #undef WAS_DEBUG
- #define _DEBUG
- #endif
- #include "aced.h"
- #include "adslib.h"
- #include "rxmfcapi.h"
- //////////////////////////////////////////////////////////////
- //
- // Standard C Test function
- //
- //////////////////////////////////////////////////////////////
- void mouse(); // ARX callbacks
- void unmouse(); // ARX callbacks
- BOOL filterMouse(MSG *pMsg); // hook function for trace mouse wheel
- // preventing from inserting the same hook twice.
- static BOOL mouseDone = FALSE;
- //////////////////////////////////////////////////////////////
- //
- // Rx interface
- //
- //////////////////////////////////////////////////////////////
- void initApp()
- {
- acedRegCmds->addCommand( "Mwheel", // Group name
- "mwheel", // Global function name
- "mwheel", // Local function name
- ACRX_CMD_MODAL, // Type
- &mouse ); // Function pointer
- acedRegCmds->addCommand( "Mwheel", // Group name
- "unmwheel", // Global function name
- "unmwheel", // Local function name
- ACRX_CMD_MODAL, // Type
- &unmouse ); // Function pointer
-
- acutPrintf( ".OK!\n" );
- }
- void unloadApp()
- {
- // Remove the command group because we are unloading
- //
- acedRegCmds->removeGroup( "Mwheel" );
- // Removing all hooks
- if (mouseDone == TRUE)
- acedRemoveFilterWinMsg(filterMouse);
- }
- //////////////////////////////////////////////////////////////
- //
- // Entry point
- //
- //////////////////////////////////////////////////////////////
- extern "C" AcRx::AppRetCode acrxEntryPoint( AcRx::AppMsgCode msg, void* pkt)
- {
- switch( msg )
- {
- case AcRx::kInitAppMsg:
- initApp();
- acrxUnlockApplication(pkt);
- acrxDynamicLinker->registerAppMDIAware(pkt);
- break;
- case AcRx::kUnloadAppMsg:
- unloadApp();
- break;
- default:
- break;
- }
- return AcRx::kRetOK;
- }
- BOOL filterMouse(MSG *pMsg)
- {
- static long ptx=0;
- static long pty=0;
- static short zdt=0;
- struct resbuf rb;
- if (pMsg->message == WM_MOUSEWHEEL) //鼠标滚轮消息
- {
- if (LOWORD(pMsg->wParam) == MK_CONTROL)
- {
- return FALSE; // continue
- }
- else
- {
- // acutPrintf("Mouse Wheel!");
- zdt=(short)HIWORD(pMsg->wParam);
- // acutPrintf("%d\n",zdt);
- rb.restype = RTSHORT;
- rb.resval.rint = zdt;
- acedSetVar("USERI5", &rb);
- ptx = LOWORD(pMsg->lParam);
- if (zdt == 120)
- pty = HIWORD(pMsg->lParam)-1;
- if (zdt == -120)
- pty = HIWORD(pMsg->lParam)+1;
- SetCursorPos(ptx,pty);
- return TRUE; // continue
- }
- }
- if (pMsg->message == WM_MBUTTONDOWN) //鼠标中键按下消息
- {
- rb.restype = RTSHORT;
- rb.resval.rint = 100;
- acedSetVar("USERI4", &rb);
- return FALSE; // continue
- }
- if (pMsg->message == WM_MBUTTONUP) //鼠标中键抬起消息
- {
- rb.restype = RTSHORT;
- rb.resval.rint = 0;
- acedSetVar("USERI4", &rb);
- return FALSE; // continue
- }
- return FALSE; // continue
- }
- ///////////////////////
- void mouse()
- {
- if (mouseDone == TRUE) // already has the hook?
- return ;
-
- acutPrintf( "mouseing...\n" );
- if (acedRegisterFilterWinMsg(filterMouse) == FALSE) //添加acadhook
- {
- acutPrintf("Can't register Windows Msg hook - VH - mouse\n");
- return ;
- }
- else
- {
- mouseDone = TRUE;
- return ;
- }
- }
- void unmouse()
- {
-
- if (mouseDone == TRUE)
- {
- acedRemoveFilterWinMsg(filterMouse); //卸载acadhook
- mouseDone = FALSE;
- }
- if (mouseDone2 == TRUE)
- {
- acedRemoveFilterWinMsg(filterMouse2);
- mouseDone2 = FALSE;
- }
- }
- [/FONT]
|
评分
-
查看全部评分
|