Another Stupid Question ...
Ok, I've done a bunch of research looking through the online
version of the MSDN on how to open files (text files in this
case) using Win32 syntax/code and here's what I've come up with
so far ...
OPENFILENAME ofn;
memset(str,0,20);
memset(&ofn,0,sizeof(OPENFILENAME));
ofn.lStructSize=sizeof(OPENFILENAME);
ofn.lpstrFile=str;
ofn.nMaxFile=20;
ofn.Flags=OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY|OFN_EXPLORER;
ofn.lpstrFilter="Text Files (*.txt)\0*.txt\0";
if(GetOpenFileName(&ofn)==FALSE)
return FALSE;
int txtfp = _open(str, O_RDONLY | O_BINARY);
if(txtfp == -1)
return FALSE;
I understand what all this code does for the most part, but the
problem is I dont know what to do next. How do I actually copy the contents of the text file into a buffer to display to the screen, or edit the text found in the .txt file, etc. etc.
Thanks for any help any of you can give :D
BTW - is there a datatype that acts as a array of type char, but doesnt have a set limit?
--
mesHead.
Edited by - mesHead on 12/29/00 11:04:35 AM
mesHead
You need to have a variable that holds the selected file:
Then create a file and open it using szFileName:
Then you proceed to do whatever you want to with the file.
or you can use the Win32 file opening functions CreateFile() and ReadFile(), look them up if that's what you want.
Hope that helps ya.
"We are the music makers, and we are the dreamers of the dreams."
- Willy Wonka
Edited by - BitBlt on December 29, 2000 12:16:56 PM
// at the top where you declare ofnstatic TCHAR szFileName[MAX_PATH]; //creates an array that is able to hold the maximum path allowed in windows// put this so windows knows where to put the file name returned from GetOpenFileName();ofn.lpstrFile = szFileName;
Then create a file and open it using szFileName:
FILE *file;file = fopen(szFileName, "wrt"); // opens szFileName with read and write access in text mode
Then you proceed to do whatever you want to with the file.
or you can use the Win32 file opening functions CreateFile() and ReadFile(), look them up if that's what you want.
Hope that helps ya.
"We are the music makers, and we are the dreamers of the dreams."
- Willy Wonka
Edited by - BitBlt on December 29, 2000 12:16:56 PM
you also may want to change ofn.nMaxFile=20; to ofn.nMaxFile=MAX_PATH, otherwise, if the returned path is more than twenty characters (which is probable), the extra characters will be cut off and your file path is incomplete.
"We are the music makers, and we are the dreamers of the dreams."
- Willy Wonka
"We are the music makers, and we are the dreamers of the dreams."
- Willy Wonka
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement