Solved

Single Window to Foreground

Posted on 2013-06-12
12
686 Views
Last Modified: 2013-06-24
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.
0
Comment
Question by:djdj
  • 6
  • 3
  • 2
  • +1
12 Comments
 
LVL 25

Expert Comment

by:Sinisa Vuk
ID: 39243567
How you create/show your pop-ups? Pase simple code here. There is wrong way how you do it.
0
 
LVL 2

Author Comment

by:djdj
ID: 39243577
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
 
LVL 25

Accepted Solution

by:
Sinisa Vuk earned 250 total points
ID: 39244122
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
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 39247231
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
 
LVL 2

Author Comment

by:djdj
ID: 39248433
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
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 39257706
does all communication go to 1 form/unit ?
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 2

Author Comment

by:djdj
ID: 39257716
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
 
LVL 1

Assisted Solution

by:Syntess
Syntess earned 250 total points
ID: 39265156
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
 
LVL 2

Author Comment

by:djdj
ID: 39265185
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
 
LVL 25

Expert Comment

by:Sinisa Vuk
ID: 39266837
Did you try my example too?
0
 
LVL 2

Author Comment

by:djdj
ID: 39267204
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
 
LVL 2

Author Closing Comment

by:djdj
ID: 39270489
Both solutions seem to have worked equally well.  Thank you!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now