1

Using the GetOpenFileName dialog. Using OFN_EXPLORER and specifying a hook (so am getting the XP style dialog). I can hide/show and enable/disable many of the controls on the dialog, but not the "up one level" (parent directory) button?

From within the hook function, how can I programatically enable and disable the "up one level" button?

EDIT: Responding to the "may have already been answered": No, that is not the same question at all. I'm trying specifically to enable and disable the "Parent" button on the dialog.

Steve
  • 1,065
  • 15
  • 34
  • possible duplicate of [limit directory with GetOpenFileName()](http://stackoverflow.com/questions/13443660/limit-directory-with-getopenfilename) – CodeCaster Aug 26 '14 at 20:34
  • No... that's a different question. That question addresses rejecting the directory that the user selects; my question is (very specifically) to enable or disable the parent directory button. Just disallowing the directory change is not what my requirement is. – Steve Aug 26 '14 at 21:28
  • As far as I can find, what you want can't be done. Does it _need_ to be a built-in dialog or can you just display a listbox with files instead? – CodeCaster Aug 26 '14 at 21:36
  • 1
    If you are hooking within your own process then you can get a handle to the toolbar and delete the button. Disabling it is harder because you don't know if/when Explorer will re-enable it so you would have to keep on checking. – user1793036 Aug 27 '14 at 02:32
  • 1
    This is such a pointless exercise. You enforce the naff XP dialog on the user? Don't do that. Let them select what they want and if it's invalid, detect and say so using standard validation techniques. Trying to hack at the private parts of a dialog is a really bad idea. – David Heffernan Aug 27 '14 at 06:51
  • David, not all of us work in an environment where we can modify the project's requirements. – Steve Aug 27 '14 at 16:19
  • user1793036, After I posted this, I did find the solution you are suggesting. I'll post it as an answer below – Steve Aug 27 '14 at 16:19

1 Answers1

1

It looks like the way to do this is described here:

http://www.codeproject.com/Articles/29/Customizing-the-Windows-Common-File-Open-Dialog

The relevant code is under the heading "Hiding the toolbar". There is also a flag for enablement, so I'm pretty sure I can get this working using this mechanism.

Edit: Here is the approach. This hides the button, but removing the TBSTATE_HIDDEN and leaving the TBSTATE_INDETERMINATE should result in it being visible but disabled.

const int TB_BTN_UPONELEVEL = 40961;
const int TB_BTN_NEWFOLDER  = 40962;

void HideToolbarBtns ( HWND hWndToolbar )
{
   TBBUTTONINFO tbinfo;
   tbinfo.cbSize = sizeof(TBBUTTONINFO);
   tbinfo.dwMask = TBIF_STATE;
   tbinfo.fsState = TBSTATE_HIDDEN | TBSTATE_INDETERMINATE;

   ::SendMessage(hWndToolbar,TB_SETBUTTONINFO,
      (WPARAM)TB_BTN_UPONELEVEL,(LPARAM)&tbinfo);
   ::SendMessage(hWndToolbar,TB_SETBUTTONINFO,
      (WPARAM)TB_BTN_NEWFOLDER,(LPARAM)&tbinfo);
}
Steve
  • 1,065
  • 15
  • 34