Single Window to Foreground

Hi, all...

I have an application which runs primarily in the background (it has visible windows, but most of the time users aren't interacting with the application and just allow it to run in the background).  It also generates popup alerts in the bottom-right corner of the screen to notify users of situations that require attention.

The problem is that whenever one of the popup windows shows up, my entire application comes to the foreground.  I've got it where it doesn't steal focus from other applications, but the very act of showing the popup window brings all other application windows to the foreground, covering up whatever a user is working on.

So this isn't a matter of focus, it is a matter of wanting ONLY the popup window to show up in front of OTHER application windows without bringing the rest of MY application windows to the foreground.

I've tried everything I can think of and haven't come up with a solution.  The moment that ANY of my application windows comes to the foreground, they all do.  But I want only the one.  But without being top-most.  I thought I could do it by having the notification window not be owned by the application, but even that doesn't solve the problem.

So, the requirements are...

1. Show a popup window on top of other applications without stealing focus.
2. Show the popup window without my application's other windows also coming to the front.
3. Allow users to click on popup window to dismiss it without my application's other windows receiving focus or coming to the front.
LVL 2
djdjAsked:
Who is Participating?
 
Sinisa VukConnect With a Mentor Commented:
I've tested with this:

- in Notify form add:
procedure TfrmNotify.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  ShowWindow(Self.Handle, SW_HIDE);
end;

Open in new window


... in main form where you call form:
    fm := TfrmNotify.CreateParented(GetDesktopWindow);
    fm.BorderStyle := bsToolWindow; // bsDialog;  //you may left what you have
    fm.Visible := True;
    //make topmost
    SetWindowPos(fm.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE);

Open in new window


... additional info about window:
http://www.angelfire.com/hi5/delphizeus/morewnds.html
0
 
Sinisa VukCommented:
How you create/show your pop-ups? Pase simple code here. There is wrong way how you do it.
0
 
djdjAuthor Commented:
fm:=TfrmNotify.create(nil);
fm.FormShow(fm);
ShowNoActivate(fm);

procedure ShowNoActivate(Form: TCustomForm);
begin
  ShowWindow(form.handle,SW_SHOWNOACTIVATE);
  Form.visible:=true;
end;

The .visible property for the form at design time is false.

As mentioned previously, the problem I'm having isn't that the form itself is stealing focus.  It is that ALL forms associated with the application are coming to the front.  Whatever application has the focus at the time does continue to retain focus, even if it is hidden behind my app.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
Geert GOracle dbaCommented:
separating the notification from the background app might solve your problem

to show 1 form, the app must be activated, thus also activating all other forms which aren't invisible

if you separate the notification system from the app,
thus creating a new app with only the notification system no other windows would become visible
0
 
djdjAuthor Commented:
Is this the only way to prevent display/activation of one window from bringing all other application windows to the foreground?  

While technically possible, it would be very difficult to separate notifications from the main app... there is a great deal of communication that goes on between the notification windows and the rest of the app, so making this change would be very time consuming.
0
 
Geert GOracle dbaCommented:
does all communication go to 1 form/unit ?
0
 
djdjAuthor Commented:
Not really.  The main unit is the largest, but there are about 70 other forms each with its own code.

The notification window is just one of those forms, with its own logic for handling mouse clicks.  But it interacts with the rest of the application, so if the user clicks on a popup message for an incoming support ticket, for example, that ticket window is opened.  Or for an new discussion comment, the comment thread window is opened.  And those actions take place without using any code in the main unit.
0
 
SyntessConnect With a Mentor Commented:
You are on the right track, there is nothing wrong with your ShowNoActive procedure. All you have to do is override the CreateParams procedure of TfrmNotify and add this:
  inherited;
  Params.ExStyle := Params.ExStyle or WS_EX_TOOLWINDOW;
  Params.WndParent := HWND_DESKTOP;

Open in new window


PS: unfortunately, this will still bring your application to the foreground when clicked, but it solves point 1 and 2.
0
 
djdjAuthor Commented:
I just implemented that and so far it looks okay.  I'll keep my eyes on it for a couple days, but for now it looks like this solution took care of the problem.

Thank you!
0
 
Sinisa VukCommented:
Did you try my example too?
0
 
djdjAuthor Commented:
Sinisav,

No, sorry... somehow I missed it.

The vast majority of your code contains things I was already doing, or don't apply (like the FormClose event... each popup window is its own object that is destroyed when it is dismissed).  The only thing that I wasn't already doing was CreateParented.

I'll try it as well and award points proportionally if it works.
0
 
djdjAuthor Commented:
Both solutions seem to have worked equally well.  Thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.