全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2747
推到 Plurk!
推到 Facebook!

如何用 HOOK 使滑鼠右鍵失效

尚未結案
ray_pong.tw
一般會員


發表:7
回覆:7
積分:2
註冊:2005-05-09

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-07-07 14:45:20 IP:61.218.xxx.xxx 未訂閱
大家好:    小弟在查閱站內關於HOOK的文章後實做了一個程式,想讓滑鼠右鍵功能失效, 但是卻無法成功,想請高手幫忙指點一下,謝謝!! 以下是小弟實作之程式碼:
    //------------------------------------------------------------------- LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
 {
 //若未掛上Hook鏈或無訊息輸出,就交予下一hook鏈
 if (nCode >=0 )
 {
   if (nCode == HC_ACTION )
    {
     MSG* pEventMsg = (MSG*)lParam;
     switch  (pEventMsg->message)
     {
       case WM_RBUTTONUP:
       // 處理 mouse down      // 自己要處理的部份           break;
     }
   }
   return 0;
 }
 else
 {
  return CallNextHookEx(hHook, nCode, wParam, lParam);
 }
}    
usb_spec
一般會員


發表:3
回覆:2
積分:1
註冊:2005-01-10

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-07-07 17:29:06 IP:60.248.xxx.xxx 未訂閱
你好,你所謂的失效,是指按右鍵不會出現"PopupMenu"嗎? 就我所知,要將訊息不回傳給OS你可以這樣作 //若未掛上Hook鏈或無訊息輸出,就交予下一hook鏈  if (nCode >=0 )  {    if (nCode == HC_ACTION )     {      MSG* pEventMsg = (MSG*)lParam;      switch  (pEventMsg->message)      {        case WM_RBUTTONUP:        // 處理 mouse down      // 自己要處理的部份             return 1; break; } } return 0; } else { return CallNextHookEx(hHook, nCode, wParam, lParam); } }
ray_pong.tw
一般會員


發表:7
回覆:7
積分:2
註冊:2005-05-09

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-07-07 18:09:45 IP:61.218.xxx.xxx 未訂閱
usb_spec 你好: 謝謝你的指教,我的確是想讓右鍵不會出現"PopupMenu" , 剛剛也試過您的方法(加上return 1;),可惜仍然無法成功, 小弟已經讀過HOOK相關的API函數說明,但是還是一頭霧水, 是否我所定義的指標(MSG* pEventMsg = (MSG*)lParam)錯誤呢? 還是期盼各位高手指點一下, 謝謝!!
limeca
中階會員


發表:2
回覆:74
積分:60
註冊:2005-05-11

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-07-07 21:36:19 IP:61.230.xxx.xxx 未訂閱
ray_pong.tw你好 你把你部份的code改成下面這樣就ok了
if (nCode == HC_ACTION )
{
   if(wParam==WM_RBUTTONDOWN )  // 處理 mouse down
       return 1;       return CallNextHookEx(hHook, nCode, wParam, lParam);
   }
}
ray_pong.tw
一般會員


發表:7
回覆:7
積分:2
註冊:2005-05-09

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-07-08 08:55:33 IP:61.218.xxx.xxx 未訂閱
limeca 你好:    謝謝你的回應,但是你給的程式也沒有成功, 小弟使用的是GetMsgProc函式,函式說明如下:
The GetMsgProc hook procedure is an application-defined or library-defined callback function that the system calls whenever the GetMessage function has retrieved a message from an application message queue. Before passing the retrieved message to the destination window procedure, the system passes the message to the hook procedure.     LRESULT CALLBACK GetMsgProc(        int code,        // hook code
    WPARAM wParam,        // removal flag
    LPARAM lParam         // address of structure with message
   );        
     Parameters    code    Specifies whether the hook procedure must process the message. If code is HC_ACTION, the hook procedure must process the message. If code is less than zero, the hook procedure must pass the message to the CallNextHookEx function without further processing and should return the value returned by CallNextHookEx.     wParam    Specifies whether the message has been removed from the queue. This parameter can be one of the following values:     Value        Meaning
PM_NOREMOVE        Specifies that the message has not been removed from the queue. (An application called the PeekMessage function, specifying the PM_NOREMOVE flag.)
PM_REMOVE        Specifies that the message has been removed from the queue. (An application called GetMessage, or it called the PeekMessage function, specifying the PM_REMOVE flag.)
     lParam    Points to an MSG structure that contains details about the message.          Return Values    The return value should be zero.     
由上數說明可知, wParam==WM_RBUTTONDOWN 是不成立的 , 目前我仍在研究該如何使用這些函式 , 如果有結果再上傳與大家分享 , 也期盼有機會與各位先進一起討論!!
limeca
中階會員


發表:2
回覆:74
積分:60
註冊:2005-05-11

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-07-08 09:44:28 IP:202.145.xxx.xxx 未訂閱
喔...我用的不是那個 我用的是WH_MOUSE_LL or WH_MOUSE
limeca
中階會員


發表:2
回覆:74
積分:60
註冊:2005-05-11

發送簡訊給我
#7 引用回覆 回覆 發表時間:2005-07-08 10:49:15 IP:202.145.xxx.xxx 未訂閱
你好~~ 如果你要用GetMsgProc來做的話 就不能用return 1來避免使用者按下滑鼠右鍵(就目前我知道的) 參考下面方法
if (nCode == HC_ACTION )
   {
      TMessage *pEvt=(TMessage*)lParam;
      if (pEvt->WParamLo ==WM_RBUTTONDOWN)
         pEvt->WParamLo =WM_NULL;// 將WM_RBUTTONDOWN的訊息用NULL取代
      return ::CallNextHookEx(hHook, nCode, wParam, lParam);
}
ray_pong.tw
一般會員


發表:7
回覆:7
積分:2
註冊:2005-05-09

發送簡訊給我
#8 引用回覆 回覆 發表時間:2005-07-08 14:26:36 IP:61.218.xxx.xxx 未訂閱
limeca 你好:    小弟剛剛試做你的程式部分已經成功,原來MSG資料結構是要這樣用啊, 但是我還是不太清楚它的結構,是否能麻煩您稍微說明一下呢,謝謝!!    以下是MSG的資料結構定義:    
The MSG structure contains message information from a thread's message queue.     typedef struct tagMSG {     // msg  
    HWND   hwnd;         
    UINT   message; 
    WPARAM wParam; // 此處不知來自何項資料參數或是結構?
    LPARAM lParam; // 此處不知來自何項資料參數或是結構?
    DWORD  time; 
    POINT  pt; 
} MSG; 
     Members    hwnd    Identifies the window whose window procedure receives the message.     message    Specifies the message number.     wParam    Specifies additional information about the message. The exact meaning depends on the value of the message member.     lParam    Specifies additional information about the message. The exact meaning depends on the value of the message member.     time    Specifies the time at which the message was posted.     pt    Specifies the cursor position, in screen coordinates, when the message was posted.          See Also    GetMessage, PeekMessage     
系統時間:2024-05-03 12:16:04
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!