Solved

Showing a form on the Windows taskbar

Posted on 2002-07-26
5
237 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

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

16 Experts available now in Live!

Get 1:1 Help Now