19 个解决方案
#1
本程序实现下面的平面组合框,供参考,道理一样
#if !defined(FLATCOMBOBOX_H_INCLUDED)
#define FLATCOMBOBOX_H_INCLUDED
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define FC_DRAWNORMAL 0x00000001
#define FC_DRAWRAISED 0x00000002
#define FC_DRAWPRESSD 0x00000004
/////////////////////////////////////////////////////////////////////////////
// CFlatComboBox window
class CFlatComboBox : public CComboBox
{
// Construction
public:
CFlatComboBox();
// Attributes
public:
bool m_bLBtnDown;
COLORREF m_clrHilite;
COLORREF m_clrShadow;
COLORREF m_clrDkShad;
COLORREF m_clrButton;
// Operations
public:
void DrawCombo(DWORD dwStyle, COLORREF clrTopLeft, COLORREF clrBottomRight);
int Offset();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CFlatComboBox)
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CFlatComboBox();
// Generated message map functions
protected:
//{{AFX_MSG(CFlatComboBox)
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnPaint();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(FLATCOMBOBOX_H_INCLUDED)
#if !defined(FLATCOMBOBOX_H_INCLUDED)
#define FLATCOMBOBOX_H_INCLUDED
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define FC_DRAWNORMAL 0x00000001
#define FC_DRAWRAISED 0x00000002
#define FC_DRAWPRESSD 0x00000004
/////////////////////////////////////////////////////////////////////////////
// CFlatComboBox window
class CFlatComboBox : public CComboBox
{
// Construction
public:
CFlatComboBox();
// Attributes
public:
bool m_bLBtnDown;
COLORREF m_clrHilite;
COLORREF m_clrShadow;
COLORREF m_clrDkShad;
COLORREF m_clrButton;
// Operations
public:
void DrawCombo(DWORD dwStyle, COLORREF clrTopLeft, COLORREF clrBottomRight);
int Offset();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CFlatComboBox)
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CFlatComboBox();
// Generated message map functions
protected:
//{{AFX_MSG(CFlatComboBox)
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnPaint();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(FLATCOMBOBOX_H_INCLUDED)
#2
#include "stdafx.h"
#include "FlatComboBox.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFlatComboBox
CFlatComboBox::CFlatComboBox()
{
m_bLBtnDown = false;
}
CFlatComboBox::~CFlatComboBox()
{
}
BEGIN_MESSAGE_MAP(CFlatComboBox, CComboBox)
//{{AFX_MSG_MAP(CFlatComboBox)
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_TIMER()
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFlatComboBox message handlers
void CFlatComboBox::OnMouseMove(UINT nFlags, CPoint point)
{
SetTimer(1,10,NULL);
CComboBox::OnMouseMove(nFlags, point);
}
void CFlatComboBox::OnLButtonDown(UINT nFlags, CPoint point)
{
m_bLBtnDown = true;
CComboBox::OnLButtonDown(nFlags, point);
}
void CFlatComboBox::OnLButtonUp(UINT nFlags, CPoint point)
{
m_bLBtnDown = false;
Invalidate();
CComboBox::OnLButtonUp(nFlags, point);
}
void CFlatComboBox::OnTimer(UINT nIDEvent)
{
POINT pt;
GetCursorPos(&pt);
CRect rcItem;
GetWindowRect(&rcItem);
static bool bPainted = false;
// OnLButtonDown, show pressed.
if (m_bLBtnDown==true) {
KillTimer (1);
if (bPainted == true) {
DrawCombo(FC_DRAWPRESSD, ::GetSysColor(COLOR_BTNSHADOW),
::GetSysColor(COLOR_BTNHIGHLIGHT));
bPainted = false;
}
return;
}
// If mouse leaves, show flat.
if (!rcItem.PtInRect(pt)) {
KillTimer (1);
if (bPainted == true) {
DrawCombo(FC_DRAWNORMAL, ::GetSysColor(COLOR_BTNFACE),
::GetSysColor(COLOR_BTNFACE));
bPainted = false;
}
return;
}
// On mouse over, show raised.
else {
if (bPainted == true)
return;
else {
bPainted = true;
DrawCombo(FC_DRAWRAISED, ::GetSysColor(COLOR_BTNSHADOW),
::GetSysColor(COLOR_BTNHIGHLIGHT));
}
}
CComboBox::OnTimer(nIDEvent);
}
void CFlatComboBox::OnPaint()
{
Default();
DrawCombo(FC_DRAWNORMAL, ::GetSysColor(COLOR_BTNFACE),
::GetSysColor(COLOR_BTNFACE));
}
void CFlatComboBox::DrawCombo(DWORD dwStyle, COLORREF clrTopLeft, COLORREF clrBottomRight)
{
CRect rcItem;
GetClientRect(&rcItem);
CDC* pDC = GetDC();
// Cover up dark 3D shadow.
pDC->Draw3dRect(rcItem, clrTopLeft, clrBottomRight);
rcItem.DeflateRect(1,1);
if (!IsWindowEnabled()) {
pDC->Draw3dRect(rcItem, ::GetSysColor(COLOR_BTNHIGHLIGHT),
::GetSysColor(COLOR_BTNHIGHLIGHT));
}
else {
pDC->Draw3dRect(rcItem, ::GetSysColor(COLOR_BTNFACE),
::GetSysColor(COLOR_BTNFACE));
}
// Cover up dark 3D shadow on drop arrow.
rcItem.DeflateRect(1,1);
rcItem.left = rcItem.right-Offset();
pDC->Draw3dRect(rcItem, ::GetSysColor(COLOR_BTNFACE),
::GetSysColor(COLOR_BTNFACE));
// Cover up normal 3D shadow on drop arrow.
rcItem.DeflateRect(1,1);
pDC->Draw3dRect(rcItem, ::GetSysColor(COLOR_BTNFACE),
::GetSysColor(COLOR_BTNFACE));
if (!IsWindowEnabled()) {
return;
}
switch (dwStyle)
{
case FC_DRAWNORMAL:
rcItem.top -= 1;
rcItem.bottom += 1;
pDC->Draw3dRect(rcItem, ::GetSysColor(COLOR_BTNHIGHLIGHT),
::GetSysColor(COLOR_BTNHIGHLIGHT));
rcItem.left -= 1;
pDC->Draw3dRect(rcItem, ::GetSysColor(COLOR_BTNHIGHLIGHT),
::GetSysColor(COLOR_BTNHIGHLIGHT));
break;
case FC_DRAWRAISED:
rcItem.top -= 1;
rcItem.bottom += 1;
pDC->Draw3dRect(rcItem, ::GetSysColor(COLOR_BTNHIGHLIGHT),
::GetSysColor(COLOR_BTNSHADOW));
break;
case FC_DRAWPRESSD:
rcItem.top -= 1;
rcItem.bottom += 1;
rcItem.OffsetRect(1,1);
pDC->Draw3dRect(rcItem, ::GetSysColor(COLOR_BTNSHADOW),
::GetSysColor(COLOR_BTNHIGHLIGHT));
break;
}
ReleaseDC(pDC);
}
int CFlatComboBox::Offset()
{
// Thanks to Todd Brannam for this suggestion...
return ::GetSystemMetrics(SM_CXHTHUMB);
}
#3
http://www.codeproject.com/cs/miscctrl/FlatDateTimePicker.asp
#4
十分感谢楼上两位的帮忙
关于ComboBox的Flat样式我早已实现,但是DateTimePicker跟ComboBox的实现原理相距甚远,在DateTimePicker的基类CDateTimeCtrl的派生类中重载OnPaint是没有用的,这样只能在3D边框以内画东西,要去掉3D边框只能重载OnNcPaint,可是去掉3D边框容易,加上自己的边框可就难了,我尝试了多种方法也不能在原边框的位置上画出任何东西,这个原3D边框的区域十分神秘,我研究了两天也没出结果(汗一个),网上也没找到有价值信息,求之不得,辗转反侧,请各位高人帮忙,谢谢
关于ComboBox的Flat样式我早已实现,但是DateTimePicker跟ComboBox的实现原理相距甚远,在DateTimePicker的基类CDateTimeCtrl的派生类中重载OnPaint是没有用的,这样只能在3D边框以内画东西,要去掉3D边框只能重载OnNcPaint,可是去掉3D边框容易,加上自己的边框可就难了,我尝试了多种方法也不能在原边框的位置上画出任何东西,这个原3D边框的区域十分神秘,我研究了两天也没出结果(汗一个),网上也没找到有价值信息,求之不得,辗转反侧,请各位高人帮忙,谢谢
#5
o
#6
striking(硬撑者) ( ) 信誉:109 2006-05-25 15:58:00 得分: 0
o
兄台可有良策?
o
兄台可有良策?
#7
lixiaosan(小三) ( ) 信誉:150 2006-05-25 14:26:00 得分: 0
http://www.codeproject.com/cs/miscctrl/FlatDateTimePicker.asp
看到这个C#的了,尝试把它转到C++,不过我不懂C#,弄了半天也没弄明白,可有高人指点?
http://www.codeproject.com/cs/miscctrl/FlatDateTimePicker.asp
看到这个C#的了,尝试把它转到C++,不过我不懂C#,弄了半天也没弄明白,可有高人指点?
#8
他也是重新处理了WM_NC_PAINT, WM_PAINT and WM_NCHITTEST 等。。。你也做类似处理即可。。
#9
画上去
#10
pripor(GDI+真是好) ( ) 信誉:100 2006-05-25 22:48:00 得分: 0
画上去
==================================================================
画不上啊
画上去
==================================================================
画不上啊
#11
他也是重新处理了WM_NC_PAINT, WM_PAINT and WM_NCHITTEST 等。。。你也做类似处理即可。。
======================================================
我竟然没看懂它对那一系列消息的处理,没发现什么玄机
======================================================
我竟然没看懂它对那一系列消息的处理,没发现什么玄机
#12
mark
#13
世界性难题?
#14
大仙们显显灵吧
#15
天灵灵,地灵灵 ... ...
#16
顶
#17
诸位辛苦,虽然没有收到一个具有建设性的,解决问题的回复,还是感谢大家的捧场
#18
学习,UP!
#19
帮顶
#20
#1
本程序实现下面的平面组合框,供参考,道理一样
#if !defined(FLATCOMBOBOX_H_INCLUDED)
#define FLATCOMBOBOX_H_INCLUDED
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define FC_DRAWNORMAL 0x00000001
#define FC_DRAWRAISED 0x00000002
#define FC_DRAWPRESSD 0x00000004
/////////////////////////////////////////////////////////////////////////////
// CFlatComboBox window
class CFlatComboBox : public CComboBox
{
// Construction
public:
CFlatComboBox();
// Attributes
public:
bool m_bLBtnDown;
COLORREF m_clrHilite;
COLORREF m_clrShadow;
COLORREF m_clrDkShad;
COLORREF m_clrButton;
// Operations
public:
void DrawCombo(DWORD dwStyle, COLORREF clrTopLeft, COLORREF clrBottomRight);
int Offset();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CFlatComboBox)
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CFlatComboBox();
// Generated message map functions
protected:
//{{AFX_MSG(CFlatComboBox)
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnPaint();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(FLATCOMBOBOX_H_INCLUDED)
#if !defined(FLATCOMBOBOX_H_INCLUDED)
#define FLATCOMBOBOX_H_INCLUDED
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define FC_DRAWNORMAL 0x00000001
#define FC_DRAWRAISED 0x00000002
#define FC_DRAWPRESSD 0x00000004
/////////////////////////////////////////////////////////////////////////////
// CFlatComboBox window
class CFlatComboBox : public CComboBox
{
// Construction
public:
CFlatComboBox();
// Attributes
public:
bool m_bLBtnDown;
COLORREF m_clrHilite;
COLORREF m_clrShadow;
COLORREF m_clrDkShad;
COLORREF m_clrButton;
// Operations
public:
void DrawCombo(DWORD dwStyle, COLORREF clrTopLeft, COLORREF clrBottomRight);
int Offset();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CFlatComboBox)
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CFlatComboBox();
// Generated message map functions
protected:
//{{AFX_MSG(CFlatComboBox)
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnPaint();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(FLATCOMBOBOX_H_INCLUDED)
#2
#include "stdafx.h"
#include "FlatComboBox.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFlatComboBox
CFlatComboBox::CFlatComboBox()
{
m_bLBtnDown = false;
}
CFlatComboBox::~CFlatComboBox()
{
}
BEGIN_MESSAGE_MAP(CFlatComboBox, CComboBox)
//{{AFX_MSG_MAP(CFlatComboBox)
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_TIMER()
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFlatComboBox message handlers
void CFlatComboBox::OnMouseMove(UINT nFlags, CPoint point)
{
SetTimer(1,10,NULL);
CComboBox::OnMouseMove(nFlags, point);
}
void CFlatComboBox::OnLButtonDown(UINT nFlags, CPoint point)
{
m_bLBtnDown = true;
CComboBox::OnLButtonDown(nFlags, point);
}
void CFlatComboBox::OnLButtonUp(UINT nFlags, CPoint point)
{
m_bLBtnDown = false;
Invalidate();
CComboBox::OnLButtonUp(nFlags, point);
}
void CFlatComboBox::OnTimer(UINT nIDEvent)
{
POINT pt;
GetCursorPos(&pt);
CRect rcItem;
GetWindowRect(&rcItem);
static bool bPainted = false;
// OnLButtonDown, show pressed.
if (m_bLBtnDown==true) {
KillTimer (1);
if (bPainted == true) {
DrawCombo(FC_DRAWPRESSD, ::GetSysColor(COLOR_BTNSHADOW),
::GetSysColor(COLOR_BTNHIGHLIGHT));
bPainted = false;
}
return;
}
// If mouse leaves, show flat.
if (!rcItem.PtInRect(pt)) {
KillTimer (1);
if (bPainted == true) {
DrawCombo(FC_DRAWNORMAL, ::GetSysColor(COLOR_BTNFACE),
::GetSysColor(COLOR_BTNFACE));
bPainted = false;
}
return;
}
// On mouse over, show raised.
else {
if (bPainted == true)
return;
else {
bPainted = true;
DrawCombo(FC_DRAWRAISED, ::GetSysColor(COLOR_BTNSHADOW),
::GetSysColor(COLOR_BTNHIGHLIGHT));
}
}
CComboBox::OnTimer(nIDEvent);
}
void CFlatComboBox::OnPaint()
{
Default();
DrawCombo(FC_DRAWNORMAL, ::GetSysColor(COLOR_BTNFACE),
::GetSysColor(COLOR_BTNFACE));
}
void CFlatComboBox::DrawCombo(DWORD dwStyle, COLORREF clrTopLeft, COLORREF clrBottomRight)
{
CRect rcItem;
GetClientRect(&rcItem);
CDC* pDC = GetDC();
// Cover up dark 3D shadow.
pDC->Draw3dRect(rcItem, clrTopLeft, clrBottomRight);
rcItem.DeflateRect(1,1);
if (!IsWindowEnabled()) {
pDC->Draw3dRect(rcItem, ::GetSysColor(COLOR_BTNHIGHLIGHT),
::GetSysColor(COLOR_BTNHIGHLIGHT));
}
else {
pDC->Draw3dRect(rcItem, ::GetSysColor(COLOR_BTNFACE),
::GetSysColor(COLOR_BTNFACE));
}
// Cover up dark 3D shadow on drop arrow.
rcItem.DeflateRect(1,1);
rcItem.left = rcItem.right-Offset();
pDC->Draw3dRect(rcItem, ::GetSysColor(COLOR_BTNFACE),
::GetSysColor(COLOR_BTNFACE));
// Cover up normal 3D shadow on drop arrow.
rcItem.DeflateRect(1,1);
pDC->Draw3dRect(rcItem, ::GetSysColor(COLOR_BTNFACE),
::GetSysColor(COLOR_BTNFACE));
if (!IsWindowEnabled()) {
return;
}
switch (dwStyle)
{
case FC_DRAWNORMAL:
rcItem.top -= 1;
rcItem.bottom += 1;
pDC->Draw3dRect(rcItem, ::GetSysColor(COLOR_BTNHIGHLIGHT),
::GetSysColor(COLOR_BTNHIGHLIGHT));
rcItem.left -= 1;
pDC->Draw3dRect(rcItem, ::GetSysColor(COLOR_BTNHIGHLIGHT),
::GetSysColor(COLOR_BTNHIGHLIGHT));
break;
case FC_DRAWRAISED:
rcItem.top -= 1;
rcItem.bottom += 1;
pDC->Draw3dRect(rcItem, ::GetSysColor(COLOR_BTNHIGHLIGHT),
::GetSysColor(COLOR_BTNSHADOW));
break;
case FC_DRAWPRESSD:
rcItem.top -= 1;
rcItem.bottom += 1;
rcItem.OffsetRect(1,1);
pDC->Draw3dRect(rcItem, ::GetSysColor(COLOR_BTNSHADOW),
::GetSysColor(COLOR_BTNHIGHLIGHT));
break;
}
ReleaseDC(pDC);
}
int CFlatComboBox::Offset()
{
// Thanks to Todd Brannam for this suggestion...
return ::GetSystemMetrics(SM_CXHTHUMB);
}
#3
http://www.codeproject.com/cs/miscctrl/FlatDateTimePicker.asp
#4
十分感谢楼上两位的帮忙
关于ComboBox的Flat样式我早已实现,但是DateTimePicker跟ComboBox的实现原理相距甚远,在DateTimePicker的基类CDateTimeCtrl的派生类中重载OnPaint是没有用的,这样只能在3D边框以内画东西,要去掉3D边框只能重载OnNcPaint,可是去掉3D边框容易,加上自己的边框可就难了,我尝试了多种方法也不能在原边框的位置上画出任何东西,这个原3D边框的区域十分神秘,我研究了两天也没出结果(汗一个),网上也没找到有价值信息,求之不得,辗转反侧,请各位高人帮忙,谢谢
关于ComboBox的Flat样式我早已实现,但是DateTimePicker跟ComboBox的实现原理相距甚远,在DateTimePicker的基类CDateTimeCtrl的派生类中重载OnPaint是没有用的,这样只能在3D边框以内画东西,要去掉3D边框只能重载OnNcPaint,可是去掉3D边框容易,加上自己的边框可就难了,我尝试了多种方法也不能在原边框的位置上画出任何东西,这个原3D边框的区域十分神秘,我研究了两天也没出结果(汗一个),网上也没找到有价值信息,求之不得,辗转反侧,请各位高人帮忙,谢谢
#5
o
#6
striking(硬撑者) ( ) 信誉:109 2006-05-25 15:58:00 得分: 0
o
兄台可有良策?
o
兄台可有良策?
#7
lixiaosan(小三) ( ) 信誉:150 2006-05-25 14:26:00 得分: 0
http://www.codeproject.com/cs/miscctrl/FlatDateTimePicker.asp
看到这个C#的了,尝试把它转到C++,不过我不懂C#,弄了半天也没弄明白,可有高人指点?
http://www.codeproject.com/cs/miscctrl/FlatDateTimePicker.asp
看到这个C#的了,尝试把它转到C++,不过我不懂C#,弄了半天也没弄明白,可有高人指点?
#8
他也是重新处理了WM_NC_PAINT, WM_PAINT and WM_NCHITTEST 等。。。你也做类似处理即可。。
#9
画上去
#10
pripor(GDI+真是好) ( ) 信誉:100 2006-05-25 22:48:00 得分: 0
画上去
==================================================================
画不上啊
画上去
==================================================================
画不上啊
#11
他也是重新处理了WM_NC_PAINT, WM_PAINT and WM_NCHITTEST 等。。。你也做类似处理即可。。
======================================================
我竟然没看懂它对那一系列消息的处理,没发现什么玄机
======================================================
我竟然没看懂它对那一系列消息的处理,没发现什么玄机
#12
mark
#13
世界性难题?
#14
大仙们显显灵吧
#15
天灵灵,地灵灵 ... ...
#16
顶
#17
诸位辛苦,虽然没有收到一个具有建设性的,解决问题的回复,还是感谢大家的捧场
#18
学习,UP!
#19
帮顶