Solved

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

Posted on 2004-03-30
3
291 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
[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
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Printing problem 2 123
Run video youtube webbrowse 10 85
Dev Express grid collapse 2 53
With Delphi XE10, how to use .Manifest file on WIndows 10 Machines 3 59
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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

737 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