C++ 检测 'explorer' 并显示另存为对话框
C++ 检测 'explorer' 并显示另存为对话框
要实现这个功能,您可以使用 C++ 的条件语句来检测 'a' 的值是否为 'explorer',如果是,则显示一个另存为 API 的窗口。具体的实现取决于您使用的窗口库或框架,以下是一个使用 Windows API 的示例代码:
#include <iostream>
#include <windows.h>
int main() {
std::string a = 'explorer';
if (a == 'explorer') {
// 显示另存为窗口
OPENFILENAMEA ofn;
CHAR szFile[260] = { 0 };
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = 'All Files (*.*)�*.*�';
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (GetSaveFileNameA(&ofn) == TRUE) {
std::cout << '保存文件路径:' << ofn.lpstrFile << std::endl;
}
else {
std::cout << '取消保存' << std::endl;
}
}
else {
std::cout << 'a 的值不是 explorer' << std::endl;
}
return 0;
}
请注意,这只是一个示例代码,具体实现可能会因为使用的窗口库或框架而有所不同。上述示例使用了 Windows API 中的 GetSaveFileNameA 函数来显示另存为窗口,并获取用户选择的文件路径。
原文地址: https://www.cveoy.top/t/topic/qCkw 著作权归作者所有。请勿转载和采集!