C # setting controls in the save dialog - how to disable the parent folder button?

I work from a sample project here: http://www.codeproject.com/Articles/8086/Extending-the-save-file-dialog-class-in-NET

I hid the address / location bar at the top and made other changes, but I can’t disable the button that allows me to go to the parent folder throughout my life. Ist is in the ToolbarWindow32 class, which is the problem. This is what I have at the moment, but it does not work:

int parentFolderWindow = GetDlgItem(parent, 0x440); //Doesn't work //ShowWindow((IntPtr)parentFolderWindow, SW_HIDE); //40961 gathered from Spy++ watching messages when clicking on the control // doesn't work //SendMessage(parentFolderWindow, TB_ENABLEBUTTON, 40961, 0); // doesn't work //SendMessage(parentFolderWindow, TB_SETSTATE, 40961, 0); //Comes back as '{static}', am I working with the wrong control maybe? GetClassName((IntPtr)parentFolderWindow, lpClassName, (int)nLength); 

Alternatively, if they use the parent folder button and go where I do not want them, I can look at the new directory in which they land, is there a way to make the navigation go back

Screenshothot

Edit: Added screenshot

+7
c # savefiledialog windows-messages
source share
3 answers

// Returns as '{static}', can I work with the wrong control?

You know that you are using the wrong control, you expected to see "ToolbarWindow32" back. A very important issue common to Codeproject.com code is that this code no longer works as published. Since 2004, Windows has changed a lot. Vista has since become the first version to add a completely new set of shell dialogs; they are based on IFileDialog . Much has improved compared to its predecessor, in particular, setting up a dialog is much cleaner using the IFileDialogCustomize interface. Actually, not what you want to do, and the settings do not include manipulation using the navigation bar.

The IFileDialogEvents interface provides the events you are looking for, this is the OnFolderChanging event . Designed so that the user can not go from the current folder, what you really want to do.

Although this looks good on paper, I must warn you that you are really trying to use these interfaces. A common problem with everything related to the Windows shell is that they simplify use only with C ++. COM interfaces are "unfriendly" types, IUnknown-based interfaces without a type library, which you can use to easily add a link to your C # or VB.NET project. Microsoft has published the Vista Bridge to use these interfaces for C #, and it looks like this . Yes Yes. The double trick, when you find that you need to do this twice, it only works in later versions of Windows, and there is a strong hint that you are trying to do this on XP (judging by the identifier of the control).

This is simply not what you want to support. Since the alternative is so simple, use the supported .NET FileOk event instead. Winforms example:

  private void SaveButton_Click(object sender, EventArgs e) { string requiredDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); using (var dlg = new SaveFileDialog()) { dlg.InitialDirectory = requiredDir; dlg.FileOk += (s, cea) => { string selectedDir = System.IO.Path.GetDirectoryName(dlg.FileName); if (string.Compare(requiredDir, selectedDir, StringComparison.OrdinalIgnoreCase) != 0) { string msg = string.Format("Sorry, you cannot save to this directory.\r\nPlease select '{0}' instead", requiredDir); MessageBox.Show(msg, "Invalid folder selection"); cea.Cancel = true; } }; if (dlg.ShowDialog() == DialogResult.OK) { // etc... } } } 
+4
source share

I am not going to work. Even if you disable the button, they can type ..\ and click "Save", and they will be raised one level. You cannot precisely disable the text field of the file name and maintain the functionality of the dialog.

You would be better off using FolderBrowserDialog and setting its RootFolder property and asking the user to enter a file name or auto generate it.

If the folder in which you want to restrict users is not Environment.SpecialFolder . Then you need to do some work to make the SHBrowseForFolder call manually using ILCreateFromPath to get PIDLIST_ABSOLUTE for your path go to BROWSEINFO.pidlRoot

You can display FolderBrowserDialog.RunDialog to find out how to make this call.

+1
source share

Since you want to use this behavior rather than developing low-level code (which will probably lead to interruption in future versions of windows), you can try to develop a form for selecting files.

This is basically a simple tree and list view. Microsoft has a walkthrough .

It will take you half a day, but after you have your custom form, you can determine all the types of behavior that you need, without tricks and restrictions.

+1
source share

All Articles