Solved

Single Window to Foreground

Posted on 2013-06-12
12
692 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 26

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 26

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 26

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

20 Experts available now in Live!

Get 1:1 Help Now