Announcement

Collapse
No announcement yet.

Maus Hook und Childwindow

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Maus Hook und Childwindow

    Hallo erstmal,

    ich habe ein Programm mit einem Panel geschrieben. Dieses Panel ist der Parent einer fremden Applikation welche ich in diesem Panel maximiert anzeige. Soweit so gut jetzt habe ich einen Maushook für dieses externe Programm geschrieben welcher bislang auch immer funktioniert hat doch jetzt wenn ich die externe Applikation als Child anzeige nicht mehr funktioniert.

    Kann mir jemand sagen wieso und wie ich es anders machen kann ??

    Tschöö

    Hendrik

    P.S. Source meines Hooks kommt von Andreas Kosch un folgt.

    library LSMausHook;
    uses WinTypes, WinProcs, Messages;
    var
    HookCount: integer;
    HookHandle: HHook; {$IFDEF WIN32}
    function MouseHookCallBack(Code: integer; Msg: WPARAM;
    MouseHook: LPARAM): LRESULT; stdcall;
    {$ELSE}
    function MouseHookCallBack(Code: integer; Msg: word;
    MouseHook: longint): longint; export;
    {$ENDIF}
    begin
    { If the value of Code is less than 0, we are not allowed to do anything
    except pass it on to the next hook procedure immediately. }
    if Code >= 0 then begin
    { This example does nothing except beep when the right mouse button is pressed. }
    if Msg = WM_RBUTTONDOWN then
    MessageBeep(1); { If you handled the situation, and don't want Windows to process the
    message, do *NOT* execute the next line. Be very sure this is what
    want, though. If you don't pass on stuff like WM_MOUSEMOVE, you
    will NOT like the results you get. }
    Result := CallNextHookEx(HookHandle, Code, Msg, MouseHook);
    end else
    Result := CallNextHookEx(HookHandle, Code, Msg, MouseHook);
    end; { Call InstallHook to set the hook. }
    function InstallHook(SystemHook: boolean; TaskHandle: THandle) : boolean; export;
    {This is really silly, but that's the way it goes. The only way to get the
    module handle, *not* instance, is from the filename. The Microsoft example
    just hard-codes the DLL filename. I think this is a little bit better. }
    function GetModuleHandleFromInstance: THandle;
    var
    s: array[0..512] of char;
    begin
    { Find the DLL filename from the instance value. }
    GetModuleFileName(hInstance, s, sizeof(s)-1);
    { Find the handle from the filename. }
    Result := GetModuleHandle(s);
    end;
    begin
    { Technically, this procedure could do nothing but call SetWindowsHookEx(),
    but it is probably better to be sure about things, and not set the hook
    more than once. You definitely don't want your callback being called more
    than once per message, do you? }
    Result := TRUE;
    if HookCount = 0 then begin
    if SystemHook then
    HookHandle := SetWindowsHookEx(WH_MOUSE, MouseHookCallBack,HInstance, 0)
    else
    { See the Microsoft KnowledgeBase, PSS ID Number: Q92659, for a discussion of
    the Windows bug that requires GetModuleHandle() to be used. }
    HookHandle := SetWindowsHookEx(WH_MOUSE, MouseHookCallBack,
    GetModuleHandleFromInstance,TaskHandle);
    if HookHandle <> 0 then
    inc(HookCount)
    else
    Result := FALSE;
    end else
    inc(HookCount);
    end; { Call RemoveHook to remove the system hook. }
    function RemoveHook: boolean; export;
    begin
    { See if our reference count is down to 0, and if so then unhook. }
    Result := FALSE;
    if HookCount < 1 then exit;
    Result := TRUE;
    dec(HookCount);
    if HookCount = 0 then
    Result := UnhookWindowsHookEx(HookHandle);
    end; { Have we hooked into the system? }
    function IsHookSet: boolean; export;
    begin
    Result := (HookCount > 0) and (HookHandle <> 0);
    end; exports
    InstallHook,
    RemoveHook,
    IsHookSet,
    MouseHookCallBack; { Initialize DLL data. }
    begin
    HookCount := 0;
    HookHandle := 0;
    end.
Working...
X