2011. február 18., péntek

How to remove the 'Create new folder' button of a TOpenDialog


How to remove the 'Create new folder' button of a TOpenDialog


Here is how you can remove the 'Create new folder' button on a TOpenDialog. Look at the lines at the bottom this procedure. But note that although the button is no longer present, it's still possible to create a new folder in the dialog, as well as all other kinds of file/ directory manipulation.

{ ... }
  TForm1 = class(TForm)
    OpenDialog1: TOpenDialog;
    { Private declarations }
    procedure MoveDialog(var Msg: TMessage); message WM_USER;
    { Public declarations }

  Form1: TForm1;


{$R *.DFM}

procedure TForm1.MoveDialog(var Msg: TMessage);
  rec: TRect;
  wh: HWND;
  l, t, r, b: Integer;
  {Center OpenDialog over form}
  if ofOldStyleDialog in OpenDialog1.Options then
    wh := OpenDialog1.Handle
    wh := Windows.GetParent(OpenDialog1.Handle);
  if IsWindow(wh) then
    if GetWindowRect(wh, rec) then
      l := (Width - (rec.Right - rec.Left)) div 2 + Left;
      t := (Height - (rec.Bottom - rec.Top)) div 2 + Top;
      r := rec.Right - rec.Left;
      b := rec.Bottom - rec.Top;
      MoveWindow(wh, l, t, r, b, True);
  if not (ofOldStyleDialog in OpenDialog1.Options) then
    {Remove the 'Create new folder' toolbutton}
    wh := Windows.GetParent(OpenDialog1.Handle);
    wh := FindWindowEx(wh, 0, 'ToolbarWindow32', nil);
    if wh <> 0 then
      SendMessage(wh, TB_DELETEBUTTON, 5, 0); {uses Commctrl}
    {Warning: 5 is the ID-number of the 'Create new folder' toolbutton.
                It may possibly change on different Windows versions.}

Nincsenek megjegyzések:

Megjegyzés küldése