实习两个多礼拜,很快就适应了环境,不过临时调到软件组去做控件及界面了,用的开发平台是visual studio 2008,毕业以来一直做的都是嵌入式C语言,还真是有些痛苦,不过还好以前对GDI有所接触,所以做GDI+也不是大问题,对于C++也只是大学学了些理论知识,没有什么实际开发经验,这次正好搞定C++,让自己的遗憾就此消除。在高人的指点下于是就硬着头皮去做了啦。
人有些时候,是被逼的,明明不会却硬着头皮去做起来,而往往这段最最煎熬的日子却是最充实的,化蛹成蝶的痛苦莫过于此吧。
言归正传吧,话说要实现对话框背景及其上面的控件全透明,但是查了好多网上、MSDN的资料后,得出一个结论,只能实现这几种情况:1、对话框背景透明而其上的控件不能透明;2、对话框背景不透明而其上的控件透明;3、如果硬要都透明,由于微软的好多控件内置图是不能替换的,所以会导致什么都看不见。
那么我们要达到对话框及其上面的控件全透明怎么办呢?核心思路是:使背景和控件都全透,然后通过GDI+的提供的借口来捕获这些对话框背景及其上面控件的消息,来获得具体的一些位置信息从而用GDI+使用PNG图绘制出透明背景及控件。具体就是通过继承GDI+的类来保留控件的消息及由此而继承来的位置信息,我们就是要这些位置信息来使用PNG绘图。
对于编辑框的实现,由微软自带的编辑框使用drawtext来绘制文字,而GDI+只能用drawstring来绘制,尽管使用相同字体,这两种函数会出来的字是不一样的,所以在实现编辑框的文字输出时,只能 以插入符为参考系,从系统得到插入符的位置,用画线的方式绘制出来,而文字使用获取窗口内容的函数获得后采用化整为零的方法是用drawstring一个个字去绘制出来。这样经过细致的调节后能够基本模拟原本的文字输出状况。
以下是我用这种方法实现treectrl 的例子:
实现文件:
/************************************************************
FileName: TprTreeCtrl.cpp
Author:LiuGuanfa
Version:1.0
Date:2011.4.2
Description:实现treectrl的透明显示
History:
<author> <time> <version > <desc>
LiuGuanfa 2011/04/03 1.0 build this moudle
***********************************************************/
#include "stdafx.h"
#include "TprUiFun.h"
#include "TprTreeCtrl.h"
#include "../ItfResource/ItfResource1920/resource.h"
IMPLEMENT_DYNAMIC(CTprTreeCtrl, CTreeCtrl)
CTprTreeCtrl::CTprTreeCtrl()
{
m_pLogTprTreeCtrl = NULL;
m_pTprTreeCtrlLogFont = NULL;
m_pTprTreeCtrlTxtFont = NULL;
m_pTprTreeCtrlSysFont = NULL;
}
CTprTreeCtrl::~CTprTreeCtrl()
{
if(m_pLogTprTreeCtrl != NULL)
{
delete m_pLogTprTreeCtrl;
m_pLogTprTreeCtrl = NULL;
}
if(m_pTprTreeCtrlLogFont != NULL)
{
delete m_pTprTreeCtrlLogFont;
m_pTprTreeCtrlLogFont = NULL;
}
if (m_pTprTreeCtrlSysFont != NULL)
{
delete m_pTprTreeCtrlSysFont;
m_pTprTreeCtrlSysFont = NULL;
}
if (m_pTprTreeCtrlTxtFont != NULL)
{
delete m_pTprTreeCtrlTxtFont;
m_pTprTreeCtrlTxtFont = NULL;
}
}
BEGIN_MESSAGE_MAP(CTprTreeCtrl, CTreeCtrl)
ON_WM_PAINT()
END_MESSAGE_MAP()
void CTprTreeCtrl::InitTprTreeCtrl(const LOGFONT *pLogFont, TPRTREECTRL *pLogTprTreeCtrl)
{
int i;
if(m_pTprTreeCtrlLogFont==NULL)
{
m_pTprTreeCtrlLogFont = new LOGFONT;
}
m_pTprTreeCtrlLogFont->lfHeight = pLogFont->lfHeight;
m_pTprTreeCtrlLogFont->lfWidth = pLogFont->lfWidth;
m_pTprTreeCtrlLogFont->lfEscapement = pLogFont->lfEscapement;
m_pTprTreeCtrlLogFont->lfOrientation = pLogFont->lfOrientation;
m_pTprTreeCtrlLogFont->lfWeight = pLogFont->lfWeight;
m_pTprTreeCtrlLogFont->lfItalic = pLogFont->lfItalic;
m_pTprTreeCtrlLogFont->lfUnderline = pLogFont->lfUnderline;
m_pTprTreeCtrlLogFont->lfStrikeOut = pLogFont->lfStrikeOut;
m_pTprTreeCtrlLogFont->lfCharSet = pLogFont->lfCharSet;
m_pTprTreeCtrlLogFont->lfOutPrecision = pLogFont->lfOutPrecision;
m_pTprTreeCtrlLogFont->lfClipPrecision = pLogFont->lfClipPrecision;
m_pTprTreeCtrlLogFont->lfQuality = pLogFont->lfQuality;
m_pTprTreeCtrlLogFont->lfPitchAndFamily = pLogFont->lfPitchAndFamily;
wcscpy(m_pTprTreeCtrlLogFont->lfFaceName,pLogFont->lfFaceName);
if(m_pLogTprTreeCtrl==NULL)
{
m_pLogTprTreeCtrl = new TPRTREECTRL;
}
m_pLogTprTreeCtrl->pImageAddSub[0] = pLogTprTreeCtrl->pImageAddSub[0];
m_pLogTprTreeCtrl->pImageAddSub[1] = pLogTprTreeCtrl->pImageAddSub[1];
for (i=0; i<9; i++)
{
m_pLogTprTreeCtrl->pImageNineFormat[i] = pLogTprTreeCtrl->pImageNineFormat[i];
}
for (i=0; i<3;i++)
{
m_pLogTprTreeCtrl->pImageScrollBarH[i] = pLogTprTreeCtrl->pImageScrollBarH[i];
m_pLogTprTreeCtrl->pImageScrollBarV[i] = pLogTprTreeCtrl->pImageScrollBarV[i];
}
m_pLogTprTreeCtrl->pImageThumbH[0] = pLogTprTreeCtrl->pImageThumbH[0];
m_pLogTprTreeCtrl->pImageThumbV[0] = pLogTprTreeCtrl->pImageThumbV[0];
/*
for (i=0; i<2;i++)
{
m_pLogTreeCtrl->pImageScrollArrowH[i] = pLogTprTreeCtrl->pImageScrollArrowH[i];
m_pLogTreeCtrl->pImageScrollArrowV[i] = pLogTprTreeCtrl->pImageScrollArrowV[i];
}
*/
//设置GDItree ctrl字体
m_pTprTreeCtrlSysFont = new CFont;
if (!(m_pTprTreeCtrlSysFont->CreateFontIndirect(m_pTprTreeCtrlLogFont)))
{
MessageBox(_T("创建字体失败!"), _T("提示"), MB_OK);
}
this->SetFont(m_pTprTreeCtrlSysFont,TRUE);
//创建GDI+tree ctrl字体
m_pTprTreeCtrlTxtFont = new TEXTFONT;
if (m_pTprTreeCtrlTxtFont)
{
m_pTprTreeCtrlTxtFont->coColor = Color(245,0,0,0);
m_pTprTreeCtrlTxtFont->pStringFormat = new StringFormat;
m_pTprTreeCtrlTxtFont->pStringFormat->SetAlignment(StringAlignmentNear);
m_pTprTreeCtrlTxtFont->pStringFormat->SetLineAlignment(StringAlignmentCenter);
m_pTprTreeCtrlTxtFont->pStringFormat->SetTrimming(StringTrimmingEllipsisCharacter);
m_pTprTreeCtrlLogFont->lfWidth = m_pTprTreeCtrlLogFont->lfWidth * 1;
m_pTprTreeCtrlLogFont->lfHeight= m_pTprTreeCtrlLogFont->lfHeight * 1;
m_pTprTreeCtrlTxtFont->pFont =new Font(this->GetDC()->m_hDC,m_pTprTreeCtrlLogFont);
}
}
/*
*绘制TprTreeCtrl接口
*/
void CTprTreeCtrl::DrawTprTreeCtrl(CDC* pDC)
{
CDC *pDCDst=this->GetDC();
CDC dcSrc;
dcSrc.CreateCompatibleDC(pDCDst);
CRect reWindowRect;
this->GetWindowRect(&reWindowRect);
CBitmap cBitmap;
cBitmap.CreateCompatibleBitmap(pDCDst, reWindowRect.Width(), reWindowRect.Height());
dcSrc.SelectObject(&cBitmap);
Graphics *pGraphics = new Graphics(dcSrc.m_hDC);
if(NULL!=pGraphics)
{
DrawFrame(pGraphics);
DrawTree(pGraphics);
DrawScrollBar(pGraphics);
}
CRect rePrRect;
GetParent()->GetWindowRect(&rePrRect);
CRect reWinRect;
this->GetWindowRect(&reWinRect);
CRect reDlgRect;
reDlgRect.left = reWinRect.left - rePrRect.left;
reDlgRect.top = reWinRect.top - rePrRect.top;
pDC->BitBlt(reDlgRect.left, reDlgRect.top, reWinRect.Width(), reWinRect.Height(), &dcSrc, 0, 0, SRCCOPY);
delete pGraphics;
pGraphics = NULL;
cBitmap.DeleteObject();
dcSrc.DeleteDC();
this->ReleaseDC(pDCDst);
}
/*
*绘制背景
*/
void CTprTreeCtrl::DrawFrame(Graphics *pGraphics)
{
RECT tClientRect;
RECT tWndRect;
int i;
int iPosX;
int iPosY;
int iWidth;
int iHight;
int iCycTimes;
//this->GetClientRect(&tClientRect);
this->GetWindowRect(&tWndRect);
tClientRect.left = 0;
tClientRect.top = 0;
tClientRect.right = tWndRect.right - tWndRect.left;
tClientRect.bottom = tWndRect.bottom - tWndRect.top;
//绘制九宫格第0块
iPosX = tClientRect.left;
iPosY = tClientRect.top;
iWidth= m_pLogTprTreeCtrl->pImageNineFormat[0]->GetWidth();
iHight= m_pLogTprTreeCtrl->pImageNineFormat[0]->GetHeight();
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageNineFormat[0], RectF(iPosX, iPosY, iWidth, iHight));
//绘制九宫格第1块
iPosX = tClientRect.left + m_pLogTprTreeCtrl->pImageNineFormat[0]->GetWidth();
iPosY = tClientRect.top;
iWidth= m_pLogTprTreeCtrl->pImageNineFormat[1]->GetWidth();
iHight= m_pLogTprTreeCtrl->pImageNineFormat[0]->GetHeight();
iCycTimes = (tClientRect.right - tClientRect.left - m_pLogTprTreeCtrl->pImageNineFormat[0]->GetWidth() - m_pLogTprTreeCtrl->pImageNineFormat[2]->GetWidth())/iWidth;
for (i=0; i<iCycTimes; i++)
{
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageNineFormat[1], RectF(iPosX, iPosY, iWidth, iHight));
iPosX += m_pLogTprTreeCtrl->pImageNineFormat[1]->GetWidth();
}
iWidth = (tClientRect.right - tClientRect.left - m_pLogTprTreeCtrl->pImageNineFormat[0]->GetWidth() - m_pLogTprTreeCtrl->pImageNineFormat[2]->GetWidth()) - iCycTimes * iWidth;
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageNineFormat[1], RectF(iPosX, iPosY, iWidth, iHight));
//绘制九宫格第2块
iPosX = tClientRect.right - m_pLogTprTreeCtrl->pImageNineFormat[2]->GetWidth();
iPosY = tClientRect.top;
iWidth= m_pLogTprTreeCtrl->pImageNineFormat[2]->GetWidth();
iHight= m_pLogTprTreeCtrl->pImageNineFormat[2]->GetHeight();
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageNineFormat[2], RectF(iPosX, iPosY, iWidth, iHight));
//绘制九宫格第3块
iPosX = tClientRect.left;
iPosY = tClientRect.top + m_pLogTprTreeCtrl->pImageNineFormat[0]->GetHeight();
iWidth= m_pLogTprTreeCtrl->pImageNineFormat[0]->GetWidth();
iHight= m_pLogTprTreeCtrl->pImageNineFormat[3]->GetHeight();
iCycTimes = (tClientRect.bottom - tClientRect.top - m_pLogTprTreeCtrl->pImageNineFormat[0]->GetHeight() - m_pLogTprTreeCtrl->pImageNineFormat[6]->GetHeight())/iHight;
for (i=0; i<iCycTimes;i++)
{
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageNineFormat[3], RectF(iPosX, iPosY, iWidth, iHight));
iPosY += m_pLogTprTreeCtrl->pImageNineFormat[3]->GetHeight();
}
iHight = (tClientRect.bottom - tClientRect.top - m_pLogTprTreeCtrl->pImageNineFormat[0]->GetHeight() - m_pLogTprTreeCtrl->pImageNineFormat[6]->GetHeight()) - iCycTimes * iHight;
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageNineFormat[3], RectF(iPosX, iPosY, iWidth, iHight));
//绘制九宫格第4块
iPosX = tClientRect.left + m_pLogTprTreeCtrl->pImageNineFormat[0]->GetWidth();
iPosY = tClientRect.top + m_pLogTprTreeCtrl->pImageNineFormat[0]->GetHeight();
iWidth= tClientRect.right - tClientRect.left - m_pLogTprTreeCtrl->pImageNineFormat[3]->GetWidth() - m_pLogTprTreeCtrl->pImageNineFormat[5]->GetWidth();
iHight= tClientRect.bottom - tClientRect.top - m_pLogTprTreeCtrl->pImageNineFormat[1]->GetHeight() - m_pLogTprTreeCtrl->pImageNineFormat[7]->GetHeight();
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageNineFormat[4], RectF(iPosX, iPosY, iWidth, iHight));
//绘制九宫格第5块
iPosX = tClientRect.right - m_pLogTprTreeCtrl->pImageNineFormat[2]->GetWidth();
iPosY = tClientRect.top + m_pLogTprTreeCtrl->pImageNineFormat[2]->GetHeight();
iWidth= m_pLogTprTreeCtrl->pImageNineFormat[2]->GetWidth();
iHight= m_pLogTprTreeCtrl->pImageNineFormat[5]->GetHeight();
iCycTimes = (tClientRect.bottom - tClientRect.top - m_pLogTprTreeCtrl->pImageNineFormat[2]->GetHeight() - m_pLogTprTreeCtrl->pImageNineFormat[8]->GetHeight())/iHight;
for (i=0; i<iCycTimes;i++)
{
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageNineFormat[5], RectF(iPosX, iPosY, iWidth, iHight));
iPosY += m_pLogTprTreeCtrl->pImageNineFormat[5]->GetHeight();
}
iHight = (tClientRect.bottom - tClientRect.top - m_pLogTprTreeCtrl->pImageNineFormat[2]->GetHeight() - m_pLogTprTreeCtrl->pImageNineFormat[8]->GetHeight()) - iCycTimes * iHight;
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageNineFormat[5], RectF(iPosX, iPosY, iWidth, iHight));
//绘制九宫格第6块
iPosX = tClientRect.left;
iPosY = tClientRect.bottom - tClientRect.top - m_pLogTprTreeCtrl->pImageNineFormat[6]->GetHeight();
iWidth= m_pLogTprTreeCtrl->pImageNineFormat[6]->GetWidth();
iHight= m_pLogTprTreeCtrl->pImageNineFormat[6]->GetHeight();
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageNineFormat[6], RectF(iPosX, iPosY, iWidth, iHight));
//绘制九宫格第7块
iPosX = tClientRect.left + m_pLogTprTreeCtrl->pImageNineFormat[6]->GetWidth();
iPosY = tClientRect.bottom - tClientRect.top - m_pLogTprTreeCtrl->pImageNineFormat[6]->GetHeight();
iWidth= m_pLogTprTreeCtrl->pImageNineFormat[7]->GetWidth();
iHight= m_pLogTprTreeCtrl->pImageNineFormat[7]->GetHeight();
iCycTimes = (tClientRect.right - tClientRect.left - m_pLogTprTreeCtrl->pImageNineFormat[6]->GetWidth() - m_pLogTprTreeCtrl->pImageNineFormat[8]->GetWidth())/iWidth;
for (i=0; i<iCycTimes; i++)
{
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageNineFormat[7], RectF(iPosX, iPosY, iWidth, iHight));
iPosX += m_pLogTprTreeCtrl->pImageNineFormat[7]->GetWidth();
}
iWidth = (tClientRect.right - tClientRect.left - m_pLogTprTreeCtrl->pImageNineFormat[6]->GetWidth() - m_pLogTprTreeCtrl->pImageNineFormat[8]->GetWidth()) - iCycTimes * iWidth;
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageNineFormat[7], RectF(iPosX, iPosY, iWidth, iHight));
//绘制九宫格第8块
iPosX = tClientRect.right - m_pLogTprTreeCtrl->pImageNineFormat[8]->GetWidth();
iPosY = tClientRect.bottom - tClientRect.top - m_pLogTprTreeCtrl->pImageNineFormat[6]->GetHeight();
iWidth= m_pLogTprTreeCtrl->pImageNineFormat[8]->GetWidth();
iHight= m_pLogTprTreeCtrl->pImageNineFormat[8]->GetHeight();
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageNineFormat[8], RectF(iPosX, iPosY, iWidth, iHight));
}
/*
*绘制树,根据节点的可见性来决定是否绘制
*/
void CTprTreeCtrl::DrawTree(Graphics *pGraphics)
{
HTREEITEM hRoot;
HTREEITEM hChild;
HTREEITEM hSibling;
HTREEITEM hHight;
UINT nState;
RECT tRect;
CString cStr;//每项的文字
SHORT sHight;//每项的高度
BOOL buer;
UINT uiIndent = 0;
int iIndentTimes = 0;//缩进次数
int iDashLength = 10;//横虚线长度为10个像素
int iPosX;
int iPosY;
int i;
sHight = this->GetItemHeight();
uiIndent = this->GetIndent();//获取缩进量
pGraphics->SetTextRenderingHint(TextRenderingHintAntiAliasGridFit);//优化字体,消除锯齿走样
//绘制root
hRoot=this->GetRootItem();
this->GetItemRect(hRoot,&tRect,TRUE);
cStr = this->GetItemText(hRoot);
pGraphics->DrawString((CONST WCHAR*)(cStr), -1, m_pTprTreeCtrlTxtFont->pFont, RectF(tRect.left, tRect.top, tRect.right - tRect.left, tRect.bottom - tRect.top), m_pTprTreeCtrlTxtFont->pStringFormat, &SolidBrush(m_pTprTreeCtrlTxtFont->coColor));
Pen *myPen = new Pen(Color(255, 0, 0, 0), 1);//下面有对应的删除
myPen->SetDashStyle(DashStyleDash);
pGraphics->DrawLine(myPen, tRect.left - iDashLength, tRect.top + (sHight)/2, tRect.left, tRect.top + (sHight)/2);//绘制横虚线
buer = ItemHasChildren(hRoot);//判断root是否有子树以是否需要绘制加减号
if (buer)
{
iPosX = (tRect.left - iDashLength) - m_pLogTprTreeCtrl->pImageAddSub[0]->GetWidth()/2;
iPosY = (tRect.top + (sHight)/2) - m_pLogTprTreeCtrl->pImageAddSub[0]->GetHeight()/2;
nState = GetItemState(hRoot, TVIS_EXPANDED);//判断是否展开
if (0 != (nState & TVIS_EXPANDED))//表示已经展开
{
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageAddSub[1], RectF(iPosX, iPosY, m_pLogTprTreeCtrl->pImageAddSub[1]->GetWidth(), m_pLogTprTreeCtrl->pImageAddSub[1]->GetHeight()));//绘制root的前减号
}
else//没展开
{
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageAddSub[0], RectF(iPosX, iPosY, m_pLogTprTreeCtrl->pImageAddSub[0]->GetWidth(), m_pLogTprTreeCtrl->pImageAddSub[0]->GetHeight()));//绘制root的前加号
}
}
//绘制其他所有可见项
while ((hSibling=this->GetNextVisibleItem(hRoot)) != NULL)
{
this->GetItemRect(hSibling,&tRect,TRUE);
cStr = this->GetItemText(hSibling);
sHight = this->GetItemHeight();
pGraphics->DrawString((CONST WCHAR*)(cStr), -1, m_pTprTreeCtrlTxtFont->pFont, RectF(tRect.left, tRect.top, tRect.right - tRect.left, tRect.bottom - tRect.top), m_pTprTreeCtrlTxtFont->pStringFormat, &SolidBrush(m_pTprTreeCtrlTxtFont->coColor));
pGraphics->DrawLine(myPen, tRect.left - iDashLength, tRect.top + (sHight)/2, tRect.left, tRect.top + (sHight)/2);//绘制横虚线
iIndentTimes =(int) ((float)tRect.left/uiIndent)- 1;//注意此处一定把tRect.left转化为浮点!判断其共缩进了几次,然后用这个缩进次数来获取一个自变量从第一个竖线往后逐一绘制出被子树隔开的竖线
for (i=0;i<iIndentTimes;i++ )
{
pGraphics->DrawLine(myPen, tRect.left - iDashLength - uiIndent * i, tRect.top + (sHight)/2, tRect.left - iDashLength - uiIndent * i, (tRect.top + (sHight)/2) - sHight);//绘制被子树隔开的竖虚线
}
pGraphics->DrawLine(myPen, tRect.left - iDashLength, tRect.top + (sHight)/2, tRect.left - iDashLength, (tRect.top + (sHight)/2) - sHight);//绘制紧密相连的竖虚线
buer = ItemHasChildren(hSibling);//判断是否有子树以是否需要绘制加减号
if (buer)
{
iPosX = (tRect.left - iDashLength) - m_pLogTprTreeCtrl->pImageAddSub[0]->GetWidth()/2;
iPosY = (tRect.top + (sHight)/2) - m_pLogTprTreeCtrl->pImageAddSub[0]->GetHeight()/2;
nState = GetItemState(hSibling, TVIS_EXPANDED);//判断是否展开
if (0 != (nState & TVIS_EXPANDED))//表示已经展开
{
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageAddSub[1], RectF(iPosX, iPosY, m_pLogTprTreeCtrl->pImageAddSub[1]->GetWidth(), m_pLogTprTreeCtrl->pImageAddSub[1]->GetHeight()));//绘制root的前减号
}
else//没展开
{
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageAddSub[0], RectF(iPosX, iPosY, m_pLogTprTreeCtrl->pImageAddSub[0]->GetWidth(), m_pLogTprTreeCtrl->pImageAddSub[0]->GetHeight()));//绘制root的前加号
}
}
hRoot = hSibling;
}
delete myPen;
//绘制选中项的高亮项,此处替换成图
hHight = this->GetSelectedItem();
if (hHight != NULL)
{
this->GetItemRect(hHight,&tRect,TRUE);
SolidBrush sBrush(Color(125,0,0,255));
Pen *myPen = new Pen(Color(255, 0, 0, 0), 1);
myPen->SetDashStyle(DashStyleDash);
pGraphics->DrawRectangle(myPen, tRect.left, tRect.top, tRect.right - tRect.left, tRect.bottom - tRect.top);
pGraphics->FillRectangle(&sBrush,tRect.left, tRect.top, tRect.right - tRect.left, tRect.bottom - tRect.top);
delete myPen;
}
}
/*
*绘制滚动条
*/
void CTprTreeCtrl::DrawScrollBar(Graphics *pGraphics)
{
RECT tClientRect;
RECT tWndRect;
SCROLLBARINFO tScrollBarInfoV;
SCROLLBARINFO tScrollBarInfoH;
int iPosX = 0;
int iPosY = 0;
int iWidth= 0;
int iHight= 0;
int iCycTimes;
int i;
this->GetClientRect(&tClientRect);
this->GetWindowRect(&tWndRect);
tScrollBarInfoV.cbSize = sizeof(SCROLLBARINFO);
if ((tWndRect.right - tWndRect.left) != tClientRect.right)
{
//绘制垂直滚动条拇指
this->GetScrollBarInfo(OBJID_VSCROLL,&tScrollBarInfoV);//得到垂直滚动条的信息,包括“拇指”的坐标信息及滚动条自身的坐标信息等。
iPosX = tScrollBarInfoV.rcScrollBar.left - tWndRect.left;//所有的X坐标都一样
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageThumbV[0], RectF(iPosX, tScrollBarInfoV.xyThumbTop, m_pLogTprTreeCtrl->pImageThumbV[0]->GetWidth(), tScrollBarInfoV.xyThumbBottom - tScrollBarInfoV.xyThumbTop));
//绘制垂直滚动条衬底
//三宫格第一块
//iWidth= tScrollBarInfoV.rcScrollBar.right - tScrollBarInfoV.rcScrollBar.left;
iWidth= m_pLogTprTreeCtrl->pImageScrollBarV[0]->GetWidth();
iHight= m_pLogTprTreeCtrl->pImageScrollBarV[0]->GetHeight();
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageScrollBarV[0], RectF(iPosX, iPosY, iWidth, iHight));
//三宫格第二块
iPosY = tScrollBarInfoV.rcScrollBar.top - tWndRect.top + m_pLogTprTreeCtrl->pImageScrollBarV[0]->GetHeight();
//iWidth= tScrollBarInfoV.rcScrollBar.right - tScrollBarInfoV.rcScrollBar.left;
iWidth = m_pLogTprTreeCtrl->pImageScrollBarV[1]->GetWidth();
iHight= m_pLogTprTreeCtrl->pImageScrollBarV[1]->GetHeight();
iCycTimes = (tScrollBarInfoV.rcScrollBar.bottom - tScrollBarInfoV.rcScrollBar.top - m_pLogTprTreeCtrl->pImageScrollBarV[0]->GetHeight() - m_pLogTprTreeCtrl->pImageScrollBarV[2]->GetHeight()) / m_pLogTprTreeCtrl->pImageScrollBarV[1]->GetHeight();
for (i=0;i<iCycTimes;i++)
{
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageScrollBarV[1], RectF(iPosX, iPosY, iWidth, iHight));
iPosY += m_pLogTprTreeCtrl->pImageScrollBarV[1]->GetHeight();
}
iHight = (tScrollBarInfoV.rcScrollBar.bottom - tScrollBarInfoV.rcScrollBar.top - m_pLogTprTreeCtrl->pImageScrollBarV[0]->GetHeight() - m_pLogTprTreeCtrl->pImageScrollBarV[2]->GetHeight()) - iCycTimes * m_pLogTprTreeCtrl->pImageScrollBarV[1]->GetHeight();
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageScrollBarV[1], RectF(iPosX, iPosY, iWidth, iHight));
//三宫格第三块
iPosY = tScrollBarInfoV.rcScrollBar.bottom - tWndRect.top - m_pLogTprTreeCtrl->pImageScrollBarV[2]->GetHeight();
//iWidth= tScrollBarInfoV.rcScrollBar.right - tScrollBarInfoV.rcScrollBar.left;
iWidth = m_pLogTprTreeCtrl->pImageScrollBarV[2]->GetWidth();
iHight= m_pLogTprTreeCtrl->pImageScrollBarV[2]->GetHeight();
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageScrollBarV[2], RectF(iPosX, iPosY, iWidth, iHight));
/*
//绘制垂直滚动条上箭头
iPosX = tScrollBarInfoV.rcScrollBar.left - tWndRect.left;
iPosY = tScrollBarInfoV.rcScrollBar.top - tWndRect.top;
iWidth= tScrollBarInfoV.rcScrollBar.right - tScrollBarInfoV.rcScrollBar.left;
iHight= m_pLogTreeCtrl->pImageScrollArrowV[0]->GetHeight();
CTprUiFun::DrawImage(pGraphics, m_pLogTreeCtrl->pImageScrollArrowV[0], RectF(iPosX, iPosY, iWidth, iHight));
//绘制垂直滚动条下箭头
iPosX = tScrollBarInfoV.rcScrollBar.left - tWndRect.left;
iPosY = tScrollBarInfoV.rcScrollBar.bottom - m_pLogTreeCtrl->pImageScrollArrowV[1]->GetHeight();
iWidth= tScrollBarInfoV.rcScrollBar.right - tScrollBarInfoV.rcScrollBar.left;
iHight= m_pLogTreeCtrl->pImageScrollArrowV[1]->GetHeight();
CTprUiFun::DrawImage(pGraphics, m_pLogTreeCtrl->pImageScrollArrowV[1], RectF(iPosX, iPosY, iWidth, iHight));
*/
}
tScrollBarInfoH.cbSize = sizeof(SCROLLBARINFO);
if ((tWndRect.bottom - tWndRect.top) != tClientRect.bottom)
{
//绘制水平滚动条拇指
this->GetScrollBarInfo(OBJID_HSCROLL,&tScrollBarInfoH);//得到水平滚动条的信息,包括“拇指”的坐标信息及滚动条自身的坐标信息等。
iPosY = tScrollBarInfoH.rcScrollBar.top - tWndRect.top;
//CTprUiFun::DrawImage(pGraphics, m_pLogTreeCtrl->pImageThumbH[0], RectF(tScrollBarInfoH.xyThumbTop, tScrollBarInfoH.rcScrollBar.top - tWndRect.top, tScrollBarInfoH.xyThumbBottom - tScrollBarInfoH.xyThumbTop,tScrollBarInfoH.dxyLineButton));
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageThumbH[0], RectF(tScrollBarInfoH.xyThumbTop, iPosY, tScrollBarInfoH.xyThumbBottom - tScrollBarInfoH.xyThumbTop,m_pLogTprTreeCtrl->pImageThumbH[0]->GetHeight()));
//绘制水平滚动条衬底
//三宫格第一块
iPosX = tScrollBarInfoH.rcScrollBar.left - tWndRect.left;
iWidth= m_pLogTprTreeCtrl->pImageScrollBarH[0]->GetWidth();
//iHight= tScrollBarInfoH.rcScrollBar.bottom - tScrollBarInfoH.rcScrollBar.top;
iHight= m_pLogTprTreeCtrl->pImageScrollBarH[0]->GetHeight();
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageScrollBarH[0], RectF(iPosX, iPosY, iWidth, iHight));
//三宫格第二块
iPosX = tScrollBarInfoH.rcScrollBar.left - tWndRect.left + m_pLogTprTreeCtrl->pImageScrollBarH[0]->GetWidth();
iWidth= m_pLogTprTreeCtrl->pImageScrollBarH[1]->GetWidth();
//iHight= tScrollBarInfoH.rcScrollBar.bottom - tScrollBarInfoH.rcScrollBar.top;
iHight= m_pLogTprTreeCtrl->pImageScrollBarH[1]->GetHeight();
iCycTimes = (tScrollBarInfoH.rcScrollBar.right - tScrollBarInfoH.rcScrollBar.left - m_pLogTprTreeCtrl->pImageScrollBarH[0]->GetWidth() - m_pLogTprTreeCtrl->pImageScrollBarH[2]->GetWidth()) / m_pLogTprTreeCtrl->pImageScrollBarH[1]->GetWidth();
for (i=0; i<iCycTimes;i++)
{
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageScrollBarH[1], RectF(iPosX, iPosY, iWidth, iHight));
iPosX += m_pLogTprTreeCtrl->pImageScrollBarH[1]->GetWidth();
}
iWidth = (tScrollBarInfoH.rcScrollBar.right - tScrollBarInfoH.rcScrollBar.left - m_pLogTprTreeCtrl->pImageScrollBarH[0]->GetWidth() - m_pLogTprTreeCtrl->pImageScrollBarH[2]->GetWidth()) - iCycTimes * m_pLogTprTreeCtrl->pImageScrollBarH[1]->GetWidth();
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageScrollBarH[1], RectF(iPosX, iPosY, iWidth, iHight));
//三宫格第三块
iPosX = tScrollBarInfoH.rcScrollBar.right - tScrollBarInfoH.rcScrollBar.left - m_pLogTprTreeCtrl->pImageScrollBarH[2]->GetWidth();
iWidth= m_pLogTprTreeCtrl->pImageScrollBarH[2]->GetWidth();
//iHight= tScrollBarInfoH.rcScrollBar.bottom - tScrollBarInfoH.rcScrollBar.top;
iHight= m_pLogTprTreeCtrl->pImageScrollBarH[2]->GetHeight();
CTprUiFun::DrawImage(pGraphics, m_pLogTprTreeCtrl->pImageScrollBarH[2], RectF(iPosX, iPosY, iWidth, iHight));
/*
//绘制水平滚动条左箭头
iPosX = tScrollBarInfoH.rcScrollBar.left - tWndRect.left;
iPosY = tScrollBarInfoH.rcScrollBar.top - tWndRect.top;
iWidth= m_pLogTreeCtrl->pImageScrollArrowH[0]->GetWidth();
iHight= tScrollBarInfoH.rcScrollBar.bottom - tScrollBarInfoH.rcScrollBar.top;
CTprUiFun::DrawImage(pGraphics, m_pLogTreeCtrl->pImageScrollArrowH[0], RectF(iPosX, iPosY, iWidth, iHight));
//绘制水平滚动条右箭头
iPosX = tScrollBarInfoH.rcScrollBar.right - m_pLogTreeCtrl->pImageScrollArrowH[1]->GetWidth();
iPosY = tScrollBarInfoH.rcScrollBar.top - tWndRect.top;
iWidth= m_pLogTreeCtrl->pImageScrollArrowH[1]->GetWidth();
iHight= tScrollBarInfoH.rcScrollBar.bottom - tScrollBarInfoH.rcScrollBar.top;
CTprUiFun::DrawImage(pGraphics, m_pLogTreeCtrl->pImageScrollArrowH[1], RectF(iPosX, iPosY, iWidth, iHight));
*/
}
}
/*
*触发自绘
*/
void CTprTreeCtrl::OnPaint()
{
::SendMessage(GetParent()->m_hWnd, WM_PAINT, (WPARAM)0, (LPARAM)0);
}
转http://hi.baidu.com/guanfaliu/blog/item/35516e60106e99ca8cb10d58.html