Solved

Showing a form on the Windows taskbar

Posted on 2002-07-26
5
230 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
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry for the delay in accepting.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

9 Experts available now in Live!

Get 1:1 Help Now