I'm taking a new direction on this at the time. What I'm doing now is storing the title, date, author, and poem (all max 255 characters) into arrays (seperate ones). Then, I use body (which is CString) to format how the data will be saved (title::author::date\n\npoem). I can get all the information from the edit boxes fine, and I can save it the way I want. My new problem arises when trying to open it.
I was reading a post in the C Programming boards here, and Prelude (I believe) showed how to read in information. But, whenever I try to open the file, I get crap as text. As far as I know it's loading it all in correctly, just not displaying it correctly. Here's what I'm using for it:
Code:
//* in header file: DWORD dwBytesWritten *//
// start code
char title[255], date[255], author[255], poem[255];
char *body = NULL;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.lpstrFilter = "\0Poetry Editor File (*.pef)\0*.pef\0\0";
if(GetOpenFileName(&ofn) == TRUE){
hFile = CreateFile((LPCTSTR)ofn.lpstrFile,
GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if(hFile != INVALID_HANDLE_VALUE){
if(sscanf((LPCTSTR)body, "%255[^::]%*c%255[^::]%*c%255[^::]%*c%1024[^::]", title, author, date, poem)){
if(ReadFile(hFile, body, strlen(body), &dwBytesWritten, NULL) == FALSE){
AfxMessageBox("Unable to read poem from file!");
}
}
if(CloseHandle(hFile) == FALSE){
AfxMessageBox("Unable to close HANDLE hFile properly!");
}
}
m_poem.SetWindowText(poem);
m_authorsname.SetWindowText(author);
m_poemtitle.SetWindowText(title);
m_datewritten.SetWindowText(date);
}
:<<EDIT>>: This program is a dialog, and I was also wondering something else. How would I load certain text stored in a file at loadtime? I've tried putting the code into the InitDialog() function just before the "return TRUE;" at the bottom of the function. Everytime I do it though, it crashes.