怎样使你的软件界面更漂亮(加代码)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

我们使用过很多的软件,给我们留下印象很深的是那些界面漂亮且迷人的软件,国外的软件象QuickTime,国产的象金山词霸等,它们的软件界面设计风格都有独特之处。本人跟据自已的经验和大家探讨一下软件的漂亮界面实现的原理并提供DEMO程序。本人经验不多,经常从VCKBASE.COM吸取知识,共同学习,如有不足之处,请指正!也欢迎和我联系。下面就开始吧!一、漂亮界面实现的原理用图象元素自绘窗口标题样栏,边框,系统按钮(最大化、最小化、关闭按钮)还有按窗口中的控件。图象当然是美工画的,但要你教美工怎么去画,是不是不能理解?,呆会我会告诉你你如何去教美工画.请先仔细看下图。明白了吧,被红线包括的部分都是要画的图象。画得好不好会直接影响你的软件界面。二、原理说玩了,来说一下实现的基本知识1、VC软件绘图技术:双击代码全选12345678910CBitmap*pBitmap=newCBitmap;BITMAPBmpInfo;CBitmap*pOldBitmap;CDC*pDisplayMemDC=newCDC;pDisplayMemDC-CreateCompatibleDC(pDC);pBitmap-LoadBitmap(IDB_TITLE_LEFT);pOldBitmap=(CBitmap*)pDisplayMemDC-SelectObject(pBitmap);pBitmap-GetBitmap(&BmpInfo);//x,y为绘图位置,必要时此语句要有For(..;..;..)控制pDC-BitBlt(x,y,BmpInfo.bmWidth,BmpInfo.bmHeight,pDisplayMemDC,0,0,SRCCOPY);1112131415pDisplayMemDC-SelectObject(pOldBitmap);pBitmap-DeleteObject();ReleaseDC(pDisplayMemDC);//记得执行以下的语句deletepDisplayMemDC;deletepBitmap;2、坐标的概念:点、窗口坐标和屏幕坐标及转换,很重要!如不清楚请先复习相关知识。下图是我写在一个界面,就是基于上述原理实现的:下面介绍软件如何实现的:①、重载对话框的消息函数:双击代码全选1voidOnNcLButtonDown(UINTnHitTest,CPointpoint);//单击标题栏时是响应双击代码全选1voidOnNcMouseMove(UINTnHitTest,CPointpoint);//Mous在标题移动时响应双击代码全选1LRESULTDefWindowProc(UINTmessage,WPARAMwParam,LPARAMlParam)②、添加关键成员函数为:BOOLDrawTitleBar(CDC*pDC)③、添加完消息涵数后,在.cpp中实现它们的代码:双击代码全选12345678910111213141516171819202122232425262728293031323334353637383940414243voidCTitleBarDlg::OnNcMouseMove(UINTnHitTest,CPointpoint){CDC*pDC=GetWindowDC();CDC*pDisplayMemDC=newCDC;pDisplayMemDC-CreateCompatibleDC(pDC);CBitmap*pBitmap=newCBitmap;CBitmap*pOldBitmap;CRectrtWnd,rtButton;if(pDC){CStringStrTemp=;GetWindowRect(&rtWnd);//mouse坐标转化为本窗口坐标重要point.x=point.x-rtWnd.left;point.y=point.y-rtWnd.top;//判断mouse是否移到系统按钮上if(m_rtButtExit.PtInRect(point)){pBitmap-LoadBitmap(IDB_EXIT_FOCUS);StrTemp=_T(关闭);}else{if(m_rtButtMin.PtInRect(point)){pBitmap-LoadBitmap(IDB_MIN_FOCUS);StrTemp=_T(最小化窗口);}else{if(m_rtButtMax.PtInRect(point)){pBitmap-LoadBitmap(IDB_MAX_FOCUS);if(IsZoomed()){StrTemp=_T(还原窗口);}else{StrTemp=_T(最化大窗口);}}4445464748495051525354555657585960616263646566676869707172737475767778798081828384858687else{pBitmap-LoadBitmap(IDB_NORMAL);}}}rtButton=m_rtButtMin;BITMAPBmpInfo;pBitmap-GetBitmap(&BmpInfo);pOldBitmap=(CBitmap*)pDisplayMemDC-SelectObject(pBitmap);pDC-BitBlt(rtButton.left-6,rtButton.top-2,BmpInfo.bmWidth,BmpInfo.bmHeight,pDisplayMemDC,0,0,SRCCOPY);pDisplayMemDC-SelectObject(pOldBitmap);pBitmap-DeleteObject();CRectShowTipRec;ShowTipRec=m_rtButtMin;if(!StrTemp.IsEmpty()){//ScreenToClient(&ShowTipRec);//m_ToolTip.AddToolTip(IDD_TITLEBAR_DIALOG,&ShowTipRec,StrTemp);//m_ToolTip.SetDelayTime(200);}}ReleaseDC(pDisplayMemDC);ReleaseDC(pDC);deletepDisplayMemDC;deletepBitmap;CDialog::OnNcMouseMove(nHitTest,point);}//此为关键函数voidCTitleBarDlg::DrawTitleBar(CDC*pDC){if(m_hWnd){CBrushBrush(RGB(0,100,255));888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131CBrush*pOldBrush=pDC-SelectObject(&Brush);CRectrtWnd,rtTitle,rtButtons;GetWindowRect(&rtWnd);//取得标题栏的位置rtTitle.left=GetSystemMetrics(SM_CXFRAME);rtTitle.top=GetSystemMetrics(SM_CYFRAME);rtTitle.right=rtWnd.right-rtWnd.left-GetSystemMetrics(SM_CXFRAME);rtTitle.bottom=rtTitle.top+GetSystemMetrics(SM_CYSIZE);//计算最小化按钮的位置,位图大小为15X15rtButtons.left=rtTitle.right-60;rtButtons.top=rtTitle.top+2;rtButtons.right=rtTitle.right-42;rtButtons.bottom=rtTitle.top+20;m_rtButtMin=rtButtons;//计算最大化按钮的位置,位图大小为15X15m_rtButtMax.left=m_rtButtMin.left+18;m_rtButtMax.top=m_rtButtMin.top;m_rtButtMax.right=m_rtButtMin.right+16;m_rtButtMax.bottom=m_rtButtMin.bottom;m_rtButtExit.left=m_rtButtMax.left+18;m_rtButtExit.top=m_rtButtMax.top;m_rtButtExit.right=m_rtButtMax.right+16;m_rtButtExit.bottom=m_rtButtMax.bottom;//准备CBitmap*pBitmap=newCBitmap;BITMAPBmpInfo;CBitmap*pOldBitmap;CDC*pDisplayMemDC=newCDC;pDisplayMemDC-CreateCompatibleDC(pDC);//重画CaptionPOINTDrawPonit;DrawPonit.x=rtTitle.left-4;DrawPonit.y=rtTitle.top-4;pBitmap-LoadBitmap(IDB_TITLE_LEFT);pOldBitmap=(CBitmap*)pDisplayMemDC-SelectObject(pBitmap);pBitmap-GetBitmap(&BmpInfo);pDC-BitBlt(rtTitle.left-4,rtTitle.top-4,BmpInfo.bmWidth,132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175BmpInfo.bmHeight,pDisplayMemDC,0,0,SRCCOPY);DrawPonit.x=DrawPonit.x+BmpInfo.bmWidth;pDisplayMemDC-SelectObject(pOldBitmap);pBitmap-DeleteObject();pBitmap-LoadBitmap(IDB_TOP);pOldBitmap=(CBitmap*)pDisplayMemDC-SelectObject(pBitmap);pBitmap-GetBitmap(&BmpInfo);while(DrawPonit.x=m_rtButtMin.left-66){pDC-BitBlt(DrawPonit.x,DrawPonit.y,BmpInfo.bmWidth,BmpInfo.bmHeight,pDisplayMemDC,0,0,SRCCOPY);DrawPonit.x=DrawPonit.x+BmpInfo.bmWidth;}pDisplayMemDC-SelectObject(pOldBitmap);pBitmap-DeleteObject();pBitmap-LoadBitmap(IDB_TITLE_RIGHT);pOldBitmap=(CBitmap*)pDisplayMemDC-SelectObject(pBitmap);pBitmap-GetBitmap(&BmpInfo);pDC-BitBlt(DrawPonit.x,DrawPonit.y,BmpInfo.bmWidth,BmpInfo.bmHeight,pDisplayMemDC,0,0,SRCCOPY);pDisplayMemDC-SelectObject(pOldBitmap);pBitmap-DeleteObject();1761771781791801811

1 / 28
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功