Click here to Skip to main content
15,896,201 members
Articles / Desktop Programming / MFC

XFileProperties - A modeless dialog to display file properties

Rate me:
Please Sign up or sign in to vote.
4.73/5 (13 votes)
13 Jun 2003CPOL3 min read 69.3K   1.2K   31  
XFileProperties demonstrates the use of CXFileProperties, a class that displays a modeless dialog similar to the Windows file properties dialog.
//////////////////////////////////////////////////////////////////////
// XSplitPath.h : interface for the CSplitPath class.
// (c) 1999, Kevin Lussier
//
// Modified by Hans Dietrich
//////////////////////////////////////////////////////////////////////

#ifndef XSPLITPATH_H
#define XSPLITPATH_H

// Example usage
///CSplitPath sp( "C:\\Temp\\Foo.txt" );
// cout << "Drive: " << sp.GetDrive()
// cout << "Directory: " << sp.GetDirectory();
// cout << "File Name: " << sp.GetFileName();
// cout << "Extension: " << sp.GetExtension();

class CSplitPath
{
// Construction
public:
	CSplitPath(LPCTSTR lpszPath)
	{
		// initialize our objects
		memset(path_buffer, 0, sizeof(path_buffer));
		memset(drive, 0, sizeof(drive));
		memset(dir, 0, sizeof(dir));
		memset(fname, 0, sizeof(fname));
		memset(ext, 0, sizeof(ext));
		memset(computername, 0, sizeof(computername));
		memset(sharename, 0, sizeof(sharename));

		Split(lpszPath);
	}

// Operations
	BOOL Split(LPCTSTR lpszPath)
	{
		// if we weren't given a path, fail
		if (lpszPath == NULL || lpszPath[0] == _T('\0'))
			return FALSE;

		// copy the path
		_tcsncpy(path_buffer, lpszPath, sizeof(path_buffer)/sizeof(TCHAR) - 1);
		// split the given path
		_tsplitpath(path_buffer, drive, dir, fname, ext);

		if (IsUNC())
		{
			// Get the computername
			_tcsncpy(computername, _tcsstr(dir, _T("\\\\"))+2, sizeof(computername)/sizeof(TCHAR)-1);
			_tcsnset(_tcsstr(computername, _T("\\")), 0, 1);

			// Strip the computername from the directory
			_tcsncpy(dir, _tcsstr(dir, _T("\\\\"))+2, sizeof(dir)/sizeof(TCHAR)-1);
			_tcsncpy(dir, _tcsstr(dir, _T("\\")), sizeof(dir)/sizeof(TCHAR)-1);

			// Get the share name
			_tcsncpy(sharename,_tcsstr(dir, _T("\\"))+1, sizeof(sharename)/sizeof(TCHAR)-1);
			_tcsnset(_tcsstr(sharename, _T("\\")), 0, 1);

			// Strip the share name from the directory
			_tcsncpy(dir, _tcsstr(dir, _T("\\"))+1, sizeof(dir)/sizeof(TCHAR)-1);
			_tcsncpy(dir, _tcsstr(dir, _T("\\")), sizeof(dir)/sizeof(TCHAR)-1);
		}

		return TRUE;
	}

	CString GetPath(void)         { return path_buffer; }
    CString GetDrive(void)        { return drive; }
    CString GetDirectory(void)    { return dir; }
    CString GetFileName(void)     { return fname; }
    CString GetExtension(void)    { return ext; }
	CString GetComputerName(void) { return computername; }
	CString GetShare(void)        { return sharename; }
	BOOL IsUNC(void) { return (_tcsncmp(path_buffer,_T("\\\\"), 2) == 0); }

// Attributes
protected:
	TCHAR path_buffer[_MAX_PATH];
	TCHAR drive[_MAX_DRIVE];
	TCHAR dir[_MAX_DIR];
	TCHAR fname[_MAX_FNAME];
	TCHAR ext[_MAX_EXT];
	TCHAR computername[_MAX_FNAME];
	TCHAR sharename[_MAX_FNAME];
};

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Hans Dietrich Software
United States United States
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.

Recently, I have moved to Los Angeles where I am doing consulting and development work.

For consulting and custom software development, please see www.hdsoft.org.






Comments and Discussions