Solved

Extending Common Dialogs (File Open/Save) in IE and Windows Explorer

Posted on 2004-03-30
3
287 Views
Last Modified: 2010-04-05

or in any third party app that uses common dialogs.

I want to add a button and an edit control to the dialogs. I am sure I have seen this done, but don't know how to do it in Delphi. Something to do with OFNHookProc I think.

Some example code would be nice.

Thanks
0
Comment
Question by:Mutley2003
  • 2
3 Comments
 
LVL 10

Expert Comment

by:Jacco
ID: 10729993
Tricky but doable :)

First you have to create a resource file:

<<< Start of NEWTEMPLATE.RC >>>
NEWTEMPLATE DIALOG 0, 0, 316, 76
STYLE 0x404L | WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS
FONT 8, "MS Sans Serif"
LANGUAGE LANG_NEUTRAL , SUBLANG_NEUTRAL
{
 LTEXT "", 1119, 0, 0, 204, 76, SS_LEFT | WS_CHILD | NOT WS_VISIBLE | WS_GROUP
}
<<< End of NEWTEMPLATE.RC >>>

To have this file compiled into your DPR choose Project/Add to project from the menu. Change the file extyension to *.rc and select the newly created NEWTEMPLATE.RC. This will add the following line to you DPR:

{$R 'NEWTEMP.res' 'NEWTEMP.RC'}

The template in this resource will be used by windows to alter the width of the OpenDialog for us. The 316 on the first line indicates this width. (Remember to use "build all" if you do not use "auto save editor files" otherwise the RC will not be recompiled)

The subclassing of TOpenDialog is shown in Unit1.pas below. It is fairly simple: Just create your components in the constructor and set the ParentWindow and positions in the override of DoShow. Then the only thing left to do is tell windows what template to use in the override of the Execute method.

<<< Start of Unit1.pas >>>
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

type
  TSpecialDialog = class(TOpenDialog)
  private
    fButton: TButton;
    fEdit: TEdit;
  protected
    procedure DoShow; override;
  public
    function Execute: Boolean; override;
    constructor Create(aOwner: TComponent); override;
  end;

{ TSpecialDialog }

constructor TSpecialDialog.Create(aOwner: TComponent);
begin
  inherited Create(aOwner);
  fButton := TButton.Create(Self);
  with fButton do
  begin
    Caption := 'Click me...';
  end;
  fEdit := TEdit.Create(Self);
  with fEdit do
  begin
    Text := 'Read me...';
  end;
end;

procedure TSpecialDialog.DoShow;
var
      lStaticRect: TRect;
begin
  inherited DoShow;
  lStaticRect := GetStaticRect;
  fButton.ParentWindow := Handle;
  fButton.Left := lStaticRect.Right + 8;
  fButton.Top := 5;
  fEdit.ParentWindow := Handle;
  fEdit.Left := lStaticRect.Right + 8;
  fEdit.Top := 30;
end;

function TSpecialDialog.Execute: Boolean;
begin
  if ofOldStyleDialog in Options then
    Options := Options -[ofOldStyleDialog];
  Template := 'NEWTEMPLATE';
  Title := 'Test';
  Result := inherited Execute;
end;

{ TSpecialDialog }

procedure TForm1.Button1Click(Sender: TObject);
begin
  with TSpecialDialog.Create(Self) do
  try
    Execute;
  finally
    Free;
  end;
end;

end.
<<< End of Unit1.pas >>>

Regards Jacco

P.S: If you are creating a component use can convert NEWTEMPLATE.RC to NEWTEMPLATE.RES using the commandline tool BRCC32 and then include it in the project putting {$R NEWTEMPLATE.RES} in one of the units.
P.P.S.S: If looked up how to do this on http://www.torry.net/extdialogs.htm PBPreviewDialog component v.4.30.00.00 by Poul Bak
0
 

Author Comment

by:Mutley2003
ID: 10730443

Jacco

Thanks for the pointer to http://www.torry.net/extdialogs.htm
- lots of nice dialog extensions there.

But I don't think your nice code does what I am after - perhaps I did not explain well enough.

Assume a user is running IE or Windows Explorer and clicks on "file save" from within that app.. I then want an enhanced save dialog to appear (extra buttons etc) and if the user clicks on that extra button,   the original app should call a Delphi app or COM object.

I think this VB code does what I want, or maybe not

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=12394&lngWId=1

I still think the answer lies with hooking, somewhere.

I'd be grateful for any further ideas and insights

thanks


 
0
 
LVL 10

Accepted Solution

by:
Jacco earned 500 total points
ID: 10734064
Sorry I don't know how to do that.

It would be an illegal hack though. This way you could make for example Word to not save correctly any more. But I guess with some nifty hooking you could do it.

Regards Jacco
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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 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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

706 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

18 Experts available now in Live!

Get 1:1 Help Now