1

I'd like to get the window handle of a new vista-style Open/SaveDialog opened by my Delphi application.

It was possible with the old style dialog by parsing OnShow, but with the new style dialog there is no such event.

Is there a possibility maybe to iterate through all window handles in Windows and get it that way?

Thanks!


Edit: I know that OpenDialog.Handle will return the handle, but only when the dialog is visible (otherwise it's 0). I'd need an event to catch the Handle straight after showing the dialog (without any user action, ie.: select an item in the dialog, changing the file type, etc.).

Steve
  • 2,510
  • 4
  • 34
  • 53
  • 1
    What about the `Handle` property ? – TLama Sep 02 '14 at 11:46
  • 1
    @Steve What are you going to do with the handle? As @TLama says you can obtain the handle via the `Handle` property, but what concerns me is what you do next? Are you going to customise the dialog? – David Heffernan Sep 02 '14 at 11:57
  • Customizations should be done using the [`IFileDialogCustomize`](http://msdn.microsoft.com/en-us/library/windows/desktop/bb775912.aspx) interface. – Remy Lebeau Sep 02 '14 at 15:39
  • David, if you try to obtain the Handle before executing the dialog, it's 0. As far as I know there is no event to get the handle straight after showing the dialog. I'd like to obtain the Handle to bring the window of the dialog to the top in a special case. – Steve Sep 02 '14 at 16:16
  • Can you just fix it by setting the parent properly? – Warren P Sep 02 '14 at 16:24
  • Unfortunately that doesn't work in this case, see my response to my question at: http://stackoverflow.com/questions/25291108/how-to-bring-an-opendialog-hidden-by-another-window-to-the-front – Steve Sep 02 '14 at 17:27
  • So you're actually looking for an event in which you can get the dialog handle, don't you ? If so, then the `OnTypeChange` event should be used when you have any `FileTypes` specified. If not, you should get it in the `OnSelectionChange` (comments on what you should do are in the VCL source). – TLama Sep 02 '14 at 19:08

2 Answers2

2

I'd like to get the window handle of a new vista-style Open/SaveDialog opened by my Delphi application.

This is available through the dialog's Handle property.

Probably the easiest way to catch the event of the dialog showing is to use a CBT hook that you set immediately before showing the dialog, and remove as soon as it closes.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • FWIW, I think you asked the wrong question. I think you need to use `Handle` but also are looking for a notification upon window creation so that you can do something with the handle. Perhaps if you edited the question we could cover that too. – David Heffernan Sep 02 '14 at 20:05
-1

TOpenDialog has an OnShow event which fires just after dialog is shown so you can use to get the OpenDialog.Handle since the handle is already set at that time.

EDIT: After some pepole pointed out that using of OnShow event changes the dialogs apperance I tested this out and can confirm that using of OnShow event realy does change the dialogs aperance.

SilverWarior
  • 7,372
  • 2
  • 16
  • 22
  • Nope, once you attach a handler to the `OnShow` event, it's not a 'Vista style dialog' anymore. – Sertac Akyuz Sep 04 '14 at 18:43
  • What do you mean? I don't see any difference and if I understand TOpenDialog source code there shouldn't be any. – SilverWarior Sep 05 '14 at 06:36
  • You should be seeing the *explorer style* dialog if you attach a handler to `OnShow`. For source, see code in `TOpenDialog.DoExecute`, see the first 'if' test. When `FOnShow` is attached, FileDialogWrapper is not executed, instead `GetOpenFileName` is called. But anyway, the visual difference is really obvious, one is [this](http://i.msdn.microsoft.com/cc300434.fig01%28en-us%29.gif), and the other is [this](http://i.msdn.microsoft.com/ee662146.newsletter_2009_10_Burnett_07.png). Also, that's the reason the question is asked, OnShow is also mentioned in the question. – Sertac Akyuz Sep 05 '14 at 08:43
  • When doing a qick test of ability to get Handle in onShow event I always ended up with Open Dialog as it is shown in second picture you linked. Maybe this due the fact that I'm using Windows 7 and not Windows Vista. Will test it out when I get home. – SilverWarior Sep 05 '14 at 11:53
  • Windows 7 doesn't matter, it use the Vista style dialog too, the IFileOpenDialog. I believe you must have done something wrong while you're testing, as `IFileDialog` simply does not support anything like a callback like the older dialog. See what it supports [here](http://msdn.microsoft.com/en-us/library/bb775876%28v=vs.85%29.aspx). – Sertac Akyuz Sep 05 '14 at 12:02
  • OK just veriried that and you are right. Using OnShow event does change dialogs apearence but on Windows 7 this is less noticable than in the pictures that have been linked. – SilverWarior Sep 05 '14 at 13:15
  • Parsing OnShow was mentioned in the original question. – Steve Sep 05 '14 at 15:53
  • Yes I know but initially I haven't noticed the difference so I suspected that such problem might be related to older versions of Delphi or even related to the Windows version itsself, since I never used Windows Vista. – SilverWarior Sep 06 '14 at 12:25