Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Poss. to bring window to front without focus?

Status
Not open for further replies.

LucieLastic

Programmer
May 9, 2001
1,694
GB
hi

I have an app which monitors processes for errors, if an error occurs I want my app to come to the front but not take focus off whatever the user is working in, is this possible? I've tried the following calls but each one makes my monitoring app take focus.

SetForegroundWindow(self.Handle);

Application.BringToFront;


Many thanks in advance
Lou
 
here you go :)

Code:
procedure ForceForegroundNoActivate;

begin
 if IsIconic(Application.Handle) then
  ShowWindow(Application.Handle, SW_SHOWNOACTIVATE);
 SetWindowPos(Application.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOACTIVATE or SWP_NOMOVE);
 SetWindowPos(Application.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOACTIVATE or SWP_NOMOVE);
end;

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Another option to notify the user of an issue is to use a tray icon with a balloon tip. I use this, and added a timer to it, so that if it isn't addressed within a specific amount of time, the balloon tip is shown again.
 
Thanks, Whosrdaddy, that's great!

Majlumbo

I've never used this balloon tip, do you have an example I could 'steal' of you? I have a tray icon next to the clock and I make the application's button flash on the taskbar but if a user has auto hide set, they don't see anything.

Many thanks
Lou
 
Under the Additional Tab, grab a TTrayIcon Component and place it on your form. From the System tab add a TTimer Component.

With the TrayIcon set your BalloonTitle, BalloonTip, BalloonFlags, and BalloonTimeOut properties in the property editor. You can also add a popup menu to add more functionality.

Add two Buttons to the form set their Caption to 'Hide/Show Icon' and 'Show Tip'

Code:
...
private
   BalloonTip_Handled:  Boolean;
public

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
   BalloonTip_Handled := False;
end;

procedure TForm1.HideShowIconClick(Sender: TObject);
begin
   TrayIcon1.Visible := Not TrayIcon1.Visible;
end;

procedure TForm1.ShowTipClick(Sender: TObject);
begin
   TrayIcon1.ShowBalloonHint;
   Timer1.Enabled := True;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
   TrayIcon1.ShowBalloonHint;
end;

procedure TForm1.TrayIconDblClick(Sender:  TObject);
begin
   BalloonTip_Handled := True;
   Timer1.Enabled := False;
   TrayIcon1.Visible := False;
end;
 
Forgot to mention, set your Timer's interval to something appropriate, its default is every 1 second...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top