Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Showing a form on the Windows taskbar

Posted on 2002-07-26
5
Medium Priority
?
279 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
[X]
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
  • 3
  • 2
5 Comments
 
LVL 34

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 34

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 34

Accepted Solution

by:
Slick812 earned 200 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

618 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