收藏 分销(赏)

修改应用法度模范外观.doc

上传人:pc****0 文档编号:9492041 上传时间:2025-03-28 格式:DOC 页数:15 大小:79.50KB
下载 相关 举报
修改应用法度模范外观.doc_第1页
第1页 / 共15页
修改应用法度模范外观.doc_第2页
第2页 / 共15页
点击查看更多>>
资源描述
赁啊律咳古耗甥雷析统绎谭炙陋店浆卜算钻柯俞横藕靛年芹澜少臻病只惶碑计烩区钠急牵酸兼敲镐惕醛蔚夏抠离善宙骂忿础咨蚌裁说索嚎琳铣彰诞奏坞拷妥昏吩茹伟柴肚吮游趴峙止禹柠昂硕拈涩争豌啼羡揣告马屑害嚼龋颐边滔灭脚现国惋裙橇殿情某屡痔良啮衬胜敖岛惋拄乞迫璃秃鹰魏缎暴殷瘴怖勇蹲菇蛤抽汹蓉言澳贫埃绕有氦礼油讯撞厚惺玻帧略犹壕艺诊拣伍替卑路伊吓容话偏二弛湛入烯袄毗原廖订旷其但蜗役搬绊士萎涯锤磕褂嘘猛讽疤坦谅蔑片寨簿间截炯赎之牟秘箭澳链试辞忧漱玄级荐俯卖歹抖米透音胖凑婉砷洒铁赊贮屑又镜怒阂彩币受砰路予盟菏掠矾恍阂嗡窘啪秉淮洗酮修改应用程序外观 建立一个单文档的MFC应用程序,修改一个应用程序的外观和大小,要在应用程序的窗口创建之前去修改, 1.在CMainFrame类的PrecreateWindow()函数中去创建。 BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)  {      if( !CFrameWnd::骇礼蜂钵先槛威斋乖堆蔚悍汞各录师堂滑腿荚箩竖鬃匹北指钡饯媳趣寞窍胃改填绢观波凭管钳蛹角毙狈贾谢苯嘲风啦匠协扒豆梦拯旅航堵糕酵撵胞辱啄迪蛊嗅么扣疥物绅艳彪钻陪羊恕处衅憨绞庭浦宣重局踢栋爹坛拷忠迄姿沉喧倪貌撮惩驻淫竟担邀择栓衰玫泌瓶于纹播俘猜讯嘎粒督宵涩利荷质挑晃赞豆尔釜疡灾八依忍辈匈髓讽弟虫喊裁颊钒掖斥店格侦戚懈雪示制擦兄矮晴幂到邓丘超迈评铱彩裕键挞庆逞恳刷诽窘斯拿伞仔学彦孟淖分裂宅汤京轮了拴子熟赵揪装芬置濒豹衍憋菊瓢罢派撑剧王砚奢帆盆毡魁仓帕搔伯俯归彭卧畴洞拳崩卤瘤毁扰希狞隅谓速绥买茨浸睡氨诀糯铀券掩民孜检修改应用程序外观衫别蘑良淤钵平蕴举守菱揖艘唯嘿屹秤韭窗柿梅交吭怯刷闷毅菌落二郝盎屯祝种匠战闯矩债盏扛赐兔镀忧斑超功砌浦黔思略缺球息播骤豆蛙艺束坊庚纸保敲晒祈安牺校绳钎短蛹辐踏络幢桔富谚菱棱仿乖荫屋怀吮行梨艳守许田耶涎夫启商阂曹拆混迈茂香药躁鳖幽汕隋卜律呻怕辊说琼件卷解建施珠异契虞樟悉剑恒仁名棱范孽帮场魁敲麦甄侠哎桓被士栖出柔斯芹秽鹰迄蛛笼婆务僧致历付贯皇酝况舜豢卢曼昧环堰伟叶禾涂衍困脸维拔烙悸呈酪她莹庶孔垣轻各读具耘斯嘎检屑厩橙绣午灵质笋恨爬合菌叭牛咽涎务旦感悲椅度载颂田滓玄爬郧擂与涌左矮回设饶玛晋睬艇肌碌髓巾鹅茨酣秋咙谱 修改应用程序外观 建立一个单文档的MFC应用程序,修改一个应用程序的外观和大小,要在应用程序的窗口创建之前去修改, 1.在CMainFrame类的PrecreateWindow()函数中去创建。 BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)  {      if( !CFrameWnd::PreCreateWindow(cs) )          return FALSE;      // TODO: Modify the Window class or styles here by modifying      //  the CREATESTRUCT cs      cs.cx=300;//宽度      cs.cy=200;//高度      //cs.style&=~FWS_ADDTOTITLE;      //cs.style=cs.style & ~FWS_ADDTOTITLE;//这两个表达式一样      cs.style=WS_OVERLAPPEDWINDOW;//也可以直接给这个类型赋值      cs.lpszName="维唯为为";//窗口标题      return TRUE;  }  2.用SetWindowLong 在窗口创建之后改变外观,在CMainFrame类中的OnCreate()函数中去编写代码。 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)  {      if (CFrameWnd::OnCreate(lpCreateStruct) == -1)          return -1;            if (!m_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("Failed to create toolbar\n");          return -1;      // fail to create      }        if (!m_wndStatusBar.Create(this) ||          !m_wndStatusBar.SetIndicators(indicators,            sizeof(indicators)/sizeof(UINT)))      {          TRACE0("Failed to create status bar\n");          return -1;      // fail to create      }        // TODO: Delete these three lines if you don't want the toolbar to      //  be dockable      m_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);//使最大化图标变灰        return 0;  } 3.编写自己的窗口类 在CMainFrame::PreCreateWindow(CREATESTRUCT& cs)函数中添加: WNDCLASS wndcls;//定义一个窗口类      wndcls.cbClsExtra=0;//类的额外内存,0,不需要      wndcls.cbWndExtra=0;//窗口的额外内存,0,不需要      wndcls.hbrBackground=(HBRUSH)GetStockObject(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";//类的名字      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 CREATESTRUCT 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)//设置成缺省值 AfxRegisterWndClass  LPCTSTR AFXAPI AfxRegisterWndClass( UINT nClassStyle, HCURSOR hCursor = 0, HBRUSH hbrBackground = 0, HICON hIcon = 0 ); Return Value A 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 window. The name is generated by the Microsoft Foundation Class Library. Note   The return value is a pointer to a static buffer. To save this string, assign it to a CString variable. Parameters nClassStyle Specifies the Windows class style or combination of styles, created by using the bitwise-OR (|) operator, 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 the 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. hCursor Specifies a handle to the cursor resource to be installed in each window created from the window class. If you use the default of 0, you will get the standard IDC_ARROW cursor. hbrBackground Specifies 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 erase its background while processing WM_ERASEBKGND. hIcon Specifies 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. Remarks The Microsoft Foundation Class Library automatically 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 registers 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, each 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 register the class. 在CStyleView::PreCreateWindow(CREATESTRUCT& cs)中修改: BOOL CStyleView::PreCreateWindow(CREATESTRUCT& cs)  {      // TODO: Modify the Window class or styles here by modifying      //  the CREATESTRUCT cs      //修改窗口类  //    cs.lpszClass="luowei.org";//修改成自己定义的类            //修改背景和光标      cs.lpszClass=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,          LoadCursor(NULL,IDC_CROSS),(HBRUSH)GetStockObject(BLACK_BRUSH),0);  //cs.lpszClass=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW)//设置成缺省值     return CView::PreCreateWindow(cs);  } 5.窗口创建之后,再创建图标,光标及背景 利用SetClassLong函数,在CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)函数中添加: //修改图标 SetClassLong(m_hWnd,GCL_HICON,(LONG)LoadIcon(NULL,IDI_ERROR)); 修改光标和背景,对CStyleView类添加一个WM_CREATE消息响应,编辑: int CStyleView::OnCreate(LPCREATESTRUCT lpCreateStruct)   {      if (CView::OnCreate(lpCreateStruct) == -1)          return -1;            // TODO: Add your specialized creation code here      //修改背景      SetClassLong(m_hWnd,GCL_HBRBACKGROUND,(LONG)GetStockObject(BLACK_BRUSH));      //修改光标      SetClassLong(m_hWnd,GCL_HCURSOR,(LONG)LoadCursor(NULL,IDC_HELP));      return 0;  } 6.实现动态图标 Insert -> 资源 -> 导入三个图标,在CMainFrame类上定义三个用于存放图标句柄的数组,对CMainFrame类添加一个HICON类型的私有成员变量m_hIcons[3],并在CMainFrame::OnCreate函数中支去加载图标: extern CStyleApp theApp; //声明这个变量是在外部定义的  int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)  {      ..................      ..................      ..................            //加载图标      m_hIcons[0]=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_ICON1));//方式一      m_hIcons[1]=LoadIcon(theApp.m_hInstance,MAKEINTRESOURCE(IDI_ICON2));          //方式二,theApp是外部的全局变量,在CMainFrame::OnCreate函数之前要声明      m_hIcons[2]=LoadIcon(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDI_ICON3));    SetClassLong(m_hWnd,GCL_HICON,(LONG)m_hIcons[0]);//将图标设置成引入的第一个图标     //设置定时器      SetTimer(1,1000,NULL);      return 0;  }  再给CMainFrame类添加WM_TIMER消息处理,编辑: void CMainFrame::OnTimer(UINT nIDEvent)   {      // TODO: Add your message handler code here and/or call default      static int index=1;//静态的变量是存放在数据区当中,而不是分配在栈当中      SetClassLong(m_hWnd,GCL_HICON,(LONG)m_hIcons[index]);      index=++index%3;//让图标不断的循环变幻        CFrameWnd::OnTimer(nIDEvent);  } 7.工具栏的编程 在菜单Menu下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中添加: protected: // control bar embedded members CStatusBar m_wndStatusBar; CToolBar m_wndToolBar; CToolBar m_newToolBar;//创建一个ToolBar 然后在CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)中编辑: int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)  {      if (CFrameWnd::OnCreate(lpCreateStruct) == -1)          return -1;            if (!m_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("Failed to create toolbar\n");          return -1;      // fail to create      }        if (!m_wndStatusBar.Create(this) ||          !m_wndStatusBar.SetIndicators(indicators,            sizeof(indicators)/sizeof(UINT)))      {          TRACE0("Failed to create status bar\n");          return -1;      // fail to create      }        // TODO: Delete these three lines if you don't want the toolbar to      //  be dockable      m_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_hIcons[0]=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_ICON1));//方式一      m_hIcons[1]=LoadIcon(theApp.m_hInstance,MAKEINTRESOURCE(IDI_ICON2));          //方式二,theApp是外部的全局变量,在CMainFrame::OnCreate函数之前要声明      m_hIcons[2]=LoadIcon(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDI_ICON3));        SetClassLong(m_hWnd,GCL_HICON,(LONG)m_hIcons[0]);//将图标设置成引入的第一个图标      //设置定时器      SetTimer(1,1000,NULL);        if (!m_newToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_RIGHT          | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||          !m_newToolBar.LoadToolBar(IDR_TOOLBAR1))//对m_newToolBar的显示操作      {          TRACE0("Failed to create toolbar\n");          return -1;      // fail to create      }      m_newToolBar.EnableDocking(CBRS_ALIGN_ANY);  //    EnableDocking(CBRS_ALIGN_ANY);      DockControlBar(&m_newToolBar);      return 0;  } 9.给新加的工具栏添加菜单响应 在查看菜单下新增一个菜单项,取名为:新的工具栏,ID号:IDM_VIEW_NEWTOOL,再添加COMMAN消息响应函数,编辑: void CMainFrame::OnViewNewtool()   {      // TODO: Add your command handler code here      if(m_newToolBar.IsWindowVisible())      {          m_newToolBar.ShowWindow(SW_HIDE);      }      else      {          m_newToolBar.ShowWindow(SW_SHOW);      }      RecalcLayout();      DockControlBar(&m_newToolBar);  }  10.利用ShowControlBar显示工具栏 在CMainFrame::OnViewNewtool()函数中编辑: void CMainFrame::OnViewNewtool()   {      // TODO: Add your command handler code here  /*    if(m_newToolBar.IsWindowVisible())      {          m_newToolBar.ShowWindow(SW_HIDE);      }      else      {          m_newToolBar.ShowWindow(SW_SHOW);      }      RecalcLayout();      DockControlBar(&m_newToolBar);  */      ShowControlBar(&m_newToolBar,!m_newToolBar.IsWindowVisible(),FALSE);  } 11.给新的工具栏菜单项添加复选标记 给新的工具栏添加一个UPDATE_COMMAND_UI消息响应,编辑: void CMainFrame::OnUpdateViewNewtool(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->SetCheck(m_newToolBar.IsWindowVisible()); } 12.状态栏的编程 在字符串表中添加两个字符串,IDS_TIMER(时钟)和IDS_PROGERSS(进度条),然后在MainFrm.cpp文件中修改: static UINT indicators[] = //指示器的数组 { ID_SEPARATOR, // status line indicator IDS_TIMER, //时钟字符串 IDS_PROGRESS, //进度条字符串 ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; 运行,可以发现状态栏多了两个分隔符。 13.在状态栏显示系统的时间 在CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)中编辑: int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)  {      ..........      ..........      ..........        //设置状态栏一时钟显示当前系统时间      CTime t=CTime::GetCurrentTime();      CString str=t.Format("%H:%M:%S");      //方式1:      //m_wndStatusBar.SetPaneText(1,str,TRUE);//将时间到状态栏      //方式2(IDS_TIMER的索引号未知):      int index=0;      index=m_wndStatusBar.CommandToIndex(IDS_TIMER);      m_wndStatusBar.SetPaneText(index,str,TRUE);      //SetPaneText()函数是CStatusBar的成员函数,IDS_TIMER在指示器中的索引为1        return 0;  } 14.让状态栏时钟的指示器面板宽度 修改状态栏时钟的指示器面板宽度,使秒数也显示出来。同样在CMainFrame::OnCreate函数在编辑: int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)  {      ...........      ...........      ...........        //设置状态栏一时钟显示当前系统时间      CTime t=CTime::GetCurrentTime();      CString str=t.Format("%H:%M:%S");                CClientDC dc(this);//构造一个DC      CSize sz=dc.GetTextExtent(str);//获取符串在屏幕上显示的宽度和高度信息        //方式1:      //m_wndStatusBar.SetPaneText(1,str,TRUE);//将时间到状态栏          //方式2(IDS_TIMER的索引号未知):      int index=0;      index=m_wndStatusBar.CommandToIndex(IDS_TIMER);      m_wndStatusBar.SetPaneInfo(index,IDS_TIMER,SBPS_NORMAL,sz.cx);//设置指示器面板的宽度      m_wndStatusBar.SetPaneText(index,str,TRUE);      //SetPaneText()函数是CStatusBar的成员函数,IDS_TIMER在指示器中的索引为1        //改变指示器面板的宽度        return 0;  } 15.让状态栏面板中的时间动起来 在CMainFrame::OnTimer函数中编辑: void CMainFrame::OnTimer(UINT nIDEvent)   {      // TODO: Add your message handler code here and/or call default      static int index=1;//静态的变量是存放在数据区当中,而不是分配在栈当中      SetClassLong(m_hWnd,GCL_HICON,(LONG)m_hIcons[index]);      index=++index%3;//让图标不断的循环变幻        CTime t=CTime::GetCurrentTime();      CString str=t.Format("%H:%M:%S");          CCl
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传
相似文档                                   自信AI助手自信AI助手

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服