Recent

Author Topic: (HACKED)Prevent Mouse Down, MouseUP, Click action when form is being focused?  (Read 1577 times)

jamie

  • Hero Member
  • *****
  • Posts: 6826
Is there an already build in way that I can have the form ignore the mouse action when the mouse is being used to bring the form into view/focus ?

  What is happening is I have a PaineBox on the form and it has a lot of functionality for the mouse events. When I click on this area and maybe others, when the form is not captured, the form will capture, come to the front like it should but the Click process also takes place there, doing stuff that I don't want to happen.

 Does the form class have some sort of property I can set to prevent this or do I need to put in some traps ?


« Last Edit: December 17, 2022, 08:29:00 pm by jamie »
The only true wisdom is knowing you know nothing

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Prevent Mouse Down, MouseUP, Click action when form is being focused?
« Reply #1 on: December 16, 2022, 11:38:29 pm »
...write in your application documentation that your app is reacting on mouse input...  :P

sorry, but i somehow not clearly understand, every application that has windows will react on mouse so why yours should be different?
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

jamie

  • Hero Member
  • *****
  • Posts: 6826
Re: Prevent Mouse Down, MouseUP, Click action when form is being focused?
« Reply #2 on: December 16, 2022, 11:42:01 pm »
I guess you don't get it ?

While the form is out of sight, behind others etc., a click on the form to bring it forward also activates all of the events on the control clicked on.

  I want those clicks to be ignored for child controls until a mouse up is completed after the form has fully been processed and brought to the front.

 From there on, any mouse actions will behave normally.

 does that clear it up a bit ?
The only true wisdom is knowing you know nothing

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Prevent Mouse Down, MouseUP, Click action when form is being focused?
« Reply #3 on: December 16, 2022, 11:52:56 pm »
I guess you don't get it ?
You are correct.

