Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Single Window to Foreground

Posted on 2013-06-12
12
699 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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
 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

808 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