我有两个与IFileSaveDialog
和IFileOpenDialog
相关的问题,我没有找到解决方法,希望您能对我有所帮助。
可以使用此API完成这些操作吗?还是其他API?
我试图用Google搜索它,然后遍历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".
就像@Remy Lebeau所说的那样,您可以使用IFileDialogEvents::OnOverwrite方法。并使用
MessageBox
创建一个合适的对话框。一些代码:
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;
}
调试:The User can open/load a file or a folder from the same dialog. Can these be done with this API? Or maybe other API?
文档中没有这种方法,您只能选择一个文件夹或文件。
作为一种折衷,我建议您可以创建一个新的MessageBox并在其中设置两个按钮,即“选择文件夹”和“选择文件”。当用户选择文件夹时,将打开带有
FOS_PICKFOLDERS
样式的文件夹对话框。否则,默认情况下会选择文件。
关于c++ - IFileDialog覆盖文件并打开文件夹/文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64748853/