Opening files with a directory browser?

This is a discussion on Opening files with a directory browser? within the Windows Programming forums, part of the Platform Specific Boards category; what im trying to is make it when the person clicks the button to open a file it brings up ...

  1. #1
    Labelizm
    Guest

    Opening files with a directory browser?

    what im trying to is make it when the person clicks the button to open a file it brings up that little window that has directory listings and what not and lets them browse arround looking for the file they want to open.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Look up the OPENFILENAME struct on MSDN..

    Set the members that you need (lStructSize, hInstance,lpstrFilter, lpstrFile, nMaxFile, Flags....etc)

    The use GetOpenFileName()

    On return of that function, the structure you sent will contain the info you need to open the file

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    I believe i have answered this question before:

    Originally posted by Okiesmokie
    heres a function i made that i used in my text-editor that brings up the open file dialog box, and lets the use pick a file to open, then loads it to the edit box

    Code:
    void FileOpen(HWND hwnd, HWND hEdit)
    {
    #define MAX_PATHSIZE 256
    
    	OPENFILENAME	ofn;
    	char			FileName[MAX_PATHSIZE] = "";
    	HANDLE			hFile;
    
    	ZeroMemory(&ofn, sizeof(ofn));
    
    	ofn.lStructSize		= sizeof(ofn);
    	ofn.hwndOwner		= hwnd;
    	ofn.lpstrFilter		= "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
    	ofn.lpstrFile		= FileName;
    	ofn.nMaxFile		= MAX_PATHSIZE;
    	ofn.Flags			= OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
    	ofn.lpstrDefExt		= "txt";
    
    	if(GetOpenFileName(&ofn))
    	{
    	}
    
    	hFile = CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
    
    	if(hFile != INVALID_HANDLE_VALUE)
    	{
    		DWORD dwFileSize;
    
    		dwFileSize = GetFileSize(hFile, NULL);
    
    		if(dwFileSize != 0xFFFFFFFF)
    		{
    			LPSTR FileText;
    
    			SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)"Opening...");
    
    			FileText = (LPSTR)GlobalAlloc(GPTR, dwFileSize + 1);
    
    			if(FileText != NULL)
    			{
    				DWORD dwRead;
    
    				if(ReadFile(hFile, FileText, dwFileSize, &dwRead, NULL))
    				{
    					FileText[dwFileSize] = 0;	// Set the NULL terminator
    
    					SetWindowText(hEdit, FileText);
    				}
    				GlobalFree(FileText);
    			}
    		}
    		CloseHandle(hFile);
    	}
    }
    "There are three kinds of people in the world...
    Those that can count and those that can't."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Listing specific files in a directory
    By knirirr in forum C Programming
    Replies: 14
    Last Post: 01-29-2008, 05:42 AM
  2. Finding files in a directory
    By smarta_982002 in forum C Programming
    Replies: 1
    Last Post: 01-25-2008, 10:10 AM
  3. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 02:30 PM
  4. opening files sequentially
    By barneygumble742 in forum C++ Programming
    Replies: 9
    Last Post: 12-21-2006, 11:26 AM
  5. Opening files - Giving options?
    By wwwGazUKcom in forum C++ Programming
    Replies: 3
    Last Post: 09-18-2001, 08:06 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21