如何在 Delphi 2010 中向 TSaveDialog 添加复选框

发布于 2024-11-06 06:16:39 字数 505 浏览 4 评论 0 原文

我想向 TSaveDialog 添加一个复选框或其他 VCL 组件。

坎图说,

新的 Vista 打开和保存对话框(由 IFileOpenDialog 和
IFileSaveDialog 接口)由新的 FileOpenDialog 直接映射
FileSaveDialog组件,也是标准的OpenDialog和SaveDialog组件使用
设置全局 UseLatestCommonDialogs 时的新样式。

我不知道这意味着什么(我从未做过任何接口编程......)

而且我不想使用第三方工具。

我刚才在网络搜索中看到它建议我查看 TOpenPictureDialog 代码并复制它。

在尝试任何路径之前,我想我应该在这里寻求一些指导。关于 XP 到 Win7 解决方案以独立于 Windows 版本的方式向现代文件、打开对话框添加复选框有什么建议吗?

汤姆

I want to add a checkbox or other VCL component to the TSaveDialog.

Cantu says,

The new Vista Open and Save dialog boxes (implemented by the IFileOpenDialog and
IFileSaveDialog interfaces) are directly mapped by the new FileOpenDialog and
FileSaveDialog components, but also the standard OpenDialog and SaveDialog component uses
the new style when the global UseLatestCommonDialogs is set.

I have no idea what that means (I've never done any Interface programming...)

And I don't want to use third party tools.

I saw it suggested on a web search just now that I look at the TOpenPictureDialog code and copy it.

Before trying any of the paths, I thought I'd ask here for some guidance. Any suggestions on an XP through Win7 solution to adding a checkbox to a modern File, Open dialog box in a Windows-version independent manner?

Tom

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

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

发布评论

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

评论(2

我做我的改变 2024-11-13 06:16:39

罗伯特,您可以使用对话框模板来做到这一点。

首先,您必须将模板存储为应用程序中的资源,然后使用 TOpenFilename 结构(不用担心名称,打开和保存对话框是相同的),最后调用 GetSaveFileName 函数传递 TOpenFilename 结构。

检查此示例

使用对话框模板创建一个资源文件(称为SaveDialog.rc)(查看添加的MyCheckBox)

MYSAVEFILE DIALOG -1, 1, 300, 60
STYLE DS_3DLOOK | DS_CONTROL | WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS
CAPTION ""
FONT 8, "Tahoma"
{
CONTROL "MyCheckBox", 666, "button", BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 84, 19, 60, 12
}

这是源代码

Uses
 CommDlg;

var
  lpofn    : TOpenFilename;
  lpstrFile: Array[0..MAX_PATH-1] of Char;

{$R *.dfm}
{$R SaveDialog.Res}

function _lpfnHook(hdlg: HWND; uiMsg:UINT;wParam:WPARAM;lParam:LPARAM): UINT stdcall;
begin
  Result:=0;
  case uiMsg of
    // Set the initial state of mycheckbox to checked
    WM_INITDIALOG : CheckDlgButton(hdlg,666,BST_CHECKED);
    WM_COMMAND    :
                   case wParam of
                    666:
                         begin
                          if (IsDlgButtonChecked(hdlg,666)=BST_CHECKED) then
                           ShowMessage('MyCheckBox was checked')
                          else
                          if (IsDlgButtonChecked(hdlg,666)=BST_UNCHECKED) then
                            ShowMessage('MyCheckBox was unchecked');
                         end;
                   end;
  end;
end;

procedure TFrmMain.Button1Click(Sender: TObject);
begin
  ZeroMemory(@lpofn,sizeof(lpofn));
  lpofn.lStructSize       := SizeOf(lpofn);
  lpofn.hwndOwner         := Handle;
  lpofn.hInstance         := hInstance;
  //set the filter name
  lpofn.lpstrFilter       := 'All files (*.*)'#0'*.*'#0#0;
  lpofn.lpstrTitle        := 'Save As';
  lpofn.lpstrFile         := lpstrFile;
  lpofn.nMaxFile          := MAX_PATH;
  //Set the template Name
  lpofn.lpTemplateName    :='MYSAVEFILE';
  //set the callback function
  lpofn.lpfnHook          := _lpfnHook;
  lpofn.Flags             := OFN_EXPLORER or OFN_CREATEPROMPT or  OFN_HIDEREADONLY or
                             OFN_PATHMUSTEXIST or OFN_ENABLEHOOK or OFN_ENABLETEMPLATE;
  //execute the dialog
  if GetSaveFileName(lpofn) then ShowMessage(lpofn.lpstrFile);
end;

,这是输出

在此处输入图像描述

Robert, you can do that using a dialog template.

First you must store the template as a resource in your app, then load the template using the TOpenFilename structure (don't worry by the name, is the same for open and save dialogs) and finally call the GetSaveFileName function passing the TOpenFilename structure.

check this sample

Create a resource file (calledSaveDialog.rc) with the dialog template (look the MyCheckBox added)

MYSAVEFILE DIALOG -1, 1, 300, 60
STYLE DS_3DLOOK | DS_CONTROL | WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS
CAPTION ""
FONT 8, "Tahoma"
{
CONTROL "MyCheckBox", 666, "button", BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 84, 19, 60, 12
}

this is the source code

Uses
 CommDlg;

var
  lpofn    : TOpenFilename;
  lpstrFile: Array[0..MAX_PATH-1] of Char;

{$R *.dfm}
{$R SaveDialog.Res}

function _lpfnHook(hdlg: HWND; uiMsg:UINT;wParam:WPARAM;lParam:LPARAM): UINT stdcall;
begin
  Result:=0;
  case uiMsg of
    // Set the initial state of mycheckbox to checked
    WM_INITDIALOG : CheckDlgButton(hdlg,666,BST_CHECKED);
    WM_COMMAND    :
                   case wParam of
                    666:
                         begin
                          if (IsDlgButtonChecked(hdlg,666)=BST_CHECKED) then
                           ShowMessage('MyCheckBox was checked')
                          else
                          if (IsDlgButtonChecked(hdlg,666)=BST_UNCHECKED) then
                            ShowMessage('MyCheckBox was unchecked');
                         end;
                   end;
  end;
end;

procedure TFrmMain.Button1Click(Sender: TObject);
begin
  ZeroMemory(@lpofn,sizeof(lpofn));
  lpofn.lStructSize       := SizeOf(lpofn);
  lpofn.hwndOwner         := Handle;
  lpofn.hInstance         := hInstance;
  //set the filter name
  lpofn.lpstrFilter       := 'All files (*.*)'#0'*.*'#0#0;
  lpofn.lpstrTitle        := 'Save As';
  lpofn.lpstrFile         := lpstrFile;
  lpofn.nMaxFile          := MAX_PATH;
  //Set the template Name
  lpofn.lpTemplateName    :='MYSAVEFILE';
  //set the callback function
  lpofn.lpfnHook          := _lpfnHook;
  lpofn.Flags             := OFN_EXPLORER or OFN_CREATEPROMPT or  OFN_HIDEREADONLY or
                             OFN_PATHMUSTEXIST or OFN_ENABLEHOOK or OFN_ENABLETEMPLATE;
  //execute the dialog
  if GetSaveFileName(lpofn) then ShowMessage(lpofn.lpstrFile);
end;

and this is the output

enter image description here

不回头走下去 2024-11-13 06:16:39

您可以使用模板来完成此操作,但这会导致 Vista/7 中出现旧版对话框。在这些平台上,您应该使用 IFileDialogCustomize。当然,为了支持 XP,您还需要实现模板方法。

You can do this with a template but this leads to the legacy dialogs in Vista/7. On those platforms you should make use of IFileDialogCustomize. Of course to support XP you need to implement the template approach too.

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