⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guigroupbox.cpp

📁 一个很好用的串口侦听源代码
💻 CPP
字号:
//-----------------------------------------------------------------------//
// This is a part of the GuiLib MFC Extention.							 //	
// Autor  :  Francisco Campos											 //
// (C) 2002 Francisco Campos <www.beyondata.com> All rights reserved     //
// This code is provided "as is", with absolutely no warranty expressed  //
// or implied. Any use is at your own risk.								 //		
// You must obtain the author's consent before you can include this code //
// in a software library.												 //
// If the source code in  this file is used in any application			 //
// then acknowledgement must be made to the author of this program		 //	
// fco_campos@tutopia.com													 //
//-----------------------------------------------------------------------//

#include "stdafx.h"
#include "..\header\GuiGroupBox.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CGuiGroupBox
#include "..\header\GuiDrawLayer.h"
CGuiGroupBox::CGuiGroupBox()
{
	m_clrface=GuiDrawLayer::GetRGBColorFace();
	m_clrShadow=GuiDrawLayer::GetRGBColorShadow();
	m_style=ALING_LEFT;
	m_Caption=_T("");
}

CGuiGroupBox::~CGuiGroupBox()
{
}


BEGIN_MESSAGE_MAP(CGuiGroupBox, CButton)
	//{{AFX_MSG_MAP(CGuiGroupBox)
	ON_WM_PAINT()
	ON_WM_SYSCOLORCHANGE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGuiGroupBox message handlers

void CGuiGroupBox::PreSubclassWindow() 
{
	CButton::PreSubclassWindow();
	GetWindowText(m_Caption);
	SetWindowText(_T(""));
}

void CGuiGroupBox::SetCaption(CString Caption)
{
	m_Caption=Caption;
	SetWindowText(_T(""));
}

void CGuiGroupBox::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	CRect rc;
	GetClientRect(rc);
	CBrush cb;
	CFont m_cfont;
	CString m_caption;
	CPen cpshadow(PS_SOLID,1,GuiDrawLayer::GetRGBColorShadow());
	cb.CreateSolidBrush(m_clrface);
	
	if ((m_style == ALING_LEFT) || (m_style == ALING_RIGHT))
		m_cfont.CreateFont( -11,0,0,0,400,0,0,0,0,1,2,1,34,"Verdana");
	else
		m_cfont.CreateFont(-11,0,900,900,400,0,0,0,0,1,2,1,34,"Verdana");	
	
	//********************************************************
	CFont* m_fontOld=dc.SelectObject(&m_cfont);
	CSize SizeCad=dc.GetTextExtent(m_Caption);
	SizeCad.cx+=2;
	CRect rCText=rc;
	rc.DeflateRect(1,1);
	rc.top+=6;
	
	//orientar la cadena*************************************

		
	if (m_style == ALING_LEFT)
	{
		rCText.left+=6;
		rCText.bottom=rCText.top+SizeCad.cy+1;
		rCText.right=rCText.left+SizeCad.cx+1;
	}
	else if (m_style == ALING_RIGHT)
	{
		rCText.right-=6;
		rCText.left=rCText.right-SizeCad.cx+1;
		rCText.bottom=rCText.top+SizeCad.cy+1;
	}
	else if (m_style == ALING_DOWN)
	{
		rCText.bottom-=6;
		rCText.left=-7;
		rCText.top=rCText.bottom-SizeCad.cx;
		rCText.right=rCText.left+SizeCad.cy+1;
	}
	else if (m_style == ALING_UP)
	{
		rCText.top+=10;
		rCText.left=-7;
		rCText.right=rCText.left+SizeCad.cy+1;
		rCText.bottom=rCText.top+SizeCad.cx+7;
		
	}
	//********************************************************
	CPen* pOld=dc.SelectObject(&cpshadow);
	//linea superior
	dc.MoveTo(rc.left+2,rc.top);
	dc.LineTo(rc.right-2,rc.top);
	//linea vertical izquierda
	dc.MoveTo(rc.left,rc.top+2);
	dc.LineTo(rc.left,rc.bottom-2);
	//linea vertical derecha
	dc.MoveTo(rc.right,rc.top+2);
	dc.LineTo(rc.right,rc.bottom-2);
	//linea horizontal inferior
	dc.MoveTo(rc.left+2,rc.bottom);
	dc.LineTo(rc.right-2,rc.bottom);

	//ahora se dibujan los vertices

	//l,t
	dc.MoveTo(rc.left+2,rc.top);
	dc.LineTo(rc.left,rc.top+2);
	//r,t
	dc.MoveTo(rc.right-2,rc.top);
	dc.LineTo(rc.right,rc.top+2);
	//l,b
	dc.MoveTo(rc.left,rc.bottom-2);
	dc.LineTo(rc.left+2,rc.bottom);
	//r,b
	dc.MoveTo(rc.right-2,rc.bottom);
	dc.LineTo(rc.right,rc.bottom-2);
	
	//sentido del mensaje
	
	int nMode = dc.SetBkMode(TRANSPARENT);
	dc.FillRect(rCText,&cb);
	dc.SetTextColor(GuiDrawLayer::GetRGBCaptionXP());
	int cont=SizeCad.cx;
	if (m_style == ALING_DOWN || m_style == ALING_UP)
		dc.TextOut(rCText.left,rCText.bottom-2,m_Caption);
	else
		dc.TextOut(rCText.left,rCText.top,m_Caption);
 	dc.SetBkMode(nMode);
	dc.SelectObject(&m_fontOld);
}

void CGuiGroupBox::SetStyle(Aling style)
{
	m_style=style;
}

void CGuiGroupBox::OnSysColorChange() 
{
	m_clrface=GuiDrawLayer::GetRGBColorFace();
	m_clrShadow=GuiDrawLayer::GetRGBColorShadow();

	CButton::OnSysColorChange();

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -