Hi evryone
I using MVC++ and built my project using Win32 app.
My program do not have any interfaces. it reads files and it put the output in another file. ( I do not mind put interface only to enter the path)

the thing is I made my program read the input file from specific directory and put the output in the specify directory. the probelm now is that I would like the user to inter the dirctory of the input file and the output file is this possible if yes, please tell me how to do it, I do not have any idea.

"C:\\Wadi\\In\\Log_01.csv" my in file directory
"C:\\Wadi\\Out\\Daily_Summary_%d.csv" my out file directory

now I would like to enable the user to enter his path for the input file and the output file.

Recommended Answers

All 3 Replies

Look in MSDN for GetOpenFileName and SetSaveFileName functions.

Look in MSDN for GetOpenFileName and SetSaveFileName functions.

Hi have this

LPTSTR CommonD_OpenFile()


    {
    
		char* lpszFileName;
    		OPENFILENAME ofn; // common dialog box structure
    	char szFile[260]; // buffer for file name
    	HWND hwnd; // owner window
		hwnd = 0;
		// Initialize OPENFILENAME
    	ZeroMemory(&ofn, sizeof(ofn));
    	ofn.lStructSize = sizeof(ofn);
    	ofn.hwndOwner = hwnd;
    	ofn.lpstrFile = szFile;
    	//
    	// Set lpstrFile[0] to '\0' so that GetOpenFileName does not 
    	// use the contents of szFile to initialize itself.
    	//
    	ofn.lpstrFile[0] = '\0';
    	ofn.nMaxFile = sizeof(szFile);
    	ofn.lpstrFilter = "Bitmap Files\0*.csv\0";
    	ofn.nFilterIndex = 1;
    	ofn.lpstrFileTitle = NULL;
    	ofn.nMaxFileTitle = 0;
    	ofn.lpstrInitialDir = NULL;
    	ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
		// Display the Open dialog box. 
		if (GetOpenFileName(&ofn)==TRUE) //Or use GetSaveFileName, same work


        	{
        		int i = (int)strlen(ofn.lpstrFile);
        		lpszFileName = new char[i+10];//init buffer to size needed
        		strcpy(lpszFileName,ofn.lpstrFile); //copy over the file name
        		return(lpszFileName); 
        	}
        	else


            	{
            		lpszFileName = new TCHAR[2];
            		lpszFileName[0]= __TEXT('\0');
            		return (lpszFileName);
		}
        }

then I call it in main
what I would like to do is. I going to post my program to the user. so I would like to enable the user to enter the path for the input file and the output file for the first time and then the system suppose to remember the path and work upon it.

Why not have your program use cmd line arguments. Then your user can specify the output directiry when invoking the prog.

Eg:

prog "D:\output Dir1"

would inform the program to write the output to:
"D:\output Dir1\Daily_Summary_%d.csv"

You could even have then specify the output file name as well.

The advantages of using cmd line args include:
- no gui components required (smaller exe0
- can be called as part of automated scripts without user intervention.
- the code can be compatible with windows & unix

Just look up 'argc & argv' arguments to main() to see how to use cmd line args in your program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.