Recent

Author Topic: [SOLVED] Form OnTop not working  (Read 437 times)

Pe3s

  • Hero Member
  • *****
  • Posts: 638
[SOLVED] Form OnTop not working
« on: November 27, 2025, 09:46:34 pm »
Hello, I have a question: why isn't the Windows On Top procedure working? I added Windows to uses, is there anything else I missed?
Code: Pascal  [Select][+][-]
  1. procedure TForm1.CheckBox1Change(Sender: TObject);
  2. begin
  3.   if CheckBox1.Checked then
  4.     SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0,
  5.       SWP_NOMOVE or SWP_NOSIZE)
  6.   else
  7.     SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0,
  8.       SWP_NOMOVE or SWP_NOSIZE);
  9. end;  
  10.  
« Last Edit: December 07, 2025, 07:32:27 pm by Pe3s »

Soner

  • Sr. Member
  • ****
  • Posts: 328
Re: Form OnTop not working
« Reply #1 on: November 27, 2025, 11:04:08 pm »
What wand you do? If you want the form to always be in the foreground then do this:
FormStyle:=fsSystemStayOnTop;

tetrastes

  • Hero Member
  • *****
  • Posts: 734
Re: Form OnTop not working
« Reply #2 on: November 27, 2025, 11:34:37 pm »
This state is not permanent, and activates only when you set the CheckBox1.Checked.
To better understand, try this code:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.CheckBox1Change(Sender: TObject);
  2. begin
  3.   if CheckBox1.Checked then
  4.     SetWindowPos(Handle, HWND_BOTTOM, 0, 0, 0, 0,
  5.       SWP_NOMOVE or SWP_NOSIZE)
  6.   else
  7.     SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0,
  8.       SWP_NOMOVE or SWP_NOSIZE);
  9. end;  
  10.  

Pe3s

  • Hero Member
  • *****
  • Posts: 638
Re: Form OnTop not working
« Reply #3 on: December 07, 2025, 07:32:12 pm »
Thank you

 

TinyPortal © 2005-2018