如何从 TOpenFileName 对话框中删除 OPEN AS READ ONLY 按钮功能
How to remove OPEN AS READ ONLY button feature from the TOpenFileName dialog
当我调用这个文件对话框时,它显示了一个漂亮的现代对话框
打开 + 打开为只读按钮。
如何删除“以只读方式打开”按钮功能?
OpenSaveFileDialog(editform,'','my|*.my','','Open my',FilSelez,True,False,True,True)
function OpenSaveFileDialog( Parent: TWinControl;
const DefExt,Filter,InitialDir,Title: string;
var FileName: string;
MustExist,OverwritePrompt,NoChangeDir,DoOpen: Boolean): Boolean;
var ofn: TOpenFileName;
szFile: array[0..MAX_PATH] of Char;
begin
Result := False;
FillChar(ofn, SizeOf(TOpenFileName), 0);
with ofn do
begin
lStructSize := SizeOf(TOpenFileName);
hwndOwner := Parent.Handle;
lpstrFile := szFile;
nMaxFile := SizeOf(szFile);
if (Title <> '') then
lpstrTitle := PChar(Title);
if (InitialDir <> '') then
lpstrInitialDir := PChar(InitialDir);
StrPCopy(lpstrFile, FileName);
lpstrFilter := PChar(StringReplace(Filter, '|', #0,[rfReplaceAll, rfIgnoreCase])+#0#0);
if DefExt <> '' then
lpstrDefExt := PChar(DefExt);
end;
if MustExist then
ofn.Flags := ofn.Flags or OFN_FILEMUSTEXIST;
if OverwritePrompt then
ofn.Flags := ofn.Flags or OFN_OVERWRITEPROMPT;
if NoChangeDir then
ofn.Flags := ofn.Flags or OFN_NOCHANGEDIR;
if DoOpen
then begin
if GetOpenFileName(ofn) then
begin
Result := True;
FileName := StrPas(szFile);
end;
end
else begin
if GetSaveFileName(ofn) then
begin
Result := True;
FileName := StrPas(szFile);
end;
end;
end;
每次使用新的 API,您总是会阅读它的完整文档。
在这种情况下,您可以查看此结构的 GetOpenFileName
function, and you find that it has a single parameter, a structure of type OPENFILENAME
. Hence, you go to the documentation 文档。
在此页面,您在网络浏览器中按 Ctrl+F,搜索“只读”即可快速找到此段内容:
Flags
A set of bit flags you can use to initialize the dialog box. When the dialog box returns, it sets these flags to indicate the user's input. This member can be a combination of the following flags.
[...]
OFN_HIDEREADONLY
0x00000004
Hides the Read Only check box.
因此,你意识到你只需要添加这个标志:
ofn.Flags := ofn.Flags or OFN_HIDEREADONLY;
当我调用这个文件对话框时,它显示了一个漂亮的现代对话框 打开 + 打开为只读按钮。
如何删除“以只读方式打开”按钮功能?
OpenSaveFileDialog(editform,'','my|*.my','','Open my',FilSelez,True,False,True,True)
function OpenSaveFileDialog( Parent: TWinControl;
const DefExt,Filter,InitialDir,Title: string;
var FileName: string;
MustExist,OverwritePrompt,NoChangeDir,DoOpen: Boolean): Boolean;
var ofn: TOpenFileName;
szFile: array[0..MAX_PATH] of Char;
begin
Result := False;
FillChar(ofn, SizeOf(TOpenFileName), 0);
with ofn do
begin
lStructSize := SizeOf(TOpenFileName);
hwndOwner := Parent.Handle;
lpstrFile := szFile;
nMaxFile := SizeOf(szFile);
if (Title <> '') then
lpstrTitle := PChar(Title);
if (InitialDir <> '') then
lpstrInitialDir := PChar(InitialDir);
StrPCopy(lpstrFile, FileName);
lpstrFilter := PChar(StringReplace(Filter, '|', #0,[rfReplaceAll, rfIgnoreCase])+#0#0);
if DefExt <> '' then
lpstrDefExt := PChar(DefExt);
end;
if MustExist then
ofn.Flags := ofn.Flags or OFN_FILEMUSTEXIST;
if OverwritePrompt then
ofn.Flags := ofn.Flags or OFN_OVERWRITEPROMPT;
if NoChangeDir then
ofn.Flags := ofn.Flags or OFN_NOCHANGEDIR;
if DoOpen
then begin
if GetOpenFileName(ofn) then
begin
Result := True;
FileName := StrPas(szFile);
end;
end
else begin
if GetSaveFileName(ofn) then
begin
Result := True;
FileName := StrPas(szFile);
end;
end;
end;
每次使用新的 API,您总是会阅读它的完整文档。
在这种情况下,您可以查看此结构的 GetOpenFileName
function, and you find that it has a single parameter, a structure of type OPENFILENAME
. Hence, you go to the documentation 文档。
在此页面,您在网络浏览器中按 Ctrl+F,搜索“只读”即可快速找到此段内容:
Flags
A set of bit flags you can use to initialize the dialog box. When the dialog box returns, it sets these flags to indicate the user's input. This member can be a combination of the following flags.
[...]
OFN_HIDEREADONLY 0x00000004
Hides the Read Only check box.
因此,你意识到你只需要添加这个标志:
ofn.Flags := ofn.Flags or OFN_HIDEREADONLY;