Squall_FF8 0 Posted Monday at 09:51 AM (edited) Hi guys, I have a modal window above my main form. I want to do something when I click outside the modal window. How I can do that? I tried with MouseMove, but it returns <X,Y> as <-1,-1> when the cursor is outside the modal window. Unfortunately that is not enough because, the same values are returned when you try to do things like resize,.. so there is no guarantee that <-1,-1> is what we need. On top of that MouseUp/Down is not even triggered when you click outside. Edited Monday at 10:23 AM by Squall_FF8 more details Share this post Link to post
PeaShooter_OMO 24 Posted Monday at 11:08 AM (edited) Clicking outside the modal form will not register a mouse down, even through TApplicationEvents.OnMessage. I suspect you might have to use Windows System Hooks with WH_MOUSE. I have not done this before though and as such cannot confirm if this would be the most appropriate way to do it. Edited Monday at 12:19 PM by PeaShooter_OMO Share this post Link to post
limelect 51 Posted 6 hours ago will this help? function MouseHook (Code: integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; var ClientPt : TPoint; begin {------------------------} { Handle Mouse Movements } {------------------------} if (GlobData <> nil) and (Code = HC_ACTION) and ((wParam = WM_MOUSEMOVE) or (wParam = WM_NCMOUSEMOVE)) then begin with PMouseHookStruct(lParam)^ do begin {-----------------------------} { Send the screen coordinates } {-----------------------------} PostMessage(GlobData^.ActiveHandle, WM_APP+2, Pt.X, Pt.Y); {-----------------------------} { Send the window coordinates } {-----------------------------} ClientPt := Pt; ScreenToClient(hwnd, ClientPt); PostMessage(GlobData^.ActiveHandle, WM_APP+3, ClientPt.X, ClientPt.Y); end; end; {-----------------------------------------------} { Call the next hook in the chain } {-----------------------------------------------} Result := CallNextHookEx(0, Code, wParam, lParam); end; function InstallMouseHook (Wnd: HWND): Boolean; stdcall; begin Result := False; if (GlobData = nil) then Exit; if (GlobData^.THook = 0) then begin GlobData^.THook := SetWindowsHookEx(WH_MOUSE, @MouseHook, HInstance, 0); if GlobData^.THook = 0 then Exit; end; GlobData^.ActiveHandle := Wnd; Result := True; end; function UninstallMouseHook: Boolean; stdcall; begin Result := True; if (GlobData = nil) then Exit; if (GlobData^.THook <> 0) then begin if not UnhookWindowsHookEx(GlobData^.THook) then Exit; GlobData^.THook = 0; end; GlobData^.ActiveHandle := 0; Result := True; end; Share this post Link to post
Der schöne Günther 325 Posted 6 hours ago (edited) Can you narrow it down further if the click you want to catch will be Still inside your own application Outside of your application, causing it to lose focus If mouse coordinates matter of you're just interested that a click happened Edited 6 hours ago by Der schöne Günther Share this post Link to post
limelect 51 Posted 5 hours ago I have this project mite help you catch the outside mouse hop it help MyWindowsInspector.zip Share this post Link to post
Squall_FF8 0 Posted 3 minutes ago 5 hours ago, Der schöne Günther said: Can you narrow it down further if the click you want to catch will be Still inside your own application Outside of your application, causing it to lose focus If mouse coordinates matter of you're just interested that a click happened Good questions! I'm interested only to signal, that mouse was clicked outside the modal window. Most likely outside click will be inside the application (usually maximized), but even if it looses the focus I dont need to react. Share this post Link to post