The interesting phenomenon of opening files in the cfile class By lypindream Download source code Apply in preparation dialog boxProgramIn the process, I found a very interesting phenomenon, that is, when you use the open member function of the cfile class to open a file, if the file path is not specified, it will be the path of the current program by default, however, if you use the cfiledialog class in the open file dialog box and open a file, the default path of the open member function file will be the path of the cfiledialog class to open the file. The following details: Cfile: Open Virtual bool open (maid, uint nopenflags, cfileexception * perror = NULL ); Return Value: If it is enabled successfully, a non-0 value is returned; otherwise, 0 is returned. The perror parameter is valid only when 0 is returned. Parameter: lpszfilename: a string that specifies the path of the required file. Nopenflag is a uint value that defines the file sharing and access methods. Perror identifies a pointer to an existing file exception object, which indicates the completion status of the open operation. Note: Open functions are designed to work with the default cfile constructor. I use the followingCodeTo obtain the default path of the currently opened file: Cstring strcurrentpath, strmsg; getcurrentdirectory (200, strcurrentpath. getbuffer (200); strcurrentpath. releasebuffer (); strmsg = _ T ("current file opening path: \ n") + strcurrentpath; MessageBox (strmsg );
The Path obtained when I did not use the File Open dialog box is as follows: The Path obtained when I opened c: \ Program Files \ desktop. ini in the open file dialog box is as follows: If you want to use cfile: open to open the file in the path of the program after using the file open dialog box cfiledialog during programming, you can only use the Windows API function getcurrentdirectory () to obtain the path and save it with variables before using the file open dialog box cfiledialog. The above is a little bit of experience in the programming process of the author. I am very smiling. Please give me more advice. |