如何从 TOpenFileName 对话框中删除“OPEN AS READ ONLY”按钮功能

发布于 2025-01-09 18:28:32 字数 1984 浏览 3 评论 0原文

当我调用此文件对话框时,它会显示一个漂亮的现代对话框 打开 + 打开为只读按钮。

如何删除“以只读方式打开”按钮功能?

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;

When I call this File dialog it displays a nice modern dialog with
OPEN + OPEN AS READONLY buttons.

How can I remove the OPEN AS READ-ONLY button feature?

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我爱人 2025-01-16 18:28:32

每次使用新的 API 时,您总是会阅读其完整文档。

在这种情况下,您可以转到文档 GetOpenFileName 函数,您会发现它只有一个参数,即 OPENFILENAME 类型的结构。因此,您可以转到文档 对于这个结构。

在此页面,您在浏览器中按Ctrl+F,然后搜索“只读”即可快速找到这段文字:

标志

可用于初始化对话框的一组位标志。当对话框返回时,它设置这些标志来指示用户的输入。该成员可以是以下标志的组合。

[...]

OFN_HIDEREADONLY
0x00000004

隐藏“只读”复选框。

因此,您意识到您只需要添加此标志:

ofn.Flags := ofn.Flags or OFN_HIDEREADONLY;

Every time you use a new API, you always read its full documentation.

In this case, you go to the docs for the GetOpenFileName function, and you find that it has a single parameter, a structure of type OPENFILENAME. Hence, you go to the documentation for this structure.

At this page, you press Ctrl+F in your web browser, and search for "read only" to quickly find this passage:

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.

Hence, you realise that you only need to add this flag:

ofn.Flags := ofn.Flags or OFN_HIDEREADONLY;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文