Recent

Author Topic: app always on top [solved]  (Read 6279 times)

diego bertotti

  • Jr. Member
  • **
  • Posts: 91
app always on top [solved]
« on: January 15, 2022, 03:17:06 pm »
hi

i need to know how to make a window always on top, on W10.

when i try my own code runs fine while ide run (pressing F9), but fails if a run a .exe file alone

i try with admin rights, and fail.

just open a new app, put a timer at 2000 ms and in it timeout procedure:

Code: Pascal  [Select][+][-]
  1. Procedure TForm1.Timer1Timer(Sender: TObject);
  2. Begin
  3.     //SetActiveWindow(form1.handle);
  4.     form1.Bringtofront;
  5.     form1.SetFocus;
  6.     form1.WindowState:= wsnormal;
  7. end;
  8.  
  9.  

anybody knows why?
« Last Edit: January 17, 2022, 03:08:56 pm by diego bertotti »

winni

  • Hero Member
  • *****
  • Posts: 3051
Re: app always on top
« Reply #1 on: January 15, 2022, 03:58:36 pm »
Hi!

use this:
Code: Pascal  [Select][+][-]
  1.  
  2. FormStyle := fsStayOnTop;

Winni

diego bertotti

  • Jr. Member
  • **
  • Posts: 91
Re: app always on top
« Reply #2 on: January 15, 2022, 04:08:14 pm »
winni

thanks, but fails too

winni

  • Hero Member
  • *****
  • Posts: 3051
Re: app always on top
« Reply #3 on: January 15, 2022, 04:15:00 pm »
Hi!

Lousy Windows.


Try

Code: Pascal  [Select][+][-]
  1. Application.bringToFront;


Winni

GetMem

  • Hero Member
  • *****
  • Posts: 3745
Re: app always on top
« Reply #4 on: January 15, 2022, 04:24:11 pm »
fsStayOnTop property will make the form stay above other forms in your application, while fsSystemStayOnTop is system wide. Which one do you prefer?

diego bertotti

  • Jr. Member
  • **
  • Posts: 91
Re: app always on top
« Reply #5 on: January 15, 2022, 09:27:08 pm »
thanks for replays

i made a mistake describing my problem.

really i want 2 things:

1_ window always on top , and with focus, it means, receiving keystrokes.

2_ why code works inside lazarus ide and why fail running alone, even with admin rights.

getmen: using fsSystemStayOnTop, is always on top, but not always with focus.
winni: don't work.


somebody knows privileges or permisions executable file have when fired inside IDE?
« Last Edit: January 15, 2022, 09:40:32 pm by diego bertotti »

440bx

  • Hero Member
  • *****
  • Posts: 2772
Re: app always on top
« Reply #6 on: January 15, 2022, 09:42:22 pm »
thanks for replays

i made a mistake describing my problem.

really i want 2 things:

1_ window always on top , and with focus, it means, receiving keystrokes.

2_ why code works inside lazarus ide and why fail running alone, even with admin rights.

getmen: using fsSystemStayOnTop, is always on top, but not always with focus.
winni: don't work.
There is a big difference between a window always being on top and a window always having the focus.  Normally, it is not possible for a window to always have the focus because it's the O/S that decides which window should have the focus.  That said, if you need the window to see _all_ keystrokes whether or not they are meant for it or another window then you have to install a system-wide keyboard hook.

Did I misunderstand what you're trying to do ?
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

GetMem

  • Hero Member
  • *****
  • Posts: 3745
Re: app always on top
« Reply #7 on: January 15, 2022, 09:42:57 pm »
@diego bertotti

Quote
getmen: using fsSystemStayOnTop, is always on top, but not always with focus.
It's called ForegroundWindow, which receive input focus. From Microsoft documentation:
Quote
The window with which the user is currently working. The system assigns a slightly higher priority to the thread that creates the foreground window than it does to other threads.
Put a timer to your form, set Interval to 500, Enabled to true, then create an OnTimer event:
Code: Pascal  [Select][+][-]
  1. uses windows;
  2.  
  3. procedure TForm1.Timer1Timer(Sender: TObject);
  4. begin
  5.   if Self.Handle <> GetForegroundWindow then
  6.     SetForegroundWindow(Self.Handle);
  7. end;  

Now your application is always on focus, until you stop the timer. As a side node this is a very abusive approach. As a user, I would delete you application immediately. :)

440bx

  • Hero Member
  • *****
  • Posts: 2772
