- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
案例:连载 需求 对象的永久保存 利用Serialize特性来读写文件 目标 通过菜单生成若干个对象: 龙骑士、口水龙 有图片、位置、生命值以及护盾的信息 通过Serialize的方式将对象的内容保存到文件(图片由程序提供,不记录) 通过Serialize的方式读取文件内容,根据内容重新恢复出文件的对象 程序结构 用一个CUnit作为所有单位的基类,拥有所有单位都会有的属性:图片、生命值、位置、大小 CDragoon和CHydralisk从CUnit中派生出来 其中CDragoon拥有一个特有的属性:护盾值 编程步骤(1) 通过AppWizard生成一个多文档(MDI)工程Serialize MFC为我们生成的类: CAboutDlg CChildFrame CMainFrame CSerializeApp CSerializeDoc CSerializeView 编程步骤(CUnit : 1) 向工程添加一个从CObject派生出的类:CUnit 编程步骤( CUnit : 2) 为CUnit添加一个静态成员,用以记录当前程序运行目录,以方便装载图片: static CString s_sDirectory; 初始化(在任何函数的外部)(静态成员必须初始化): CString CUnit::s_sDirectory = ; 赋值: char fname[MAX_PATH]; GetModuleFileName(NULL, fname, MAX_PATH); CString s; s.Format(%s, fname); s_sDirectory = s.Left(s.ReverseFind(\\)); CString A CString object consists of a variable-length sequence of characters. 它在很大程度上简化了MFC中的许多操作,使得MFC在做字符串操作的时候方便了很多。 GetModuleFileName The GetModuleFileName function retrieves the full path and filename for the executable file containing the specified module. DWORD GetModuleFileName( HMODULE hModule, // handle to module to find filename for LPTSTR lpFilename, // pointer to buffer to receive module path DWORD nSize // size of buffer, in characters ); CString::Format void Format( LPCTSTR lpszFormat, ... ); Call this member function to write formatted data to a CString in the same way that sprintf formats data into a C-style character array. This function formats and stores a series of characters and values in the CString. CString::ReverseFind int ReverseFind( TCHAR ch ) const; The index of the last character in this CString object that matches the requested character; –1 if the character is not found. ch The character to search for. CString::Left CString Left( int nCount ) const; A CString object containing a copy of the specified range of characters. Note that the returned CString object may be empty. nCount The number of characters to extract from this CString object. 编程步骤( CUnit : 3) 为CUnit添加如下成员变量: HBITMAP m_hBitmap; // 位图句柄 HDC m_hDC; //
您可能关注的文档
最近下载
- 数学中考总复习.doc VIP
- 限制型心肌病超声诊断与评估.pptx
- _【课件】第四章 三角形 +问题解决策略:特殊化课件北师大版七年级数学下册.pptx VIP
- 中考数学总复习第一轮考点复习(重庆专版).pptx VIP
- 2025在线网课《信息检索与科技写作( 理大)》单元测试考核答案.pdf VIP
- 高频精选:京东快递员ai面试题及答案.doc VIP
- 新北师大版初中七年级数学下册《第四章三角形问题解决策略:特殊化(1)》教学课件.pptx VIP
- 河北 2023年农信社储蓄知识考试真题模拟汇编(共213题).doc VIP
- 河北 2023年农信社基础知识考试真题模拟汇编(共672题).doc VIP
- 四川省宜宾市2023-2024学年高一下学期期末学业质量监测语文试卷(原卷版+解析版).docx VIP
文档评论(0)