I'm trying to write a file:save routine for my program. After I've already saved, and if I select save again, I want the program to save without opening the save dialog (just save the file). However when I save again, the program shuts down. I was wondering where I was going wrong here.
The problem clearly has something to do with what I'm doing with my "savedtemp" variable.
Here is a snippet of code.
Thanks for your help.
The problem clearly has something to do with what I'm doing with my "savedtemp" variable.
Here is a snippet of code.
- Code:
LRESULT lResult = TRUE;
BOOL saved=FALSE;
TCHAR szFile[MAX_PATH] = TEXT("\0");
WCHAR *savedtemp;
OPENFILENAME ofn;
memset(&(ofn),0,sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szFile;
ofn.nMaxFile = MAX_PATH;
case ID_FILE_SAVE:
ofn.lpstrFilter = TEXT("Text(*.txt)\0*.txt\0");
ofn.lpstrTitle = TEXT("Save File As");
ofn.Flags = OFN_HIDEREADONLY;
ofn.lpstrDefExt = TEXT("txt);
if(saved==FALSE)
{
if(GetSaveFileName(&ofn))
{
saved=TRUE;
ShowInfo(hwnd,ofn.lpstrFile);
//Add saving file code here
textfile = _tfopen(ofn.lpstrFile,_T("w"));
savedtemp = ofn.lpstrFile;
if(!textfile) return -1;
fprintf(textfile,"Test\n");
fclose(textfile);
}
}
else
{
ShowInfo(hwnd,savedtemp);
//Add saving file code here.
textfile=_tfopen(savedtemp,_T('w"));
if(!textfile) return -1;
fprintf(textfile,"Test\n");
fclose(textfile);
}
break;
Thanks for your help.