What I can say is:
When a form not having focus it not react on anything (as long you doing it the normal LCL way).
When I click with a mouse on a form (that hasn't got focus) on a button, guess what will happen, right, the button be pressed.
That is how every GUI works.
So again, why should your app work differently?

Or in other words, you can do something strange for each of your controls like "OnMouseEnter = assign a event" and "OnMouseLeave = remove event".
If that be a stable solution you need to find out.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

jamie

  • Hero Member
  • *****
  • Posts: 6826
Re: Prevent Mouse Down, MouseUP, Click action when form is being focused?
« Reply #4 on: December 17, 2022, 12:12:16 am »
I found a property..

"FormIsUpdating"

We will see if that gives us any fruit!
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6826
Re: Prevent Mouse Down, MouseUP, Click action when form is being focused?
« Reply #5 on: December 17, 2022, 12:55:36 am »
Apparently the TFORM class does not have this feature.

I need to process the WM_MOUSEACTIVATE and return this value

MA_ACTIVATEANDEAT
2
Activates the window, and discards the mouse message.

Of course this will only work in windows and also I need to use my Windows unit to make easy to insert message trap because the LCL does not have this message in the list, so it's not cross platform.

The only true wisdom is knowing you know nothing

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10912
  • Debugger - SynEdit - and more
    • wiki
Re: Prevent Mouse Down, MouseUP, Click action when form is being focused?
« Reply #6 on: December 17, 2022, 03:22:26 am »
I am not aware of such an option.

I am not sure in which order events are delivered.

If don't know if Focus and MouseDown are guaranteed to be delivered in a certain order (or whe WM_* messages for those.)

If you receive a MouseDown, and the form is not focused, then you can set a flag, and ignore mouse-click/up.
Clear the flag in MouseUp, LooseFocus, Deactivate.

If Focus comes first (i.e. the flag is not set yet), then set the flag.


  What is happening is I have a PaineBox
I guess you also must catch the Mouseup.

Mind that while the mouse is down, the app can become inactive via keyboard.
So either watch for all the events that can abort, or toggle MouseCapture.

dseligo

  • Hero Member
  • *****
  • Posts: 1480
Re: Prevent Mouse Down, MouseUP, Click action when form is being focused?
« Reply #7 on: December 17, 2022, 03:46:07 am »
While the form is out of sight, behind others etc., a click on the form to bring it forward also activates all of the events on the control clicked on.

How do you click on it if it is "out of sight, behind others"?

jamie

  • Hero Member
  • *****
  • Posts: 6826
Re: Prevent Mouse Down, MouseUP, Click action when form is being focused?
« Reply #8 on: December 17, 2022, 12:03:09 pm »
The PaintBox  covers much of the form except for a Toolbar on top.

Most of the time the Paintbox gets touched because that is the easiest target.

 I also found that the OnActivate only seems to work once which is strange because I would have thought this to work when ever changing forms? Maybe this is a bug?

 As for the focus, I would need a control on the form to focus on and also, I am thinking the mouse comes in first which will start all of this.

 I am glad I got some interest on this, I must not be the only one with this issue.
The only true wisdom is knowing you know nothing

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Prevent Mouse Down, MouseUP, Click action when form is being focused?
« Reply #9 on: December 17, 2022, 12:15:57 pm »
Form OnActivate will just fire once when the form is full loaded and show.
You can use TApplicationProperties OnActivate event to maybe do your strange stuff.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Prevent Mouse Down, MouseUP, Click action when form is being focused?
« Reply #10 on: December 17, 2022, 12:52:37 pm »
To make you happy, here is a working code.
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes , SysUtils , Forms , Controls , Graphics , Dialogs , StdCtrls ,
  9.   ExtCtrls;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     ApplicationProperties1: TApplicationProperties;
  17.     Button1: TButton;
  18.     Timer1: TTimer;
  19.     procedure ApplicationProperties1Activate(Sender: TObject);
  20.     procedure ApplicationProperties1Deactivate(Sender: TObject);
  21.     procedure Timer1Timer(Sender: TObject);
  22.     procedure Button1Click(Sender: TObject);
  23.   strict private
  24.     FAllowClicks: Boolean;
  25.   private
  26.  
  27.   public
  28.  
  29.   end;
  30.  
  31. var
  32.   Form1: TForm1;
  33.  
  34. implementation
  35.  
  36. {$R *.lfm}
  37.  
  38. { TForm1 }
  39.  
  40. procedure TForm1.ApplicationProperties1Activate(Sender: TObject);
  41. begin
  42.   Timer1.Interval := 250; // how many time must window be focused before clicking is allowed....
  43.   Timer1.Enabled := True;
  44. end;
  45.  
  46. procedure TForm1.ApplicationProperties1Deactivate(Sender: TObject);
  47. begin
  48.   Timer1.Enabled := False;
  49.   FAllowClicks := False;
  50. end;
  51.  
  52. procedure TForm1.Timer1Timer(Sender: TObject);
  53. begin
  54.   FAllowClicks := True;
  55.   Timer1.Enabled := False;
  56. end;
  57.  
  58. procedure TForm1.Button1Click(Sender: TObject);
  59. begin
  60.   if FAllowClicks then
  61.     ShowMessage('Allowed');
  62. end;
  63.  
  64. end.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

jamie

  • Hero Member
  • *****
  • Posts: 6826
Re: Prevent Mouse Down, MouseUP, Click action when form is being focused?
« Reply #11 on: December 17, 2022, 04:25:20 pm »
Ok, I can hack a OnActivate, I'll simply implement an event for the form and use that same event for the Application.OnActivate so I won't need to write two different events.

 I will not be using a timer, timers for hackers and invites other issues. I'll set a integer flag that get sets to a numerical position of the clicks in case someone drags the mouse off the form before it gets unclicked.

  I still think the WM_MOUSEACTIVATE control event is better, because it covers all cases, and you can better control the outcome.
The only true wisdom is knowing you know nothing

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
My way is Crossplatform I think, anyway I would like to see your working version, I am not interested in override normal window behavior but like to watch your try.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Ps: Timer I just used to give OnActivate and my Boolean a little time to breath and save posting code of my own Freeze-free Sleep()  8-)
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

 

TinyPortal © 2005-2018