看到很多软件里的Groupbox的四个角都是圆形,而不是普通的方形,VC里要用DrawItem自绘制的方法实现,请问DrawItem里具体的实现代码该是怎样的呢?
解决方案 »
- MFC如何模拟多个客户端
- 这个vb函数在vc中怎么样实现?
- 我想在VC7.1中看到宏扩展的结果,请问用什么编译选项或参数?
- 如何将自己定义的函数里的CString加到CListBox里.在线等.
- 怎么int转换成字符串
- 高级问题:为什么我创建的字体(提供给OpenGL)大小不能改变!?怎么改CreateFont的参数都无效。
- 我已贴过好几次了,就是没人能回答,是不是这样不行?(我在线等)
- 如何使无模式对话框在任务条上有一个对应的按钮。
- VC的SDK中如果用RegisterClass注册了两个或更多的窗口类后再调用CreateWindow或CreateWindowex时,那将创建哪个窗口类的实例呢?
- 关于winsock的一个问题,比较菜,答着有分
- 我在CDialog::OnInitDialog中new的对象,在哪个函数中delete好?
- 局域网内共享文件的复制问题?<用户权限相关>
=========================
也有可能该软件用的XP风格
* *
* GuiToolKit *
* (MFC extension) *
* Created by Francisco Campos G. www.beyondata.com [email protected] *
*--------------------------------------------------------------------------*
* *
* This program is free software;so you are free to use it any of your *
* applications (Freeware, Shareware, Commercial),but leave this header *
* intact. *
* *
* These files are provided "as is" without warranty of any kind. *
* *
* GuiToolKit is forever FREE CODE !!!!! *
* *
*--------------------------------------------------------------------------*
* Created by: Francisco Campos G. *
* Bug Fixes and improvements : (Add your name) *
* -Francisco Campos *
* *
****************************************************************************/
#include "stdafx.h"
#include "GuiGroupBox.h"
#include "GuiDrawLayer.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CGuiGroupBoxCGuiGroupBox::CGuiGroupBox()
{
m_clrface = /*GuiDrawLayer::GetRGBColorFace()*/RGB(233, 233, 233);
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 handlersvoid 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,_T("Verdana"));
else
m_cfont.CreateFont(-11,0,900,900,400,0,0,0,0,1,2,1,34,_T("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();
}
* *
* GuiToolKit *
* (MFC extension) *
* Created by Francisco Campos G. www.beyondata.com [email protected] *
*--------------------------------------------------------------------------*
* *
* This program is free software;so you are free to use it any of your *
* applications (Freeware, Shareware, Commercial),but leave this header *
* intact. *
* *
* These files are provided "as is" without warranty of any kind. *
* *
* GuiToolKit is forever FREE CODE !!!!! *
* *
*--------------------------------------------------------------------------*
* Created by: Francisco Campos G. *
* Bug Fixes and improvements : (Add your name) *
* -Francisco Campos *
* *
****************************************************************************/#if !defined(AFX_GUIGROUPBOX_H__C7AAD4CA_1B37_42E8_8F08_AEF18BA77DFD__INCLUDED_)
#define AFX_GUIGROUPBOX_H__C7AAD4CA_1B37_42E8_8F08_AEF18BA77DFD__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// GuiGroupBox.h : header file
///////////////////////////////////////////////////////////////////////////////
// CGuiGroupBox windowclass CGuiGroupBox : public CButton
{
// Construction
public:
CGuiGroupBox();
enum Aling{ALING_LEFT=0,ALING_RIGHT=1,ALING_DOWN=2, ALING_UP=3};
// Attributes
public:
void SetStyle(Aling AlingStyle);
void SetCaption(CString Caption);
Aling m_style;
COLORREF m_clrface;
COLORREF m_clrShadow;
CString m_Caption;
// Operations
public:
virtual void PreSubclassWindow();
public:
virtual ~CGuiGroupBox(); // Generated message map functions
protected:
//{{AFX_MSG(CGuiGroupBox)
afx_msg void OnPaint();
afx_msg void OnSysColorChange();
//}}AFX_MSG DECLARE_MESSAGE_MAP()
};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_GUIGROUPBOX_H__C7AAD4CA_1B37_42E8_8F08_AEF18BA77DFD__INCLUDED_)