Recent

Author Topic: How to bring a Form in front over all programs and give it the focus?  (Read 3100 times)

Hartmut

  • Hero Member
  • *****
  • Posts: 910
Re: How to bring a Form in front over all programs and give it the focus?
« Reply #15 on: November 16, 2023, 06:24:59 pm »
What equal Form.BorderStyle?
The value of Form1.BorderStyle = 'bsSizeable'.

Quote
Do you want me to use Threads? I never worked with this and I think this effort would be too much for me.
No.
In Windows, there is only a single thread connected to the input. It is allowed to do SetFocus for it. You can force the thread of your window (MainThreadID) to be connected to the thread of the active window (possibly someone else's application).

Thank you for this idea, but this is complete new to me and I think this effort will be higher then I want to invest. And probably it won't work this way on Linux. Meanwhile I tested my program on Windows and there I do *not* have the disadvantages described in my 1st post. So the problem is - as so often - only on Linux.



Thanks KodeZwerg for your new demo. I already have procedures to show a Form only for a certain time. But that is not what I need in this case. Because I don't know, whether the User is always sitting in front of the screen and always looking to it. He might go to catch some coffee etc. and when he comes back, he must see my Form, until he presses a button to hide the Form.

ASerge

  • Hero Member
  • *****
  • Posts: 2440
Re: How to bring a Form in front over all programs and give it the focus?
« Reply #16 on: November 16, 2023, 06:47:25 pm »
What equal Form.BorderStyle?
The value of Form1.BorderStyle = 'bsSizeable'.
In this case, it is enough:
Code: Pascal  [Select][+][-]
  1. const
  2.   CCmdShow: array[Boolean] of Integer = (SW_SHOW, SW_RESTORE);
  3. var
  4.   Wnd: HWND;
  5. begin
  6.   Wnd := Handle;
  7.   ShowWindow(Wnd, CCmdShow[IsIconic(Wnd)]);
  8.   SetForegroundWindow(Wnd);
  9. end;
If it doesn't work, then the problem is elsewhere in the program.

Hartmut

  • Hero Member
  • *****
  • Posts: 910
Re: How to bring a Form in front over all programs and give it the focus?
« Reply #17 on: November 16, 2023, 07:15:22 pm »
Thank you ASerge for the new suggestion but unfortunately it does not work:

As demo I used the demo from KodeZwerg from reply #5. I replaced his routine "MakeFormVisible" by your code:

Code: Pascal  [Select][+][-]
  1. procedure MakeFormVisible_ASerge(const AForm: TForm);
  2.    const CCmdShow: array[Boolean] of Integer = (SW_SHOW, SW_RESTORE);
  3.    var Wnd: HWND;
  4.    begin
  5.    Wnd := AForm.Handle;
  6.    ShowWindow(Wnd, CCmdShow[IsIconic(Wnd)]);
  7.    SetForegroundWindow(Wnd);
  8.    end;

When I tested on Linux, I exactly got the results which I described in reply #6 with all 3 problems. I'm not surprised about that, because his routine "MakeFormVisible" includes your commands.

Did you test your code on Linux?

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: How to bring a Form in front over all programs and give it the focus?
« Reply #18 on: November 16, 2023, 07:57:23 pm »
Thanks KodeZwerg for your new demo. I already have procedures to show a Form only for a certain time. But that is not what I need in this case. Because I don't know, whether the User is always sitting in front of the screen and always looking to it. He might go to catch some coffee etc. and when he comes back, he must see my Form, until he presses a button to hide the Form.
You are welcome, so remove the timer event or increase the interval .... ?! Be creative!
The created window in demo close itself after 5 second or when user click on it.
What happen after it close is up to you, thats just a suggestion from my side.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

ASerge

  • Hero Member
  • *****
  • Posts: 2440
Re: How to bring a Form in front over all programs and give it the focus?
« Reply #19 on: November 16, 2023, 08:23:36 pm »
Did you test your code on Linux?
No :(. From my first post "In Windows".

 

TinyPortal © 2005-2018