mercredi 5 août 2015

Finding the directory path


I'm making a windows application, and right now I can find the path for a file when I click open, but how would I be able to find the directory path? For example, if user selects "file.txt", then I want to get the path of "file.txt".(Its location on the disk). I'm using ATL/WTL, and VS 2013.

OPENFILENAME m_ofn;

BOOL m_bOpenFileDialog = true;  // TRUE for file open, FALSE for file save
TCHAR m_szFileTitle[_MAX_FNAME];// contains file title after return
TCHAR m_szFileName[_MAX_PATH];  // contains full path name after return

memset(&m_ofn, 0, sizeof(m_ofn));
m_szFileName[0] = _T('\0');
m_szFileTitle[0] = _T('\0');

m_ofn.lStructSize = sizeof(m_ofn);

m_ofn.lpstrFile = m_szFileName;
m_ofn.nMaxFile = _MAX_PATH;
m_ofn.lpstrDefExt = _T("bmp");
m_ofn.lpstrFileTitle = (LPTSTR)m_szFileTitle;
m_ofn.nMaxFileTitle = _MAX_FNAME;

m_ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | 
              OFN_OVERWRITEPROMPT | OFN_EXPLORER | 
              OFN_ENABLEHOOK | OFN_ENABLESIZING;

m_ofn.lpstrFilter = _T("Image Files (*.bmp;*.jpg;*.jpe;*.gif;*.tga)\0*.bmp;*.jpg;*.jpe;*.gif;*.tga\0All Files\0*.*\0");
m_ofn.hInstance = ModuleHelper::GetResourceInstance();
m_ofn.lpfnHook = NULL;
m_ofn.hwndOwner = NULL;

BOOL bRet;
bRet = ::GetOpenFileName(&m_ofn);
char gcd;
gcd = GetCurrentDirectory(sizeof(m_ofn), m_szFileName);
m_view.Report("Filename = %S\n", m_szFileName);



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire