How do I Set the default Location for Saving Files??
-
Hi, I have a Single Doc, Multiple views Application and I have a Menu option called "options" which accepts the Default location to Save Files. How do I set the Default Location ?What is the Function used and How do I use it? so that, when the user says File->Save, it should show the deafault directory to save the file. Any Suggestions... Thank you Priya
-
Hi, I have a Single Doc, Multiple views Application and I have a Menu option called "options" which accepts the Default location to Save Files. How do I set the Default Location ?What is the Function used and How do I use it? so that, when the user says File->Save, it should show the deafault directory to save the file. Any Suggestions... Thank you Priya
Try this code [CODE]
OPENFILENAME ofn;
char defaultFileName[MAX_PATH + 1] = "Default file name";
char szFileTitle[MAX_PATH + 1];
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = NULL;
ofn.hInstance = GetModuleHandle(NULL);
ofn.lpstrFilter = "All Files (*.*)\0*.*\0\0";
ofn.lpstrCustomFilter = (LPTSTR) NULL;
ofn.nMaxCustFilter = 0L;
ofn.nFilterIndex = 1L;
ofn.lpstrFile = defaultFileName;
ofn.nMaxFile = sizeof(defaultFileName);
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = MAX_PATH;
ofn.lpstrInitialDir = "C:\\DefaultDir";
ofn.lpstrTitle = __TEXT("Save Da Doc as...");
ofn.nFileOffset = 0;
ofn.nFileExtension = 0;
ofn.lpstrDefExt = NULL;
ofn.lCustData = 0;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_EXPLORER | OFN_LONGNAMES;
int result = GetSaveFileName(&ofn);
if (result == IDOK) {
MessageBox(defaultFileName,"Full Path is ");
MessageBox(szFileTitle,"File Name only is ");
}
[CODE] Note There is also easier ways with MFC ... :D Hope It will help ALfadhly -
Hi, I have a Single Doc, Multiple views Application and I have a Menu option called "options" which accepts the Default location to Save Files. How do I set the Default Location ?What is the Function used and How do I use it? so that, when the user says File->Save, it should show the deafault directory to save the file. Any Suggestions... Thank you Priya
SetCurrentDirectory The SetCurrentDirectory function changes the current directory for the current process. BOOL SetCurrentDirectory( LPCTSTR lpPathName // pointer to name of new current directory ); Parameters lpPathName Pointer to a null-terminated string that specifies the path to the new current directory. This parameter may be a relative path or a fully qualified path. In either case, the fully qualified path of the specified directory is calculated and stored as the current directory. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError. Remarks Each process has a single current directory made up of two parts: A disk designator that is either a drive letter followed by a colon, or a server name and share name (\\servername\sharename) A directory on the disk designator
-
SetCurrentDirectory The SetCurrentDirectory function changes the current directory for the current process. BOOL SetCurrentDirectory( LPCTSTR lpPathName // pointer to name of new current directory ); Parameters lpPathName Pointer to a null-terminated string that specifies the path to the new current directory. This parameter may be a relative path or a fully qualified path. In either case, the fully qualified path of the specified directory is calculated and stored as the current directory. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError. Remarks Each process has a single current directory made up of two parts: A disk designator that is either a drive letter followed by a colon, or a server name and share name (\\servername\sharename) A directory on the disk designator
SetCurrentDirectory Changes the current directory for the current process This means that if your program is writting to temporary files or reading from other files you will be effecting the location of all subsequent File I/O operations which you don't specify the Exact Directory location for. Do you really want to do that.? Alfadhly
-
SetCurrentDirectory Changes the current directory for the current process This means that if your program is writting to temporary files or reading from other files you will be effecting the location of all subsequent File I/O operations which you don't specify the Exact Directory location for. Do you really want to do that.? Alfadhly
No this means that you do a GetCurrentDirectory SetCurrentDirectory, do your file saving and return to the directory that you retrieved with GetCurrentDirectory. But anyway, as you never can be sure what the current directory is, unless you set it yourself,you should never try to read/write without an exact directory location and temorary files should go into the TEMP variable or the winnt\system.
-
No this means that you do a GetCurrentDirectory SetCurrentDirectory, do your file saving and return to the directory that you retrieved with GetCurrentDirectory. But anyway, as you never can be sure what the current directory is, unless you set it yourself,you should never try to read/write without an exact directory location and temorary files should go into the TEMP variable or the winnt\system.
You will be pleasantly surprised to find that Windows Terminal Services Edition might prevent you from writing altogether to the Windows\System folder. There is a call to obtain the temporary directory that should be used, I think it is GetTempDirectory(). Since Windows 2000 might allow multiple logons, I have noticed that the temporary directory is different for each user.
-
You will be pleasantly surprised to find that Windows Terminal Services Edition might prevent you from writing altogether to the Windows\System folder. There is a call to obtain the temporary directory that should be used, I think it is GetTempDirectory(). Since Windows 2000 might allow multiple logons, I have noticed that the temporary directory is different for each user.