Re: app always on top
« Reply #8 on: January 15, 2022, 09:50:53 pm »
As a side node this is a very abusive approach. As a user, I would delete you application immediately. :)
It certainly is very abusive and Windows doesn't cooperate with an application with that attitude.  There are a good number of restrictions on setting the foreground window.  I have some doubts that a window can continuously and successfully make itself the foreground window.

I wonder what it is that @diego is _really_ trying to do. 

FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

diego bertotti

  • Jr. Member
  • **
  • Posts: 91
Re: app always on top
« Reply #9 on: January 15, 2022, 09:59:15 pm »
getmem:
Code: Pascal  [Select][+][-]
  1. uses windows;
  2.  
  3. procedure TForm1.Timer1Timer(Sender: TObject);
  4. begin
  5.   if Self.Handle <> GetForegroundWindow then
  6.     SetForegroundWindow(Self.Handle);
  7. end;  

it fail. i try it before and now again. but why all these diferent codes works fine inside ide?

i need these behavior because is only one app running and user only will have an numeric keyboard, no mouse, then if a popup or on

another thing happens, user will can't solve it. its about a special case user

440bx: my first motherboard was a triton 440bx!!!
« Last Edit: January 15, 2022, 10:03:55 pm by diego bertotti »

GetMem

  • Hero Member
  • *****
  • Posts: 3745
Re: app always on top
« Reply #10 on: January 15, 2022, 10:04:01 pm »
@diego, @440bx

Quote
it fail. i try it before. but why all these diferent codes works fine inside ide?
I give up. I seriously doubt that works inside the IDE and fails when your program runs as a standalone application.

Quote
i need these behavior because is only one app running and user only will have an numeric keyboard, no mouse, then if a popup or onther thing happens, user will can't solve.
Simulate ALT + TAB?

diego bertotti

  • Jr. Member
  • **
  • Posts: 91
Re: app always on top
« Reply #11 on: January 15, 2022, 10:23:09 pm »
@diego, @440bx

Quote
it fail. i try it before. but why all these diferent codes works fine inside ide?
I give up. I seriously doubt that works inside the IDE and fails when your program runs as a standalone application.

Quote
i need these behavior because is only one app running and user only will have an numeric keyboard, no mouse, then if a popup or onther thing happens, user will can't solve.
Simulate ALT + TAB?

my apologizes if i disturb you, but if you don't believe me, you can try it, just 5 min to do it with your computer and try it out.

user will not have and ctrl and tab keys. numeric keyboerd normally don't have it

diego bertotti

  • Jr. Member
  • **
  • Posts: 91
Re: app always on top
« Reply #12 on: January 15, 2022, 10:24:50 pm »
thanks for replays

i made a mistake describing my problem.

really i want 2 things:

1_ window always on top , and with focus, it means, receiving keystrokes.

2_ why code works inside lazarus ide and why fail running alone, even with admin rights.

getmen: using fsSystemStayOnTop, is always on top, but not always with focus.
winni: don't work.
There is a big difference between a window always being on top and a window always having the focus.  Normally, it is not possible for a window to always have the focus because it's the O/S that decides which window should have the focus.  That said, if you need the window to see _all_ keystrokes whether or not they are meant for it or another window then you have to install a system-wide keyboard hook.

Did I misunderstand what you're trying to do ?

you got it!!

in was thinking something like this or maybe a windows message with a mouse click with an app coordinates. but app will have a child windows. then keystrokes must be redirected to this and not to mainform of app...i'll see

ASerge

  • Hero Member
  • *****
  • Posts: 1917
Re: app always on top
« Reply #13 on: January 16, 2022, 11:19:00 am »
I give up. I seriously doubt that works inside the IDE and fails when your program runs as a standalone application.
It's possible. From SetForegroundWindow: ...A process can set the foreground window only if one of the following conditions is true:...The process is being debugged...

diego bertotti

  • Jr. Member
  • **
  • Posts: 91
Re: app always on top
« Reply #14 on: January 16, 2022, 01:14:49 pm »
Hi
I found this:

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-locksetforegroundwindow

Remarks
The system automatically enables calls to SetForegroundWindow if the user presses the ALT key or takes some action that causes the system itself to change the foreground window (for example, clicking a background window).

This function is provided so applications can prevent other applications from making a foreground change that can interrupt its interaction with the user.


Ill try

 

TinyPortal © 2005-2018