[英]IFileDialog Overwrite File and Open Folder/File
I have two issues related to IFileSaveDialog
& IFileOpenDialog
I did not managed to find a solution for, I hope you can help me.我有两个与IFileSaveDialog
和IFileOpenDialog
相关的问题我没有找到解决方案,希望你能帮助我。
Can these be done with this API?这些可以用这个 API 来完成吗? Or maybe other API?或者其他API?
I tried to google it and go over Microsoft documentation to find a solution, but with no luck.我试图用谷歌搜索它并查看 Microsoft 文档以找到解决方案,但没有运气。
- When the user is saving a file with an existing name, the "Confirm Save As" prompt appears.当用户使用现有名称保存文件时,会出现“确认另存为”提示。 I need the "Yes" option to be marked as default instead of "No".我需要将“是”选项标记为默认值而不是“否”。
As @Remy Lebeau said that, you can use IFileDialogEvents::OnOverwrite method.正如@Remy Lebeau 所说,您可以使用IFileDialogEvents::OnOverwrite方法。 And use MessageBox
to create a suitable dialog.并使用MessageBox
创建一个合适的对话框。
Some code:一些代码:
IFACEMETHODIMP OnOverwrite(IFileDialog* , IShellItem*psi, FDE_OVERWRITE_RESPONSE* response) {
int msgboxID = MessageBox(
NULL,
(LPCWSTR)L"Windows already exists, \n\rDo you want to replace it?",
(LPCWSTR)L"Confirm Save As",
MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON1
);
switch (msgboxID)
{
case IDYES:
*response = FDEOR_ACCEPT;
break;
case IDNO:
*response = FDEOR_REFUSE;
break;
}
return S_OK;
}
Debug:调试:
The User can open/load a file or a folder from the same dialog.用户可以从同一个对话框打开/加载文件或文件夹。 Can these be done with this API?这些可以用这个 API 来完成吗? Or maybe other API?或者其他API?
There is no such method in the document, you can only select a folder or file.文档中没有这种方法,只能选择文件夹或文件。
As a compromise, I suggest that you can create a new MessageBox and set two buttons in it, namely "select folders" and "select files".作为妥协,我建议您可以创建一个新的 MessageBox 并在其中设置两个按钮,即“选择文件夹”和“选择文件”。 When the user selects folders, folder dialog with the FOS_PICKFOLDERS
style is opened.当用户选择文件夹时,将打开具有FOS_PICKFOLDERS
样式的文件夹对话框。 Otherwise, Files is selected by default.否则,默认选择文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.