ImageVerifierCode 换一换
格式:DOCX , 页数:19 ,大小:22.72KB ,
资源ID:23060514      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/23060514.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(修改应用程序外观.docx)为本站会员(b****2)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

修改应用程序外观.docx

1、修改应用程序外观修改应用程序外观建立一个单文档的MFC应用程序,修改一个应用程序的外观和大小,要在应用程序的窗口创建之前去修改,1.在CMainFrame类的PrecreateWindow()函数中去创建。BOOLCMainFrame:PreCreateWindow(CREATESTRUCT&cs)if(!CFrameWnd:PreCreateWindow(cs)returnFALSE;/TODO:ModifytheWindowclassorstylesherebymodifying/theCREATESTRUCTcscs.cx=300;/宽度cs.cy=200;/高度/cs.style&=F

2、WS_ADDTOTITLE;/cs.style=cs.style&FWS_ADDTOTITLE;/这两个表达式一样cs.style=WS_OVERLAPPEDWINDOW;/也可以直接给这个类型赋值cs.lpszName=维唯为为;/窗口标题returnTRUE;2.用SetWindowLong在窗口创建之后改变外观,在CMainFrame类中的OnCreate()函数中去编写代码。intCMainFrame:OnCreate(LPCREATESTRUCTlpCreateStruct)if(CFrameWnd:OnCreate(lpCreateStruct)=-1)return-1;if(!m

3、_wndToolBar.CreateEx(this,TBSTYLE_FLAT,WS_CHILD|WS_VISIBLE|CBRS_TOP|CBRS_GRIPPER|CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_SIZE_DYNAMIC)|!m_wndToolBar.LoadToolBar(IDR_MAINFRAME)TRACE0(Failedtocreatetoolbarn);return-1;/failtocreateif(!m_wndStatusBar.Create(this)|!m_wndStatusBar.SetIndicators(indicators,sizeof(in

4、dicators)/sizeof(UINT)TRACE0(Failedtocreatestatusbarn);return-1;/failtocreate/TODO:Deletethesethreelinesifyoudontwantthetoolbarto/bedockablem_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);EnableDocking(CBRS_ALIGN_ANY);DockControlBar(&m_wndToolBar);/修改窗口的外观/SetWindowLong(m_hWnd,GWL_STYLE,WS_OVERLAPPEDWIND

5、OW);/修改现有窗口的类型SetWindowLong(m_hWnd,GWL_STYLE,GetWindowLong(m_hWnd,GWL_STYLE)&WS_MAXIMIZEBOX);/使最大化图标变灰return0;3.编写自己的窗口类在CMainFrame:PreCreateWindow(CREATESTRUCT& cs)函数中添加:WNDCLASSwndcls;/定义一个窗口类wndcls.cbClsExtra=0;/类的额外内存,0,不需要wndcls.cbWndExtra=0;/窗口的额外内存,0,不需要wndcls.hbrBackground=(HBRUSH)GetStockOb

6、ject(BLACK_BRUSH);/背景wndcls.hCursor=LoadCursor(NULL,IDC_HELP);/NULL,指定标准光标/注:要改变窗口的背景和光标要在View类中去改变,因View窗口覆盖在Frame窗口之上wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);/图标wndcls.hInstance=AfxGetInstanceHandle();/获取当前应用程序的句柄wndcls.lpfnWndProc=:DefWindowProc;/窗口过程用缺省的,函数名指函数的地址wndcls.lpszClassName=luowei.org;/类的

7、名字wndcls.lpszMenuName=NULL;wndcls.style=CS_HREDRAW|CS_VREDRAW;/水平重画,垂直重画RegisterClass(&wndcls);/注册窗口类cs.lpszClass=luowei.org;在CStyleView:PreCreateWindow(CREATESTRUCT& cs)函数中添加:BOOL CStyleView:PreCreateWindow(CREATESTRUCT& cs) / TODO: Modify the Window class or styles here by modifying / the CREATEST

8、RUCT cs /修改窗口类 cs.lpszClass=luowei.org;/修改成自己定义的类 return CView:PreCreateWindow(cs);4.利用AfxRegisterWnd函数修改在CMainFrame:PreCreateWindow 中添加:cs.lpszClass=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,0,0,LoadIcon(NULL,IDI_WARNING);/cs.lpszClass=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW)/设置成缺省值AfxRegisterWnd

9、Class LPCTSTR AFXAPI AfxRegisterWndClass( UINT nClassStyle, HCURSOR hCursor = 0, HBRUSH hbrBackground = 0, HICON hIcon = 0 ); Return ValueA null-terminated string containing the class name. You can pass this class name to the Create member function in CWnd or other CWnd-derived classes to create a w

10、indow. The name is generated by the Microsoft Foundation Class Library.NoteThe return value is a pointer to a static buffer. To save this string, assign it to a CString variable. ParametersnClassStyleSpecifies the Windows class style or combination of styles, created by using the bitwise-OR (|) oper

11、ator, for the window class. For a list of class styles, see the WNDCLASS structure in the Win32 SDK documentation. If NULL, the defaults will be set as follows: Sets the mouse style to CS_DBLCLKS, which sends double-click messages to the window procedure when the user double-clicks the mouse.Sets th

12、e arrow cursor style to the Windows standard IDC_ARROW.Sets the background brush to NULL, so the window will not erase its background.Sets the icon to the standard, waving-flag Windows logo icon. hCursorSpecifies a handle to the cursor resource to be installed in each window created from the window

13、class. If you use the default of 0, you will get the standard IDC_ARROW cursor.hbrBackgroundSpecifies a handle to the brush resource to be installed in each window created from the window class. If you use the default of 0, you will have a NULL background brush, and your window will, by default, not

14、 erase its background while processing WM_ERASEBKGND.hIconSpecifies a handle to the icon resource to be installed in each window created from the window class. If you use the default of 0, you will get the standard, waving-flag Windows logo icon.RemarksThe Microsoft Foundation Class Library automati

15、cally registers several standard window classes for you. Call this function if you want to register your own window classes.The name registered for a class by AfxRegisterWndClass depends solely on the parameters. If you call AfxRegisterWndClass multiple times with identical parameters, it only regis

16、ters a class on the first call. Subsequent calls to AfxRegisterWndClass with identical parameters simply return the already-registered classname.If you call AfxRegisterWndClass for multiple CWnd-derived classes with identical parameters, instead of getting a separate window class for each class, eac

17、h class shares the same window class. This can cause problems if the CS_CLASSDC class style is used. Instead of multiple CS_CLASSDC window classes, you end up with one CS_CLASSDC window class, and all C+ windows that use that class share the same DC. To avoid this problem, call AfxRegisterClass to r

18、egister the class.在CStyleView:PreCreateWindow(CREATESTRUCT& cs)中修改:BOOLCStyleView:PreCreateWindow(CREATESTRUCT&cs)/TODO:ModifytheWindowclassorstylesherebymodifying/theCREATESTRUCTcs/修改窗口类/cs.lpszClass=luowei.org;/修改成自己定义的类/修改背景和光标cs.lpszClass=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,LoadCursor(NULL

19、,IDC_CROSS),(HBRUSH)GetStockObject(BLACK_BRUSH),0);/cs.lpszClass=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW)/设置成缺省值returnCView:PreCreateWindow(cs);5.窗口创建之后,再创建图标,光标及背景 利用SetClassLong函数,在CMainFrame:OnCreate(LPCREATESTRUCT lpCreateStruct)函数中添加:/修改图标 SetClassLong(m_hWnd,GCL_HICON,(LONG)LoadIcon(NULL,IDI

20、_ERROR);修改光标和背景,对CStyleView类添加一个WM_CREATE消息响应,编辑:intCStyleView:OnCreate(LPCREATESTRUCTlpCreateStruct)if(CView:OnCreate(lpCreateStruct)=-1)return-1;/TODO:Addyourspecializedcreationcodehere/修改背景SetClassLong(m_hWnd,GCL_HBRBACKGROUND,(LONG)GetStockObject(BLACK_BRUSH);/修改光标SetClassLong(m_hWnd,GCL_HCURSOR

21、,(LONG)LoadCursor(NULL,IDC_HELP);return0;6.实现动态图标Insert - 资源 - 导入三个图标,在CMainFrame类上定义三个用于存放图标句柄的数组,对CMainFrame类添加一个HICON类型的私有成员变量m_hIcons3,并在CMainFrame:OnCreate函数中支去加载图标:externCStyleApptheApp;/声明这个变量是在外部定义的intCMainFrame:OnCreate(LPCREATESTRUCTlpCreateStruct)./加载图标m_hIcons0=LoadIcon(AfxGetInstanceHan

22、dle(),MAKEINTRESOURCE(IDI_ICON1);/方式一m_hIcons1=LoadIcon(theApp.m_hInstance,MAKEINTRESOURCE(IDI_ICON2);/方式二,theApp是外部的全局变量,在CMainFrame:OnCreate函数之前要声明m_hIcons2=LoadIcon(AfxGetApp()-m_hInstance,MAKEINTRESOURCE(IDI_ICON3); SetClassLong(m_hWnd,GCL_HICON,(LONG)m_hIcons0);/将图标设置成引入的第一个图标/设置定时器SetTimer(1,1

23、000,NULL);return0;再给CMainFrame类添加WM_TIMER消息处理,编辑:voidCMainFrame:OnTimer(UINTnIDEvent)/TODO:Addyourmessagehandlercodehereand/orcalldefaultstaticintindex=1;/静态的变量是存放在数据区当中,而不是分配在栈当中SetClassLong(m_hWnd,GCL_HICON,(LONG)m_hIconsindex);index=+index%3;/让图标不断的循环变幻CFrameWnd:OnTimer(nIDEvent);7.工具栏的编程在菜单Menu下

24、IDR_MAINFRAME中添加一个菜单项Test,在图标Toolbar下IDR_MAINFRAME中添加一个图标。ID号都取为:IDC_TEST。对Test菜单添加一个COMMAND消息响应函数,编辑:void CMainFrame:OnTest() / TODO: Add your command handler code here MessageBox(Test);在工具栏图标之间,添加分隔符,可以用鼠标左键拖住图标往左移一点即可; 可以用鼠标左键把图标拖出工具栏外边即可!8.创建工具栏在ToolBar上新建一个工具栏IDR_TOOLBAR1,并在CMainFrame.h中添加:prot

25、ected: / control bar embedded members CStatusBar m_wndStatusBar; CToolBar m_wndToolBar; CToolBar m_newToolBar;/创建一个ToolBar然后在CMainFrame:OnCreate(LPCREATESTRUCT lpCreateStruct)中编辑:intCMainFrame:OnCreate(LPCREATESTRUCTlpCreateStruct)if(CFrameWnd:OnCreate(lpCreateStruct)=-1)return-1;if(!m_wndToolBar.Cr

26、eateEx(this,TBSTYLE_FLAT,WS_CHILD|WS_VISIBLE|CBRS_TOP|CBRS_GRIPPER|CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_SIZE_DYNAMIC)|!m_wndToolBar.LoadToolBar(IDR_MAINFRAME)TRACE0(Failedtocreatetoolbarn);return-1;/failtocreateif(!m_wndStatusBar.Create(this)|!m_wndStatusBar.SetIndicators(indicators,sizeof(indicators)/size

27、of(UINT)TRACE0(Failedtocreatestatusbarn);return-1;/failtocreate/TODO:Deletethesethreelinesifyoudontwantthetoolbarto/bedockablem_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);EnableDocking(CBRS_ALIGN_ANY);DockControlBar(&m_wndToolBar);/修改窗口的外观/SetWindowLong(m_hWnd,GWL_STYLE,WS_OVERLAPPEDWINDOW);/修改现有窗口的类型/SetWindowLong(m_hWnd,GWL_STYLE,GetWindowLong(m_hWnd,GWL_STYLE)&WS_MAXIMIZEBOX);/使最大化图标变灰/修改图标/SetClassLong(m_hWnd,GCL_HICON,(LONG)LoadIcon(NULL,IDI_ERROR);/加载图标m_hIcons0=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_ICON1);/方式一m_hIcons1=LoadIcon(theApp.m_hInstance,

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1