I have been looking hi and low on how to implement a save as... function for my tic tac toe game. I think I am almost there, but not quite. I have tried 2 approaches. I have used the old style OPENFILENAME and I have tried using the Common Item Dialog box. I seem to have more luck getting it to work better with the Common Item Dialog box.
However, I have 2 issues. First, sometimes when I am clicking around folders in the dialog box, then I go to the area where I enter the file name and press "save," it opens the last folder I had clicked on instead.
Second issue, how can I get the box below the file name entry to display the default extensions.
*apologies for the excessive tabs, it's in a case statement
IFileSaveDialog *pFileOpen;
// Create the FileOpenDialog object.
HRESULT hr = CoCreateInstance(CLSID_FileSaveDialog, NULL, CLSCTX_ALL,
IID_IFileSaveDialog, reinterpret_cast<void**>(&pFileOpen));
if (SUCCEEDED(hr))
{
// Show the Open dialog box.
hr = pFileOpen->SetDefaultExtension(L"dat");
hr = pFileOpen->Show(hWnd);
// Get the file name from the dialog box.
if (SUCCEEDED(hr))
{
IShellItem *pItem;
hr = pFileOpen->GetResult(&pItem);
if (SUCCEEDED(hr))
{
PWSTR pszFilePath;
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
// Display the file name to the user.
if (SUCCEEDED(hr))
{
LPWSTR path = pszFilePath;
wstring file = path;
string str(file.begin(), file.end());
sounds.playSound(str);
CoTaskMemFree(pszFilePath);
}
pItem->Release();
}
}
}
I got the second issue fixed, but I still have an issue when clicking around, and then clicking the save button, it opens the last folder I clicked on instead.