2017-12-14 9 views
1

내가 코드를 아래로 마우스 클릭 이벤트에 마우스 훅을 생성하고 특정 응용 프로그램 클릭 :

mousehook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookProc, NULL, 0); 

그것은 마우스 클릭에 MouseHookProc 함수를 호출 할 수 있습니다.

하지만 다른 응용 프로그램이나 일반 데스크탑 화면을 클릭해도이 MouseHookProc 함수가 호출됩니다. 어떻게이 훅 이벤트를 현재 애플리케이션으로 만 제한 할 수 있습니까?

답변

0

첫 번째로, 응용 프로그램 내에서 마우스 이벤트 만 찾고 있다면, 아마도 훅 대신 주 메시지 펌프를 사용할 수있을 것이라고 생각합니다.

그러나, 낮은 수준의 마우스 후크를 사용하여이 다른 응용 프로그램에서 때 방해 앱에서 작업을 처리하지 것이다

MSLLHOOKSTRUCT *hookStruct = (MSLLHOOKSTRUCT*)lParam; 
// hMyMainAppHWND in the line below would already be defined 
// and set when your program starts and gets its handle 
if(GetAncestor(WindowFromPoint(hookStruct->pt),GA_ROOTOWNER) != hMyMainAppHWND){ 
    // if the owner of the window where the mouse event occurred 
    // isn't your application's owning window, pass the event on 
    return CallNextHookEx(mousehook, nCode, wParam, lParam); 
} else { 
    // The event occurred on your application 
    // Do your stuff here 
    // Don't forget to do one of the following: 
    // if you want to consume the event, making it as though it never happened: 
    // return TRUE; 
    // if you want the event to be processed as normal: 
    // return CallNextHookEx(mousehook, nCode, wParam, lParam); 
}