📄 gprsstatic.cpp
字号:
// clockstrl.cpp : Defines the class behaviors for the application.
//
///////////////////////////////// Includes //////////////////////////////////
#include "stdafx.h"
#include "Gprsstatic.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
///////////////////////////////// Implementation //////////////////////////////
BEGIN_MESSAGE_MAP(CGprsStatic, CStatic)
//{{AFX_MSG_MAP(CGprsStatic)
ON_WM_PAINT()
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CGprsStatic::CGprsStatic()
{
Init();
}
void CGprsStatic::PreSubclassWindow()
{
CStatic::PreSubclassWindow();//Let the parent class do its thing
PreDrawBackGround();
}
void CGprsStatic::OnPaint()
{
CPaintDC dc(this);//最少要在此函数中调用一次(CPaintDC)
// Refresh();
DrawInterFace();
}
BOOL CGprsStatic::OnEraseBkgnd(CDC* pDC)
{
if(m_bBkTransparent)
{
if(!m_bDCStored)
{
CRect clientRect;
GetClientRect(&clientRect);
int cx=clientRect.Width ();
int cy=clientRect.Height ();
// Store our orignal DC.
CBitmap bitmap;
memDC.CreateCompatibleDC (pDC);
bitmap.CreateCompatibleBitmap (pDC,cx,cy);
memDC.SelectObject (&bitmap);
memDC.BitBlt (0,0,cx,cy,pDC,0,0,SRCCOPY);
m_bDCStored=TRUE;
}
return TRUE;
}
else
{
return FALSE;
}
//return TRUE;
}
CGprsStatic::CGprsStatic(UINT BackgroundID,BOOL BackGroudEnable)
{
Init();
m_DispBMPBackground=BackGroudEnable;
m_BMPBackgroundID=BackgroundID;
m_bBkTransparent=FALSE;
m_bDCStored=FALSE;
}
void CGprsStatic::Init()
{
//Initialize the member variables to their default values
m_ColorBackground =RGB(154,203,233);
m_BMPBackgroundID=0;
m_DispBMPBackground=FALSE;
m_ColorCaption=RGB(255,255,255);
m_csStrCaptionName=_T("");
m_uiFontHight=15;
m_uiFontWidth=0;
}
void CGprsStatic::DrawBackGround()
{
if(m_DispBMPBackground)
{
// device context for painting
//CPaintDC dc(this);
CClientDC dc(this);//这里不能用CPaintDC,否则有问题
//Force a recalc if not initialized
//-------------------------------------
CDC dcMem;
dcMem.CreateCompatibleDC(&dc); //创建与对话框dc兼容的内存dc
CRect rect;
GetClientRect(&rect);
BITMAP bitMap;
m_bmpBackground.GetBitmap(&bitMap);
CBitmap *pbmpOld=dcMem.SelectObject(&m_bmpBackground); //将背景位图选入内存dc中
dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitMap.bmWidth,bitMap.bmHeight,SRCCOPY); //将内存dc中的位图拉伸显示在对话框的dc中
//-------------------------------------
//SetBitmap((HBITMAP)pbmpOld->Detach());
}
}
void CGprsStatic::PreDrawBackGround()
{
if(m_DispBMPBackground)
{
m_bmpBackground.LoadBitmap(m_BMPBackgroundID); // 窗体背景图片
}
}
//add for Translate style
void CGprsStatic::Refresh()
{
CRect rect;
GetClientRect(&rect);
CClientDC dc(this);
if(m_bBkTransparent==FALSE)
{
//画背景或者填充背景颜色
// dc.FillRect(&rect,&CBrush(::GetSysColor(COLOR_BTNFACE)) );
}
else
{
dc.BitBlt (0,0,rect.Width (),rect.Height (),&memDC,0,0,SRCCOPY);
}
}
void CGprsStatic::SetTransparent(BOOL bTransparent)
{
m_bBkTransparent=bTransparent;
}
void CGprsStatic::DrawInterFace()//元素入口
{
// CPaintDC dc(this);//调用此函数发WM_PAINT消息
Refresh();
DrawBackGround();
DrawCaptionFace();
}
void CGprsStatic::DrawCaptionFace()
{
//Work out the size of the point rectangle
RECT rRect;
CRect rectClient;
GetClientRect(&rectClient);
rRect.left=rectClient.left;//(rectClient.Width()*1)/2;
rRect.top=rectClient.top+2;
rRect.right=rectClient.right;
rRect.bottom=rectClient.bottom;
// font we use
CFont font;
font.CreateFont(
m_uiFontHight, // nHeight
m_uiFontWidth, // nWidth
0, // nEscapement
0, // nOrientation
FW_BOLD,//FW_NORMAL, // nWeight
TRUE,//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("Arial") // lpszFacename
);
// Use the font which you just created.
CClientDC dc(this);
CFont* def_font = dc.SelectObject(&font);
dc.SetBkMode(TRANSPARENT);
dc.SetTextColor(m_ColorCaption);
dc.DrawText(m_csStrCaptionName,&rRect, DT_RIGHT | DT_TOP);
dc.SelectObject(def_font);
// Finished with the font, now delete the font object.
font.DeleteObject();
}
void CGprsStatic::SetCaption(LPTSTR ptsCaptionName,COLORREF colorfont,UINT uifontHight,UINT uifontWidth)
{
m_csStrCaptionName=ptsCaptionName;
m_ColorCaption=colorfont;
m_uiFontHight=uifontHight;
m_uiFontWidth=uifontWidth;
DrawInterFace();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -