[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 10301
  • Last Modified:

Bring Window to Front (No "Always On Top")

Hello,

How can I bring a window to front once?  No "Always On Top", just bring the window to front once.

Thanks.

rng
0
rng
Asked:
rng
  • 2
3 Solutions
 
Ivanov_GCommented:
if your active form is Form1 then
Form1.BringToFront;

if you want to use it anywhere
if (Self is TForm) then
  (Self as TForm).BringToFront;

you can also use Windows API functions SetForegroundWindow, SetActiveWindow and FlashWindow to achieve something more.
0
 
rngAuthor Commented:
Could you give an example for using those API function ?

Thanks.
rng
0
 
esoftbgCommented:
The BringWindowToTop function brings the specified window to the top of the Z order. If the window is a top-level window, it is activated. If the window is a child window, the top-level parent window associated with the child window is activated.

BOOL BringWindowToTop(
    HWND hWnd       // handle to window
   );      

Parameters:
hWnd
Identifies the window to bring to the top of the Z order.
 

Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

//........ example:

procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
  BringWindowToTop(Form2.Handle);
end;
0
 
Ivanov_GCommented:
procedure TForm1.Button1Click(Sender: TObject);
begin
  // using TForm's method
  Form1.BringToFront;
  // Set window on foreground
  SetForegroundWindow(Form1.Handle);
  // set active
  SetActiveWindow(Form1.Handle);
  // flash Window
  FlashWindow(Form1.Handle, True);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  // flash Window
  FlashWindow(Form1.Handle, True);
end;
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now