Code:
switch(wParam)
{case M_SAVE: if(!Battle){
szFileName[0] = '\0'; /* Puts a blank in front of the filename buffer. */
ZeroMemory(ofn, sizeof(*ofn)); /* Zeroes out the above class. */
ofn->lStructSize = sizeof(*ofn); /* Sets its size. */
ofn->hwndOwner = hwnd; /* Sets the window that owns the save file dialog box. */
ofn->hInstance = hInstance; /* Sets the application instance that the dialog box will belong to. */
ofn->lpstrFilter = "Adventurer Save Files (*.asv)\0*.asv\0All Files (*.*)\0*.*\0"; /* Sets the selectable filters for the dialog box. */
ofn->lpstrFile = szFileName; /* Sets the place to store the path of the file to save. */
ofn->nMaxFile = MAX_PATH; /* Sets the maximum length of the path. */
ofn->Flags = OFN_EXPLORER|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT; /* Sets the options for the save dialog box. */
ofn->lpstrDefExt = "asv"; /* Sets the default file extension. */
if(GetSaveFileName(ofn))/* Gets the filename and path to save to. */
{Save_File = CreateFile(szFileName,GENERIC_WRITE|GENERIC_READ,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN,NULL); /* Opens or creates the file with write access. */
if(Save_File == INVALID_HANDLE_VALUE)
{MessageBox(hwnd,"Couldn't Open Save File","--- Error ---",MB_OK|MB_ICONINFORMATION); strcpy(Message,separators[107]+1); Changed = 1; return 1;}
SetFilePointer(Save_File,0,NULL,FILE_BEGIN); /* Sets the position in the file to write to. */
/* Saves the first inventory item. If successful sends sucess message. */
if(WriteFile(Save_File,Inventory1,55,bytes,NULL)){strcpy(Message,separators[108]+1);
//Saves everything else, presuming that if one WriteFile works, so will the rest. */
WriteFile(Save_File,Inventory2,55,bytes,NULL);
WriteFile(Save_File,Inventory3,55,bytes,NULL);
WriteFile(Save_File,Inventory4,55,bytes,NULL);
WriteFile(Save_File,Inventory5,55,bytes,NULL);
WriteFile(Save_File,Inventory6,55,bytes,NULL);
WriteFile(Save_File,Inventory7,55,bytes,NULL);
WriteFile(Save_File,Inventory8,55,bytes,NULL);
WriteFile(Save_File,Inventory9,55,bytes,NULL);
WriteFile(Save_File,Inventory10,55,bytes,NULL);
WriteFile(Save_File,InventoryQ,40,bytes,NULL);
WriteFile(Save_File,&Exp_To_Next_Level,4,bytes,NULL);
WriteFile(Save_File,&Level,4,bytes,NULL);
WriteFile(Save_File,&Max_HP,4,bytes,NULL);
WriteFile(Save_File,&Strength,4,bytes,NULL);
WriteFile(Save_File,&Defence,4,bytes,NULL);
WriteFile(Save_File,&HP,4,bytes,NULL);
WriteFile(Save_File,&Gold_Coins,4,bytes,NULL);
WriteFile(Save_File,Time,8,bytes,NULL);
WriteFile(Save_File,&Weapon,55,bytes,NULL);
WriteFile(Save_File,&Weapon_Attack,4,bytes,NULL);
WriteFile(Save_File,&Armour,55,bytes,NULL);
WriteFile(Save_File,&Armour_Defence,4,bytes,NULL);
WriteFile(Save_File,&Variables,8,bytes,NULL);
WriteFile(Save_File,&Old_Position,4,bytes,NULL);
WriteFile(Save_File,&Position,4,bytes,NULL);
WriteFile(Save_File,&Sub_Position,4,bytes,NULL);
WriteFile(Save_File,&Buying,1,bytes,NULL);
WriteFile(Save_File,&Item_To_Buy,4,bytes,NULL);
WriteFile(Save_File,&Sell_Price,4,bytes,NULL);
WriteFile(Save_File,Position_Name,41,bytes,NULL);
WriteFile(Save_File,Position_Text,601,bytes,NULL);
WriteFile(Save_File,Position_Commands,501,bytes,NULL);}
else strcpy(Message,separators[107]+1); /* If saving failed displays failure message. */
CloseHandle(Save_File);} /* Closes save file. */
else strcpy(Message,separators[107]+1);} /* If saving failed displays failure message. */
else strcpy(Message,separators[109]+1);
Changed = 1; return 1;/* Sets program to update. */
break;
case M_LOAD: if(!Battle){
szFileName = '\0'; /* Blanks a char array to hold the path of the file to load. */
ZeroMemory(ofn, sizeof(*ofn)); /* Zeroes out the above class. */
ofn->lStructSize = sizeof(*ofn); /* Sets its size. */
ofn->hwndOwner = hwnd; /* Sets the window that owns the load file dialog box. */
ofn->lpstrFilter = "Adventurer Save Files (*.asv)\0*.asv\0All Files (*.*)\0*.*\0"; /* Sets the selectable filters for the dialog box. */
ofn->lpstrFile = szFileName; /* Sets the place to store the path of the file to load. */
ofn->nMaxFile = MAX_PATH; /* Sets the maximum length of the path. */
ofn->Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; /* Sets the options for the load dialog box. */
ofn->lpstrDefExt = "asv"; /* Sets the default file extension. */
if(GetOpenFileName(ofn)) /* Gets the filename and path to load from. */
{Save_File = CreateFile(szFileName,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN,NULL); /* Opens the file with read access. */
if(Save_File == INVALID_HANDLE_VALUE)
{MessageBox(hwnd,"Couldn't Open Save File","--- Error ---",MB_OK|MB_ICONINFORMATION); strcpy(Message,separators[111]+1); Changed = 1; return 1;}
SetFilePointer(Save_File,0,NULL,FILE_BEGIN); /* Sets the position in the file to write to. */
if(ReadFile(Save_File,Inventory1,55,bytes,NULL)){strcpy(Message,separators[112]+1); /* Loads the position. If successful sends success message. */
//Saves everything else, presuming that if one ReadFile works, so will the rest. */
ReadFile(Save_File,Inventory2,55,bytes,NULL);
ReadFile(Save_File,Inventory3,55,bytes,NULL);
ReadFile(Save_File,Inventory4,55,bytes,NULL);
ReadFile(Save_File,Inventory5,55,bytes,NULL);
ReadFile(Save_File,Inventory6,55,bytes,NULL);
ReadFile(Save_File,Inventory7,55,bytes,NULL);
ReadFile(Save_File,Inventory8,55,bytes,NULL);
ReadFile(Save_File,Inventory9,55,bytes,NULL);
ReadFile(Save_File,Inventory10,55,bytes,NULL);
ReadFile(Save_File,InventoryQ,40,bytes,NULL);
ReadFile(Save_File,&Exp_To_Next_Level,4,bytes,NULL);
ReadFile(Save_File,&Level,4,bytes,NULL);
ReadFile(Save_File,&Max_HP,4,bytes,NULL);
ReadFile(Save_File,&Strength,4,bytes,NULL);
ReadFile(Save_File,&Defence,4,bytes,NULL);
ReadFile(Save_File,&HP,4,bytes,NULL);
ReadFile(Save_File,&Gold_Coins,4,bytes,NULL);
ReadFile(Save_File,Time,8,bytes,NULL);
ReadFile(Save_File,&Weapon,55,bytes,NULL);
ReadFile(Save_File,&Weapon_Attack,4,bytes,NULL);
ReadFile(Save_File,&Armour,55,bytes,NULL);
ReadFile(Save_File,&Armour_Defence,4,bytes,NULL);
ReadFile(Save_File,&Variables,8,bytes,NULL);
ReadFile(Save_File,&Old_Position,4,bytes,NULL);
ReadFile(Save_File,&Position,4,bytes,NULL);
ReadFile(Save_File,&Sub_Position,4,bytes,NULL);
ReadFile(Save_File,&Buying,1,bytes,NULL);
ReadFile(Save_File,&Item_To_Buy,4,bytes,NULL);
ReadFile(Save_File,&Sell_Price,4,bytes,NULL);
ReadFile(Save_File,Position_Name,41,bytes,NULL);
ReadFile(Save_File,Position_Text,601,bytes,NULL);
ReadFile(Save_File,Position_Commands,501,bytes,NULL);}
else strcpy(Message,separators[111]+1); /* If loading failed displays failure message. */
CloseHandle(Save_File);} /* Closes save file. */
else strcpy(Message,separators[111]+1);} /* If loading failed displays failure message. */
else strcpy(Message,separators[113]+1);
Changed = 1; return 1;/* Sets program to update. */
return 1;