views:

536

answers:

2

Question:

Does anyone know how to change the current directory of an already running open file dialog?

Details:

I have a customized open file dialog (using a custom template to add extra controls) that also has all the validation, existing checks, and creation tests turned off (via the OpenFileName flags).

Turning those things off disables the built-in behavior of the dialog that will cause it to change the currently displayed folder if the user types a folder name into the "file name" combo box and hits the enter key.

I would like to add that behavior back. I can detect when this happens via the hook procedure. I've hidden the OK button, turned off it's accelerator, and put my own "select" button on the control. This means that the only time I get a CDN_FILEOK message is when the user hits enter in the text box after typing.

I can't, however, figure out how to programatically tell the dialog to change the current directory.

I was thinking that I might be able to accomplish this by sending some sort of a message to the SHELLDLL_DefView control in the window, but I haven't been able to find any documentation on it.

+1  A: 

I'm not sure of the direct answer, but if you have SPY++ or any other message snooping program, try checking the messages that go by when you change a normal OpenFileName dialog's directory. You might uncover the answer there (although it's the hard way out).

Someone else might know the answer off-hand though; let's hope they do.

lc
A: 

I was able to figure out a work around.

It turns out that when validation is turned off, typing in a directory name that ends in a "\" will still change the folder being displayed, but typing in a directory name that does not end in a "\" will not.

Using spy++ I was able to see that when enter is hit a WM_COMMAND message will be sent to the common dialog control with a wParam argument whose hi-order word is BN_CLICKED and whose low order word is ID_OK.

If I subclass the common dialog I can intercept the message, change the text in the file name combo box, forward the message through to original subclass procedure, and then change the text back afterwards.

It's a little bit of hack, but it enables me to get the behavior I want from the dialog.

Scott Wisniewski