一丶打开文件
CoInitialize(NULL);
IFileOpenDialog * pOpenFileDlg = NULL;
HRESULT hr = S_FALSE;
hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog, (LPVOID*)&pOpenFileDlg);
if (SUCCEEDED(hr))
{
hr = pOpenFileDlg->Show(NULL);
if (SUCCEEDED(hr))
{
//从对话框中获取文件名
IShellItem* pItem;
hr = pOpenFileDlg->GetResult(&pItem);
if (SUCCEEDED(hr))
{
//结果成功,获取名字.
PWSTR pszFilePath = NULL;
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
if (SUCCEEDED(hr))
{
//进行你的代码操作. pszFilePath = 打开的路径
CString str(pszFilePath);
m_ChoosPluginEdt.SetWindowTextW(str);
CoTaskMemFree(pszFilePath);//释放内存
}
pItem->Release();
}
}
pOpenFileDlg->Release();//释放内存
}
CoUninitialize();
//保存文件用 IFileSaveDialog 用到再写