Get the File Location into an Edit Box

All questions regarding Windows programming, post here. API,COM, ActiveX, DirectX, OpenGL, MFC and so on...

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

Get the File Location into an Edit Box

Postby WRV » Wed Jul 30, 2008 8:39 pm

I need to find a way to use an Open Dialog to let the user choose a file then have the file's location in an Edit box. I know how to open the contents of a file and put them on a text box but I'm not sure about the location.
WRV
 
Posts: 1
Joined: Wed Jul 30, 2008 6:04 pm

Postby Dante Shamest » Wed Jul 30, 2008 8:58 pm

To create an Open File Dialog, you can use the GetOpenFileNamefunction.

[syntax="cpp"]#include <windows.h>

bool openFileDialog( HWND hwndOwner, TCHAR* strFile ){
OPENFILENAME ofn = {0};

ofn.lStructSize = sizeof(OPENFILENAME);
ofn.lpstrTitle = TEXT("Open File") ;
ofn.lpstrFileTitle = 0 ;
ofn.hwndOwner = hwndOwner ;
ofn.lpstrFilter = TEXT("*.*\0*.*\0") ;
ofn.lpstrFile = strFile ;
ofn.nMaxFile = MAX_PATH;
ofn.nMaxFileTitle = MAX_PATH;
ofn.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_NOCHANGEDIR ;

if ( ::GetOpenFileName(&ofn) != 0 ) {
return true ;
}

return false ;
}

int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrev, LPSTR args, int nShow ) {
TCHAR filePath[MAX_PATH] = {0};
if ( openFileDialog( NULL, filePath ) ) {
MessageBox( NULL, filePath, TEXT("You selected..."), MB_OK );
}
return 0 ;
}[/syntax]
User avatar
Dante Shamest
Moderator
 
Posts: 3131
Joined: Wed Oct 22, 2003 10:29 pm
Location: Malaysia


Return to Windows Programming

Who is online

Users browsing this forum: No registered users and 0 guests