2011. február 18., péntek
How to remove the 'Create new folder' button of a TOpenDialog
Problem/Question/Abstract:
How to remove the 'Create new folder' button of a TOpenDialog
Answer:
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.
{ ... }
type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
private
{ Private declarations }
procedure MoveDialog(var Msg: TMessage); message WM_USER;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.MoveDialog(var Msg: TMessage);
var
rec: TRect;
wh: HWND;
l, t, r, b: Integer;
begin
{Center OpenDialog over form}
if ofOldStyleDialog in OpenDialog1.Options then
wh := OpenDialog1.Handle
else
wh := Windows.GetParent(OpenDialog1.Handle);
if IsWindow(wh) then
if GetWindowRect(wh, rec) then
begin
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);
end;
if not (ofOldStyleDialog in OpenDialog1.Options) then
begin
{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.}
end;
end;
Feliratkozás:
Megjegyzések küldése (Atom)
Nincsenek megjegyzések:
Megjegyzés küldése