I create an OPENFILENAME:
OPENFILENAME ofn;
char szFile[260];
HWND hwnd = NULL;
// Initialize OPENFILENAME
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = (LPWSTR)szFile;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = L"PNG Files\0*.PNG*\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
std::string input;
if (GetOpenFileName(&ofn))
{
input = CW2A(ofn.lpstrFile);
std::cout << input << std::endl;
}
else
errorHandle("Open Dialog Problem");
But then when I try to import something via SMFL it says "Error: Unable to open file.":
sf::Texture _cursor;
if (!_cursor.loadFromFile("Resources/Metal_Norm.png"))
errorHandle("-Cursor Texture Couldn't Load");
Not sure why this error is occurring if anyone has any possible answers I would appreciate it.
GetOpenFileName
changes the current directory as you navigate around in the browser.There is a flag you can set,
OFN_NOCHANGEDIR
which was supposed to prevent this but I notice the MSDN docs have been updated at some point to say it doesn't work withGetOpenFileName
.You could try that but if it's true it doesn't work, the solution would be to save the current directory (use
GetCurrentDirectory
) before callingGetOpenFileName
and then restore it afterwards usingSetCurrentDirectory
.