BOOL SaveAsFile(HWND hwnd, LPSTR pszFileName)
{
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
pszFileName[0] = 0;
string buffer2;
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = "Map Files (*.lvl)\0*.lvl\0All Files (*.*)\0*.*\0\0";
ofn.lpstrFile = pszFileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrDefExt = "lvl";
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY |OFN_OVERWRITEPROMPT|OFN_NOCHANGEDIR;
ofn.lpstrInitialDir = "Level";
if(GetSaveFileName(&ofn))
{
SaveLvlFile(pszFileName);
//gives me full path not just file name
SetWindowText(hwnd,pszFileName);
}
return TRUE;
}
[\source]
Need help with getting filename only from OPENFILENAME
in notepad when a user saves there text file it puts the title in the caption bar at the top. Iam trying to do the same thing.
But I can not get just the file name I am getting the fule path.
Couldn't you just look for the last backslash in the full path, and take everything after it? Something like:
char* fileName = pszFileName + strlen(pszFileName);assert(*fileName == 0);while(; fileName != pszFileName && *fileName != '\\'; --fileName);SetWindowText(hwnd, fileName);
Just strip the path. Start at the end of the string and go backwards until you hit a file separator / or \\ or whichever your operating system uses, and strip everything from there on.
I could be wrong, but I believe there's a member of that struct that gives you just the filename without the rest of the path, i believe it's lpstrFileTitle.
Quote:Original post by kingpinzsAre you serious? What about instead of:
I thinck so to but I dont know how to use lpstrFileTitle. Any one have any idea.
SetWindowText(hwnd,pszFileName);
You use:SetWindowText(hwnd,ofn.lpstrFileTitle);
Edit: actually, I think you've got to supply your own buffer for lpstrFileTitle, but it's no different to how you have to supply your own buffer for lpstrFile.
Quote:Original post by CodekaQuote:Original post by kingpinzsAre you serious? What about instead of:
I thinck so to but I dont know how to use lpstrFileTitle. Any one have any idea.You use:SetWindowText(hwnd,pszFileName);
SetWindowText(hwnd,ofn.lpstrFileTitle);
Edit: actually, I think you've got to supply your own buffer for lpstrFileTitle, but it's no different to how you have to supply your own buffer for lpstrFile.
Yeah, you have to supply your own buffer, so something like this.
char fileTitle[MAX_PATH];
//later in the file
ofn.lpstrFileTitle = fileTitle;
//later in file
SetWindowText(hWnd,fileTitle);
although, you could use ofn.lpstrFileTitle after the buffer has been set, but that's just ugly and wrong
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement