Solved

Showing a form on the Windows taskbar

Posted on 2002-07-26
5
244 Views
Last Modified: 2010-04-04
I'm using the following code to place a child form on the taskbar

procedure TfrmTemplate.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  Params.WndParent := 0;
end;

However whenever a dialog box is shown focus is set to the application main form. When the dialog box is closed focus returns to the child form. Is there any way around this.

Thanks

Jo
0
Comment
Question by:nnbbb09
  • 3
  • 2
5 Comments
 
LVL 33

Expert Comment

by:Slick812
ID: 7182736
What types of "Dialog" boxes do you refer to, if it's a Modal TForm then you can adjust the focus when it closes
0
 
LVL 3

Author Comment

by:nnbbb09
ID: 7183422

It's both modal TForms and also windows open/save dialogs.
Its the setting of focus to the application main form that I want to prevent. eg : If the child form has focus and a TOpenDialog is shown I don't want the application main form to come back into view while the dialog is open. This is what is happening at the moment.
0
 
LVL 33

Expert Comment

by:Slick812
ID: 7184148
you could try the TForm's BringToFront


procedure TForm2.buton_OpenDiagClick(Sender: TObject);
var
FName: String;
begin
if OpenDialog1.Execute then
FName := OpenDialog1.FileName;
Form2.BringToFront
end;

or try

begin
Form3.ShowModal;
SetFocus(Form2.Handle);
end;
0
 
LVL 33

Accepted Solution

by:
Slick812 earned 50 total points
ID: 7186883
After I posted my sugestions above, I re-Read your question and saw that I was thinking about something different than your problem. So I tested a couple of things and came up with these. If you use your CreateParams trick for a modal form and set WndParent to active Form like
"Params.WndParent := Form2.Handle;"
then your active form will not go behind the Main Form. However, I could not get a solution to the Open Dialog Box except to create it from Windows API, so here's some code -


Form1 is the "MainForm", Form2 if the Form with a Title bar, and Form# is the Modal Form called from Form2

{For Form2}
  public
    { Public declarations }
    DialogText: String;
    DialogNumber: Integer;
    procedure CreateParams (var Params : TCreateParams); override;
  end;


var
  Form2: TForm2;

implementation

uses newfade3, Commdlg;

{$R *.DFM}

procedure TForm2.CreateParams(var Params: TCreateParams);
begin
 inherited CreateParams(Params);
 Params.WndParent := 0;
end;

function OpenDialog(Open: Boolean; InitialDir: String; var FileName: String) : Boolean;
var
OFName1 : TOpenFilename;
TempFilename : String;

begin
{if you want to change the Open and save Dialog options
then you will need to look up in API Help index "OPENFILENAME"
and set the parameters of OFName1 below}
Setlength(TempFileName,1026);
  with OFName1 do
    begin
    lStructSize := sizeof(OFName1);
    hwndowner := Form2.Handle;
    hInstance := sysInit.hInstance;
    lpstrFile := @TempFileName[1];
    FillChar(lpstrFile^,1026,0);
    nMaxFile := 1024;

   if Open then
   lpstrTitle:='Open a File'
   else lpstrTitle:='Save this File';
   lpstrDefExt := 'txt';
   if not Open then
   StrLCopy(lpstrFile, @FileName[1],Length(FileName)+1);

   lpstrFilter := 'Text file (*.txt)'#0'*.txt'#0'All files (*.*)'#0'*.*'#0#0;
   if (Length(InitialDir) > 2) then
   lpstrInitialDir := @InitialDir[1]
   else
   lpstrInitialDir := 'C:\';

  lpstrCustomFilter := nil;
  nMaxCustFilter := 0;
  nFilterIndex := 0;
  lpstrFileTitle := nil;
  nMaxFileTitle := 0;
  Flags:=OFN_EXPLORER or OFN_LONGNAMES or OFN_PATHMUSTEXIST or OFN_FILEMUSTEXIST or OFN_HIDEREADONLY;
  lCustData := integer(@OFName1);
  lpTemplateName := nil;
  lpfnHook := nil;
  end;
 
  if Open then
  result := GetOpenFileName(OFName1)
  else Result := GetSaveFileName(OFName1);
  if result then
  begin
  FileName := copy(TempFileName, 1, pos(#0, TempFilename) -1);
  end else
  FileName := '';

end;

procedure TForm2.sbut_OpenDiagClick(Sender: TObject);
var
FileName: String;
begin
FileName := 'New1.txt';
{for the OpenDialog a "True" gives a Open and a False gives a Save
The FileName will be returned with the result filename
and if OpenDialog is false then the Dialog Box was canceled}
if OpenDialog(False, 'C:\Stuff', FileName) then
Label1.Caption := FileName;
end;

procedure TForm2.sbut_ShowForm3Click(Sender: TObject);
begin
Application.CreateForm(TForm3, Form3);
Form3.ShowModal;
Label1.Caption := DialogText+IntToStr(DialogNumber);
end;

end.

- - - - - - - - - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - -  -- - -

{For Form3, the modal form
move Form3 in the menu - Project - Options - Forms, to Availible Forms}

public
    { Public declarations }
    procedure CreateParams (var Params : TCreateParams); override;
  end;

var
  Form3: TForm3;

implementation

{$R *.DFM}

procedure TForm3.CreateParams(var Params: TCreateParams);
begin
 inherited CreateParams(Params);
 Params.WndParent := Form2.Handle;
{set the parent here to the Active Form}
end;

procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Form2.DialogText := Edit1.Text;
Form2.DialogNumber := Edit1.Tag;
{get all the Data from your form here because you will Free it}
Action := caFree;
end;

end.

 - - - - - - - - - - - - - - - - - - - - - - - - -

I did NOT use the Modal Form3 except from From2, if you need to use it from another Form you would have to change the WndParent in the CreateParams, Sorry about the first post
0
 
LVL 3

Author Comment

by:nnbbb09
ID: 7196825
Sorry for the delay in accepting.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

778 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