Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

water908

saving and opening

This topic is 5597 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know how to save and read in files, but I want to know how to be able to search for where I want to save and read in from. What I mean is if you use Word and you want to save you can choose what folder it is saved in and it''s name, and have that little window, if possible. Thank you for your help.

Share this post


Link to post
Share on other sites
Advertisement
What you want is the "open" and "save as" common dialog boxes. Here are the two in Win32 API.

Open...

void Open_Game(HWND hwnd)
{
OPENFILENAME ofn;
char szFileName[MAX_PATH] = "";

ZeroMemory(&ofn, sizeof(ofn));

ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = "
Some file (*.huh)\0*.huh\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = "
huh";

if(GetOpenFileName(&ofn))
{
//Activate your reading function here, pass in ''szFileName'' for the "location of the file"

}
}

Change what file extension you want by replacing the *.huh stuff.
The ofn.lpstrDefExt you insert in a generic file extension. Say user enters in the correct file name but not correct extension. If it does not match the filter... try to match it to the ofn.lpstrDefExt before exiting.
The szFileName contains the path of the file you want to open, pass into fstream or something of that nature.


void Save_Game(HWND hwnd)
{
HANDLE hFile;
OPENFILENAME ofn;
char szFileName[MAX_PATH] = "";

ZeroMemory(&ofn, sizeof(ofn));

ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = "
Some file (*.huh)\0*.huh\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrDefExt = "
huh";
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
if(GetSaveFileName(&ofn))
{
//File save function here

}
else
{
//Error box thing, file cannot be saved here

}

Practically same thing as above.

I suppose just cut and paste if you want to utilize the common dialog boxes, just make sure to adjust for variable differences.

If you have questions, ask me and I''m sure either the others or myself can answer them. Hope that helps.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!