How to add a checkbox to TSaveDialog in Delphi 2010
我想在TSaveDialog中添加一个复选框或其他VCL组件。
坎图说,
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.
我不知道这是什么意思(我从未做过任何接口编程...)
我不想使用第三方工具。
我刚刚在查看TOpenPictureDialog代码并将其复制时,才在网络搜索中看到它的建议。
在尝试任何路径之前,我想我会在这里寻求一些指导。关于通过Win7解决方案在XP上以Windows版本独立的方式向现代文件,打开对话框添加复选框的任何建议?
汤姆
Robert,您可以使用对话框模板来做到这一点。
首先,您必须将模板作为资源存储在应用程序中,然后使用
检查此样本
使用对话框模板(看一下添加的MyCheckBox)创建一个资源文件(称为SaveDialog.rc)。
1 2 3 4 5 6 7 | 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 } |
这是源代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | 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; |
这是输出
您可以使用模板执行此操作,但这会导致Vista / 7中出现旧式对话框。在那些平台上,您应该使用IFileDialogCustomize。当然,要支持XP,您也需要实现模板方法。