VC++ 程序设计ppt

上传人:油条 文档编号:47549940 上传时间:2018-07-02 格式:PPT 页数:38 大小:84KB
返回 下载 相关 举报
VC++ 程序设计ppt_第1页
第1页 / 共38页
VC++ 程序设计ppt_第2页
第2页 / 共38页
VC++ 程序设计ppt_第3页
第3页 / 共38页
VC++ 程序设计ppt_第4页
第4页 / 共38页
VC++ 程序设计ppt_第5页
第5页 / 共38页
点击查看更多>>
资源描述

《VC++ 程序设计ppt》由会员分享,可在线阅读,更多相关《VC++ 程序设计ppt(38页珍藏版)》请在金锄头文库上搜索。

1、VC+ 入门与提高主讲教师:贾澎涛第六章 应用实例之一编写一 个具有实用功能的字处理软件本篇经典n文档和视图是怎样联系起来的?n如何为程序添加查找、替换等功能?n为什么在某些程序新创建的菜单中只输入了一个菜 单ID标识就可以实现某一种功能?n怎样为程序添加一个浮动菜单?n如何在“帮助关于”对话框中添加系统信息?n怎样为应用程序做一个每日提示(在程序启动时显 示)?n如何动态修改菜单n怎样为应用程序增加一个日历?n怎样修改应用程序标题栏上的显示文字?n怎样使应用程序以最大化窗口显示?n怎样在应用程序的状态条上显示时间?n怎样使应用程序支持拖放功能?n怎样建立一个文件打开、保存对话框?n如何为应用

2、程序添加一个闪屏?n如何使用字体、颜色对话框?n如何处理文字输入?n如何实现应用程序对数据的读出和写入?14.如何为应用程序添加一个闪屏 ?1)打开工程项目EditSoft; (2)选择“ProjectAdd to ProjectComponents and Controls”将出现组件和控件库对话框,双击部件文 件夹(Visual C+ Components),选择Splash screen,双 击。出现插入部件确认对话框,选择“确定”,出现部 件类的实现文件和头文件的文件名对话框,保留缺省 值,选择“OK”按钮。 (3)将返回到“Components and Controls Galler

3、y”,单击 “Close”,插入过程完成。 (4)编译、连接并运行。(5)我们发现主窗口和闪屏同时出现了,所以修改应用 类的InitInstance()函数,隐藏主窗口。pMainFrame-ShowWindow(SW_HIDE); (6)图形界面不美观。设计一张位图,在启动窗口显示 。 可以在ResourceView中删除原有的图片,插入你想 要的闪屏图片,然后将其ID改为IDS_SPLASH。或按 照以下方法加入一个真彩图片。 (7)下一步我们来实现装载24位真彩位图的,我们直接 采用读入文件的方式,所以我们将闪屏类的Create函 数改写成下面这样。BOOL CSplashWnd:Cre

4、ate(CWnd* pParentWnd /*= NULL*/) HBITMAP hBitmap=(HBITMAP)LoadImage(NULL,_T(“SnpSplash.bmp“),/图像文件名称 ,注意换成你的文件名称。 IMAGE_BITMAP,/读入位图,还可以设定为读入图标或鼠 标指针 0,/位图宽 0,/位图高 LR_CREATEDIBSECTION/创建DibSection |LR_LOADFROMFILE);/从文件读 if(hBitmap=NULL) return false; m_bitmap.Attach(hBitmap);/获得位图指针 BITMAP bm; m_bi

5、tmap.GetBitmap(return CreateEx(0, AfxRegisterWndClass(0, AfxGetApp()- LoadStandardCursor(IDC_ARROW), NULL, WS_POPUP | WS_VISIBLE, 0, 0, bm.bmWidth, bm.bmHeight, pParentWnd-GetSafeHwnd(), NULL); (8)最后我们来完成闪屏消失,主窗口显示的部分 void CSplashWnd:HideSplashScreen() / Destroy the window, and update the mainframe.

6、 DestroyWindow(); AfxGetApp()-m_pMainWnd- ShowWindow(SW_SHOWMAXIMIZED);/恢复了我们的最大 化主窗口 AfxGetApp()-m_pMainWnd-UpdateWindow();说明nCBitmap The CBitmap class encapsulates a Windows graphics device interface (GDI) bitmap and provides member functions to manipulate the bitmap. To use a CBitmap object, cons

7、truct the object, attach a bitmap handle to it with one of the initialization member functions, and then call the objects member functions.nLoadImage The LoadImage function loads an icon, cursor, or bitmap. HANDLE LoadImage( HINSTANCE hinst, / handle of the instance containing the image LPCTSTR lpsz

8、Name, / name or identifier of image UINT uType, / type of image int cxDesired, / desired width int cyDesired, / desired height UINT fuLoad / load flags ); 15.如何使用字体、颜色对话框 ?与文件对话框一样,字体、颜色对话框也是 Windows通用对话框的两个重要成员,他们是从 CCommonDialog类派生出来的,通过调用 Windows的COMMDLG.DLL动态连接库实现。 在大多数的字处理软件中,字体和颜色对话框的 实现均放置在视图

9、类中并将其结果返回给文档类 ,以便于文档对字体和颜色进行保存和维护,视 图类则通过调用GetDocument()函数或的文档 的字体和颜色。通用对话框的调用分三个步骤: (1)用MFC的封装类创建一个对话框对象,要确定 已经把参数传递给对象的构造函数以初始化对话框; (2)对象调用DoModal()成员函数,从DoModal()的返 回值标明对话框存在的方式(IDOK或IDCCANCLE) ; (3)如果DoModal()函数返回IDOK,则把公用对话框 的成员函数的返回值赋与用户。使用字体对话框n在字体对话框的操作中,用户进行的操作结 果存放在CFontDialog的数据变量m_cf中, m

10、_cf 是一个保存字体对话框对象属性的一个结构, 在构造CFontDialog对象之后,在调用DoModal() 函数之前,可使用m_cf修改对话框的各种属性 。CFontDialogThe CFontDialog class allows you to incorporate a font- selection dialog box into your application. A CFontDialog object is a dialog box with a list of fonts that are currently installed in the system. The us

11、er can select a particular font from the list, and this selection is then reported back to the application. CFontDialog:CFontDialog ( LPLOGFONT lplfInitial = NULL, DWORD dwFlags = CF_EFFECTS | CF_SCREENFONTS, CDC* pdcPrinter = NULL, CWnd* pParentWnd = NULL );CFontDialog Class Members DoModalDisplays

12、 the dialog and allows the user to make a selection. GetCurrentFontRetrieves the name of the currently selected font. GetFaceNameReturns the face name of the selected font. GetStyleNameReturns the style name of the selected font. GetSizeReturns the point size of the selected font. GetColorReturns th

13、e color of the selected font. GetWeightReturns the weight of the selected font. IsStrikeOutDetermines whether the font is displayed with strikeout. IsUnderlineDetermines whether the font is underlined. IsBoldDetermines whether the font is bold. IsItalicDetermines whether the font is italic.(1)新建一个工程

14、EditScroll,在Step 6中将视图类的基 类改为CScollView类。 (2)在“编辑”菜单下增加子菜单:字体,ID: ID_EDIT_FONT。为其增加消息处理函数。 (3)在文档类的定义中添加如下代码:CString m_Text; /定义一个存放文本的字符串变量CFont m_Font;/定义一个字体变量 LOGFONT m_lf; /定义一个LOGFONT结构变量 CPoint m_StartPoint; /定义文字的初始显示位置(4)在字体的消息处理函数中添加如下代码:void CEditScollView:OnEditFont() CEditScollDoc *pDoc

15、=GetDocument(); ASSERT_VALID(pDoc); CFontDialog FontDlg( /定义一个字体对话框对象 FontDlg.DoModal(); /调用字体对话框 InvalidateRect(NULL); /通知视图数据已经改变,请刷新 (5)在视图类的OnDraw()函数中编辑显示代码:/ TODO: add draw code for native data here int nOldMode=pDC-SetBkMode(TRANSPARENT); pDoc-m_Font.CreateFontIndirect( CFont *pOldFont=pDC-Se

16、lectObject( pDC-TextOut(pDoc-m_StartPoint.x,pDoc- m_StartPoint.y,pDoc-m_Text); pDC-SelectObject(pOldFont); pDoc-m_Font.DeleteObject(); pDC-SetBkMode(nOldMode);(6)在文档类的新建文件函数OnNewDocument中初始 化有关变量。然后编译连接。 / (SDI documents will reuse this document) m_Text=“同学们好!“; m_StartPoint=CPoint(0,0); m_lf.lfHeight=20; m_lf.lfWidth=0; m_lf.lfEscapement=0; m_lf.lfOrientation=0; m_lf.lfWeight=FW_NORMAL; m_lf.lfItalic=0; m_lf.

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号