Recent

Author Topic: [Solved] How to disable Mouse and Keyboard events in ownership state?  (Read 864 times)

loaded

  • Hero Member
  • *****
  • Posts: 825
Hi All,
Code: Pascal  [Select][+][-]
  1. function SetParent(hWndChild:HWND; hWndNewParent:HWND):HWND; external 'user32' name 'SetParent';
Can we stop the mouse and keyboard events coming to the application that we take ownership of and embed in our own form with the command ?
« Last Edit: March 21, 2022, 12:44:54 pm by loaded »
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

balazsszekely

  • Guest
Re: How to disable Mouse and Keyboard events in ownership state?
« Reply #1 on: March 21, 2022, 09:59:58 am »
@loaded
Quote
Can we stop the mouse and keyboard events coming to the application that we take ownership of and embed in our own form with the command ?
Create a low level mouse hook. I did something similar here: https://forum.lazarus.freepascal.org/index.php/topic,28963.msg182081.html#msg182081
Just replace taskbar handle with hWndChild, which is the embedded form's handle. If you wish to completely stop mouse event(s), set the hook result to -1 and immediately exit, something like this:
Code: Pascal  [Select][+][-]
  1. function LowLevelMouseHook(nCode: Integer; wParam: WPARAM; lParam: LPARAM): HRESULT; stdcall;
  2. var
  3.   pmsll: PtagMSLLHookStruct;
  4.   pt: TPOINT;
  5.   Rect: TRECT;
  6. begin
  7.   pmsll := PtagMSLLHookStruct(Pointer(lParam));
  8.   if nCode = HC_ACTION then
  9.   begin
  10.     if wParam = WM_MOUSEMOVE then //set here the event you wish to prevent
  11.     begin
  12.       pt := pmsll^.pt;
  13.       if IsMouseOverEmbeddedForm(pt) then
  14.       begin        
  15.         Result := -1; //stop mouse event to propagate further
  16.         Exit;
  17.       end;
  18.     end;
  19.   end;
  20.   Result := CallNextHookEx(llMouseHook, nCode, wParam, lParam);
  21. end;

You can do the same with the keyboard. Just do a quick forum search, I posted similar code in the past.

loaded

  • Hero Member
  • *****
  • Posts: 825
Re: How to disable Mouse and Keyboard events in ownership state?
« Reply #2 on: March 21, 2022, 12:44:34 pm »
Thank you very much for your answer, my dear master GetMem.
I tried your suggestion, but was not successful. Meanwhile, I tried another method that came to my mind;
I uploaded the external application to the Panel control from my own form, then I solved the problem by disabling the enabled feature.
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

balazsszekely

  • Guest
Re: [Solved] How to disable Mouse and Keyboard events in ownership state?
« Reply #3 on: March 21, 2022, 02:24:22 pm »
@loaded
Quote
I uploaded the external application to the Panel control from my own form, then I solved the problem by disabling the enabled feature.
You're absolutely right, I overthought this one. :)

 

TinyPortal © 2005-2018