Robert,您可以使用對話框模板來做到這一點。
首先,你必須存儲模板爲您的應用程序的資源,然後加載使用TOpenFilename
結構的模板(不要被名字擔心,是開放的相同和保存對話框),最後調用傳遞GetSaveFileName
功能TOpenFilename
結構。
檢查該樣本
創建對話框模板資源文件(calledSaveDialog.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;
和這是輸出
做得很好,RRUZ。很好的答案,加上示例代碼,並顯示結果的屏幕截圖。謝謝! – RobertFrank 2011-05-08 02:13:07