Solved

Focus wnd while rest of app is minimized

Posted on 1998-07-17
3
247 Views
Last Modified: 2010-04-04
How do I activate a window and let the rest of my program be minimized?

It's like this:
I have an app which minimizes and run an OLE-embedd on Word. Then when users press certain buttons in Word I want a to fire up a dialog from my program on top of Word but I do not want the rest of my program to be on top of Word it should stay minimized. Can I accomplish this without having to use DLL's?
0
Comment
Question by:dr_gonzo
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 90 total points
ID: 1358084
Sure it's possible, just make sure that the parent of the popup form isn't the main form of your program, but something like the program manager, here is some code (I learned it from the example at Delphi Cornor of Brendan Delumpa :

Making Secondary Forms Independent of the Main Form

In my application, I want to be able to iconize the main form and still leave the secondary forms displaying on the desktop. Likewise, I want to be able to select
secondary forms without the main form popping up. How can I do this?

Recently a user asked me about this, and I had to do a bit of experimentation before I finally figured it out. And the solution to this problem is actually so simple, you'll
scream (actually, I did all the screaming myself). But it's not something that's necessarily easy to find out nor intuitive (maybe it is for some, but it wasn't for me). But
before I give you the solution, let's discuss the concept that's behind it.

All windowed controls have a parent of some sort; that is, some control that maintains visual control (ie. display) over it. Main forms of an application all point to the
Application as their parent. Likewise, by default, secondary forms point to the main form of the application for parentage. But the neat thing about creating windowed
objects in Delphi (though you need to be careful with some controls) is that you can change the parentage of a control to isolate its visual control, essentially giving it
independence from its default parent. Okay, so how do you do it? You might think that you can reset parentage at FormCreate, but that's not the right place to do it.
The only way to do this is before the window gets created in the first place, and that place is in the CreateParams procedure.

I've discussed CreateParams in previous articles, so I won't go into details about it, though I will brush over what it does. CreateParams is an inherited procedure that
wraps the WinAPI functions CreateWindow and CreateWindowEx that are responsible for a window's initial appearance. It's a convenient way to set display
parameters. With it, we can change the a variable parameter called Params that is a TCreateParams structure (you should look this structure up in the online help) to
affect a number of different things about a form. One of the fields in the TCreateParams structure is WndParent. This parameter specifies the handle of the window that
controls the display of the window being created. By changing this parameter to point another window handle (hint, hint), we can change the default parentage.

So now it's a matter of deciding what window is going to be the secondary form's new parent. In this case, whenever we want to make a secondary form independent of
the main form, we're essentially turning it into its own mini-application without creating a new EXE. So it's best to choose a parent that's at the highest order in the
system. That window is Windows' Desktop Window. Fortunately we have a way of getting its handle by using the WinAPI call GetDesktopWindow, which returns the
handle of the Desktop.

Okay, we've covered all the bases. Now you're going to kill me for belaboring the point. Here's the code:

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm2 = class(TForm)
  private
    { Private declarations }
    //override the CreateParams procedure for any child forms you want to
    //make independent of the main form
    procedure CreateParams(var Params : TCreateParams); override;
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.DFM}

//Here's the implementation of CreateParams
procedure TForm2.CreateParams(var Params : TCreateParams);
begin
  inherited CreateParams(Params); //Don't ever forget to do this!!!
  Params.WndParent := GetDesktopWindow;
end;

end.

Insanely simple, huh? Sorry I took so long to lead up to it, but while the solution was simple, I just couldn't get away from explaining at least a bit of background
information to help those who aren't familiar with the internal workings of the WinAPI. In any case, HAVE AT IT!!!

Greetings, Zif.
0
 

Author Comment

by:dr_gonzo
ID: 1358085
Yepp, simple should have thought about it. But there's one thing left. This trick creates a task bar icon and dialog's really don't do that. How can I get rid of it?
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1358086
;-) Look at the answer pages of Brendan delumpa. He's got an example for that too.

http://wwW.delumpa.com/dc_main.html
 -> tips/articles -> hiding an application from windows

Greetings Zif.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

19 Experts available now in Live!

Get 1:1 Help Now