从MFC类继承的基本方式

来源:互联网 发布:php做app后端 编辑:程序博客网 时间:2024/05/19 16:33

Version VS2008

继承CString类的基本方式 

#pragma onceclass CPathString :public CString{public:CPathString(void);virtual ~CPathString(void);CString GetFileExtend(void);CString GetFileName(void);CString GetFileBase(void);CString GetFilePath(void);using CString::operator =;};


这是实现文件

#include "StdAfx.h"#include "PathString.h"CPathString::CPathString(void){}CPathString::~CPathString(void){}CString CPathString::GetFileExtend(void){CString s;int nSlash = ReverseFind('\\');int nDot = ReverseFind('.');if (nDot != -1 && nDot > nSlash)s = Mid(nDot + 1);return s;}CString CPathString::GetFileName( void ){CString s;int nSlash = ReverseFind('\\');if (nSlash != -1)s = Mid(nSlash + 1);elses = GetString();return s;}CString CPathString::GetFileBase( void ){CString s = GetFileName();int nDot = s.ReverseFind('.');if (nDot != -1)s = s.Left(nDot);return s;}CString CPathString::GetFilePath( void ){CString s;int nSlash = ReverseFind('\\');if (nSlash != -1)s = Left(nSlash);return s;}


void CInherentView::OnDraw(CDC* pDC){CInherentDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);if (!pDoc)return;// TODO: add draw code for native data hereCString s;CPathString path;static TCHAR buff[MAX_PATH];::GetModuleFileName(NULL, buff, MAX_PATH);path = buff;CSize sz = pDC->GetTextExtent("A", 1);int y = 0;s.Format("File Extension: \"%s\"", path.GetFileExtend());pDC->TextOut(2, y, s);y += sz.cy;s.Format("File Name: \"%s\"", path.GetFileName());pDC->TextOut(2, y, s);y += sz.cy;s.Format("File Base: \"%s\"", path.GetFileBase());pDC->TextOut(2, y, s);y += sz.cy;s.Format("File Path: \"%s\"", path.GetFilePath());pDC->TextOut(2, y, s);y += sz.cy;}




引发我的思考 ReverseFind函数的操作对象 当path调用时 path作为隐藏的参数传到函数中 函数中所有的成员变量和成员函数前面都应该加上这个参数 
原创粉丝点击