VC++自绘界面
// MySkinDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MySkin.h"
#include "MySkinDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMySkinDlg dialog
CMySkinDlg::CMySkinDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMySkinDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMySkinDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_ShowTitle = TRUE;
}
void CMySkinDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMySkinDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMySkinDlg, CDialog)
//{{AFX_MSG_MAP(CMySkinDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_NCLBUTTONDOWN()
ON_WM_NCMOUSEMOVE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMySkinDlg message handlers
BOOL CMySkinDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About…" menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application’s main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CMySkinDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CMySkinDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() – cxIcon + 1) / 2;
int y = (rect.Height() – cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMySkinDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
LRESULT CMySkinDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
LRESULT lrst=CDialog::DefWindowProc(message, wParam, lParam);
if (!::IsWindow(m_hWnd))
return lrst;
if (message==WM_MOVE||
message==WM_PAINT||
message==WM_NCPAINT||
message==WM_NCACTIVATE||
message == WM_NOTIFY)
{
CDC* pWinDC = GetWindowDC();
if (pWinDC)
DrawTitleBar(pWinDC);
ReleaseDC(pWinDC);
}
return lrst;
}
void CMySkinDlg::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rtWnd;
GetWindowRect(&rtWnd);
//mouse坐标转化为本窗口坐标 重要
point.x = point.x – rtWnd.left;
point.y = point.y – rtWnd.top;
//检测各按钮是否按到
if (m_rtButtExit.PtInRect(point))
{
SendMessage(WM_CLOSE);
}
else
{
if (m_rtButtMin.PtInRect(point))
{
m_ShowTitle = FALSE;
SendMessage(WM_SYSCOMMAND,
SC_MINIMIZE,
MAKELPARAM(point.x, point.y));
}
else
{
if (m_rtButtMax.PtInRect(point))
{
m_ShowTitle = TRUE;
if (IsZoomed())
SendMessage(WM_SYSCOMMAND,
SC_RESTORE,
MAKELPARAM(point.x, point.y));
else
{
SendMessage(WM_SYSCOMMAND,
SC_MAXIMIZE,
MAKELPARAM(point.x, point.y));
Invalidate();
}
}
else
{
if (!IsZoomed())
{
Default();
}
}
}
}
CDialog::OnNcLButtonDown(nHitTest, point);
}
void CMySkinDlg::OnNcMouseMove(UINT nHitTest, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDC* pDC = GetWindowDC();
CDC* pDisplayMemDC=new CDC;
pDisplayMemDC->CreateCompatibleDC(pDC);
CBitmap* pBitmap = new CBitmap;
CBitmap* pOldBitmap;
CRect rtWnd, rtButton;
if (pDC)
{
// CString StrTemp = "";
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("最化大窗口");
}
}
else
{
pBitmap->LoadBitmap(IDB_NORMAL);
}
}
}
rtButton = m_rtButtMin;
BITMAP BmpInfo;
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();
CRect ShowTipRec;
ShowTipRec = m_rtButtMin;
/* if(!StrTemp.IsEmpty())
{
// ScreenToClient(&ShowTipRec);
// m_ToolTip.AddToolTip(IDD_TITLEBAR_DIALOG,&ShowTipRec,StrTemp);
// m_ToolTip.SetDelayTime(200);
}*/
}
ReleaseDC(pDisplayMemDC);
ReleaseDC(pDC);
delete pDisplayMemDC;
delete pBitmap;
CDialog::OnNcMouseMove(nHitTest, point);
}
BOOL CMySkinDlg::DrawTitleBar(CDC *pDC)
{
if (m_hWnd)
{
CBrush Brush(RGB(0,100,255));
CBrush* pOldBrush = pDC->SelectObject(&Brush);
CRect rtWnd, 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);
//计算最小化按钮的位置,位图大小为15X15
rtButtons.left = rtTitle.right-60;
rtButtons.top= rtTitle.top+2;
rtButtons.right = rtTitle.right-42;
rtButtons.bottom = rtTitle.top+20;
m_rtButtMin = rtButtons;
//计算最大化按钮的位置,位图大小为15X15
m_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 = new CBitmap;
BITMAP BmpInfo;
CBitmap* pOldBitmap;
CDC* pDisplayMemDC=new CDC;
pDisplayMemDC->CreateCompatibleDC(pDC);
//重画Caption
POINT DrawPonit;
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,
BmpInfo.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();
//重画最小化button
rtButtons = m_rtButtMin;
pBitmap->LoadBitmap(IDB_NORMAL);
pBitmap->GetBitmap(&BmpInfo);
pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
pDC->BitBlt(rtButtons.left-6,
rtButtons.top-2,
BmpInfo.bmWidth,
BmpInfo.bmHeight,
pDisplayMemDC,
0,
0,
SRCCOPY);
pDisplayMemDC->SelectObject(pOldBitmap);
pBitmap->DeleteObject();
int nOldMode = pDC->SetBkMode(TRANSPARENT);
COLORREF clOldText=pDC->GetTextColor();
CFont titleFont;
titleFont.CreateFont( 12, // nHeight
8, // nWidth
0, // nEscapement文本行逆时针旋转角度
0, // nOrientation字体角度
FW_BOLD, // nWeight字体粗细程度
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut 删除线
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
_T("隶书"));// lpszFac pDC->SelectStockObject(SYSTEM_FIXED_FONT);
CFont *OldFont;
OldFont = pDC->SelectObject(&titleFont);
CString m_StrTitle;
GetWindowText(m_StrTitle);
pDC->SetTextColor(RGB(80,255,25));
if(m_ShowTitle)
{
pDC->TextOut(65,10,m_StrTitle);
}
else
{
m_StrTitle = m_StrTitle.Left(6);
m_StrTitle += "…";
pDC->TextOut(30,10,m_StrTitle);
}
pDC->SetBkMode(nOldMode);
pDC->SetTextColor(clOldText);
pDC->SelectObject(OldFont);
//pDC->TextOut(60,60,m_StrTitle);
//重画左边框
pBitmap->LoadBitmap(IDB_LEFTDOWN);
pBitmap->GetBitmap(&BmpInfo);
pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
int i ;
for (i= 20;i<=rtWnd.bottom;i=i+BmpInfo.bmHeight-3)
{
pDC->BitBlt(0, rtButtons.top+i,
BmpInfo.bmWidth,
BmpInfo.bmHeight,
pDisplayMemDC,
0,
0,
SRCCOPY);
}
pDisplayMemDC->SelectObject(pOldBitmap);
pBitmap->DeleteObject();
//重画右边框
pBitmap->LoadBitmap(IDB_RIGHTDOWN);
pBitmap->GetBitmap(&BmpInfo);
pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
GetClientRect(&rtWnd);
for (i= 25;i<=rtWnd.bottom+27;i=i+BmpInfo.bmHeight-3)
{
pDC->BitBlt(rtWnd.right, i,
BmpInfo.bmWidth,
BmpInfo.bmHeight,
pDisplayMemDC,
0,
0,
SRCCOPY);
}
pDisplayMemDC->SelectObject(pOldBitmap);
pBitmap->DeleteObject();
//重画底边框
pBitmap->LoadBitmap(IDB_DOWN);
pBitmap->GetBitmap(&BmpInfo);
pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
GetClientRect(&rtWnd);
for (i= 9; i<=rtWnd.right; i=i+2)
{
GetClientRect(&rtWnd);
pDC->BitBlt(i,rtWnd.bottom+26,
BmpInfo.bmWidth,
BmpInfo.bmHeight,
pDisplayMemDC,
0,
0,
SRCCOPY);
}
pDisplayMemDC->SelectObject(pOldBitmap);
pBitmap->DeleteObject();
ReleaseDC(pDisplayMemDC);
delete pDisplayMemDC;
delete pBitmap;
}
return TRUE;
}
效果:
VC++自绘界面的更多相关文章
- VC之美化界面(内容覆盖十分全面,经典)
界面美化 摘要本文专题讨论VC中的界面美化,适用于具有中等VC水平的读者.读者最好具有以下VC基础: 1. 大致了解MFC框架的基本运作原理: 2. 熟悉Windows消息机制,熟悉MFC的消息映射和 ...
- 基于VC的MFC界面开发
教你熟悉VC6.0创建一个可视化软件的过程 UpdateData(TRUE);//将输入数据赋给文本框变量. UpdateData(FALSE);//将内容显示在文本框中 AfxMessageBox( ...
- 美化VC界面(用户登录界面)
源代码:下载 VC开发程序单调的界面相信大家都是深有感触,提到界面美化编程,人们都会说做界面不要用VC写,太难了.一句俗语:难者不会,会者不难.VC的美化界面编程并没有人们想像的那么难.这篇文章是我写 ...
- [收藏夹整理]VC部分
c++多线程(一) C++11 多线程 鸡啄米:C++编程入门系列之十二(类与对象:面向对象设计的基本思想和特点) 鸡啄米:C++编程入门系列之二十一(C++程序设计必知:类的静态成员) [笔记]VS ...
- MFC Button控件自绘
文章参考地址: http://blog.csdn.net/yue7603835/article/details/6649458 VC下的界面着实难看 有时候我们不得不自己进行控件的绘制 以前 ...
- Swift - 界面的跳转模式
iOS开发中界面跳转有两种方式,上下跳转和左右跳转. 上下跳转_TO: let secondViewController = SecondViewController() self.presentVi ...
- 怎样在VC里面使用graphics.h绘图
网上很多绘图程序和小游戏程序都是用的 TC,在 VC 下编译时提示错误:fatal error C1083: Cannot open include file: 'graphics.h': No su ...
- openlayers4 入门开发系列之地图标绘篇(附源码下载)
前言 openlayers4 官网的 api 文档介绍地址 openlayers4 api,里面详细的介绍 openlayers4 各个类的介绍,还有就是在线例子:openlayers4 官网在线例子 ...
- 结对项目——图形界面实现与dll动态链接
先来一发软件截图~~~ 生成题目的界面 测评界面 第三块本来准备做一个文件历史记录的界面,但是由于时间不够,暂时还没做完. 图形界面的设计与实现 由于对传统的对话框风格不太满意,所以这次作业的图形界面 ...
随机推荐
- HTML实体符号
http://www.php100.com/html/program/html/2013/0903/1052.html
- Qt学习(四)—实例涂鸦画板mspaint
一.Qt图形绘制 自己在Qt开源社区在自学yafeilinux前辈的<Qt快速入门系列教程>中的图形篇,结合所学的知识,可以做一个涂鸦板实例 二.实现涂鸦板 1.新建工程mspaint, ...
- [ArcGIS Engine]栅格数据处理 RasterDataset RasterLayer Raster RasterBandCollection
原文 http://www.cnblogs.com/zoe-j/archive/2012/03/22/2412403.html 1.由RasterLayer 得到RasterDataset IRast ...
- HTML5学习摘录
设计原理 不是规范里都包含什么,而是规范里为什么会包含它们,以及在设计这个规范的时候,设计者们是怎么看待这些东西的. 发展史:HTML2.0——>HTML3.2——>HTML4.0.1—— ...
- Maximum Depth of Binary Tree 解答
Question Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along ...
- hdu 5610 Baby Ming and Weight lifting
Problem Description Baby Ming is fond of weight lifting. He has a barbell pole(the weight of which c ...
- 在web应用程序中使用MemcachedClient
本文来自:http://www.cnblogs.com/yukaizhao/archive/2008/11/10/memcached_client_usage.html 一. 背景: 在大访问量的we ...
- SQL With(递归 CTE 查询)
本文来自:http://www.cnblogs.com/smailxiaobai/archive/2012/01/16/2323291.html 指定临时命名的结果集,这些结果集称为公用表表达式 (C ...
- Tomcat可以在eclipse里启动,可是不能訪问首页的问题
今天在使用eclipse的时候发现一个问题.就是我在eclipse里面已经启动了tomcat.部署上去的项目也能够启动,可是就是没法訪问tomcat的首页.port等等都没有问题. 后来查到解决方式, ...
- Android开发最佳学习路线图
为了帮助大家更好的学习Android开发的相关知识,尚观4G智能操作系统研究室(www.up4g.com)为大家制作下面学习路线图:希望能帮助到广大的android爱好者. 在開始之前我们 ...