GroupboxEx.cpp
资源名称:GGBT.rar [点击查看]
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:2k
源码类别:
P2P编程
开发平台:
Visual C++
- // GroupboxEx.cpp : implementation file
- //
- #include "stdafx.h"
- #include "testbt.h"
- #include "GroupboxEx.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CGroupboxEx
- CGroupBoxEx::CGroupBoxEx()
- {
- m_font.CreateFont(-12, 0, 0, 0, FW_BOLD, 0, 0, 0, 134, 0, 0, 0, 2, "宋体");
- }
- CGroupBoxEx::~CGroupBoxEx()
- {
- }
- BEGIN_MESSAGE_MAP(CGroupBoxEx, CButton)
- //{{AFX_MSG_MAP(CGroupBoxEx)
- ON_WM_PAINT()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CGroupBoxEx message handlers
- void CGroupBoxEx::PreSubclassWindow()
- {
- // store the current text (from resource)
- GetWindowText(m_txtString);
- // store the box rectangle
- GetWindowRect(&m_boxRect);
- ScreenToClient(&m_boxRect);
- CButton::PreSubclassWindow();
- }
- void CGroupBoxEx::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- // add a blank on each side of text
- CString sText;
- sText.Format(" %s ", m_txtString);
- // get the text size used by resource editor
- CSize seText0 = dc.GetTextExtent(sText);
- // set the font to draw
- CFont *oldFont = dc.SelectObject(&m_font);
- int PenStyle = PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_SQUARE;
- CPen pnFrmDark, pnFrmLight;
- pnFrmDark.CreatePen(PenStyle, 1, ::GetSysColor(COLOR_3DSHADOW));
- pnFrmLight.CreatePen(PenStyle, 1, ::GetSysColor(COLOR_3DHILIGHT));
- // get the drawn text size
- CSize seText = dc.GetTextExtent(sText);
- CPoint ptStart, ptEnd;
- ptStart.y = ptEnd.y = m_boxRect.top + seText0.cy / 2 - 1;
- ptStart.x = m_boxRect.left + seText.cx;
- ptEnd.x = m_boxRect.right;
- // draw the first box
- CPen* ppnOldPen = dc.SelectObject(&pnFrmDark);
- dc.MoveTo(ptStart);
- dc.LineTo(m_boxRect.right, ptStart.y);
- // draw the second box (hilite)
- dc.SelectObject(&pnFrmLight);
- dc.MoveTo(ptStart.x, ptStart.y + 1);
- dc.LineTo(m_boxRect.right + 1, ptStart.y + 1);
- //
- // draw text (if any)
- //
- dc.SetBkMode(TRANSPARENT);
- if(!sText.IsEmpty())
- {
- // get top of text box
- dc.DrawText(sText, m_boxRect,
- DT_TOP| DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
- }
- dc.SelectObject(oldFont);
- dc.SelectObject(ppnOldPen);
- // Do not call CButton::OnPaint() for painting messages
- }