自绘的CComboBox,怎样绘制右边有三角符号的下拉按钮?

cpluser 2003-06-11 11:24:05
谢谢!
...全文
279 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
cpluser 2003-06-11
  • 打赏
  • 举报
回复
up
cpluser 2003-06-11
  • 打赏
  • 举报
回复
谢谢楼上各位,特别是 kingcom_xu(我们去倒分吧,倒个MVP玩玩)
kingcom_xu 2003-06-11
  • 打赏
  • 举报
回复
上面的源文件中#include "bksms.h"可删去,另在你的工程中加入三张ID分别为
IDB_KCB_DOWN IDB_KCB_NORMAL IDB_KCB_OVER 的位图
kingcom_xu 2003-06-11
  • 打赏
  • 举报
回复
//cpp

// KComboBox.cpp : implementation file
//

#include "stdafx.h"
#include "bksms.h"
#include "KComboBox.h"

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

/////////////////////////////////////////////////////////////////////////////
// CKComboBox

CKComboBox::CKComboBox()
{
m_bLBtnDown = FALSE;
m_bOver=FALSE;
m_nOffset= ::GetSystemMetrics(SM_CXHTHUMB);
}

CKComboBox::~CKComboBox()
{
}


BEGIN_MESSAGE_MAP(CKComboBox, CComboBox)
//{{AFX_MSG_MAP(CKComboBox)
// NOTE - the ClassWizard will add and remove mapping macros here.
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_PAINT()

ON_WM_MOUSEMOVE()
ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CKComboBox message handlers
void CKComboBox::OnLButtonDown(UINT nFlags, CPoint point)
{
CRect rcItem,rcBt;
GetClientRect(&rcItem);
rcBt.left=rcItem.right-m_nOffset-2;
rcBt.top=rcItem.top+2;
rcBt.bottom=rcItem.bottom-2;
rcBt.right=rcItem.right-2;
if(rcBt.PtInRect(point)){
m_bLBtnDown = TRUE;
Invalidate();
}

CComboBox::OnLButtonDown(nFlags, point);
}

void CKComboBox::OnLButtonUp(UINT nFlags, CPoint point)
{
m_bLBtnDown = FALSE;
Invalidate();
CComboBox::OnLButtonUp(nFlags, point);
}



void CKComboBox::OnPaint()
{
Default();
DrawCombo();
}

void CKComboBox::DrawCombo()
{
CRect rcItem,rcBt;

GetClientRect(&rcItem);
rcBt.left=rcItem.right-m_nOffset-2;
rcBt.top=rcItem.top+2;
rcBt.bottom=rcItem.bottom-2;
rcBt.right=rcItem.right-2;

CDC* pDC = GetDC();
pDC->Draw3dRect(&rcItem,RGB(123,125,123),RGB(123,125,123));
rcItem.DeflateRect(1,1);
pDC->Draw3dRect(&rcItem,RGB(255,255,255),RGB(255,255,255));

CDC memdc;
CBitmap bt;



memdc.CreateCompatibleDC(pDC);
if(m_bLBtnDown){
bt.LoadBitmap(IDB_KCB_DOWN);
}else{
bt.LoadBitmap(IDB_KCB_NORMAL);
}
if(m_bOver&&!m_bLBtnDown){
if(bt.m_hObject){
bt.DeleteObject();
}
bt.LoadBitmap(IDB_KCB_OVER);
}
BITMAP bm;
bt.GetObject(sizeof(bm),&bm);

CBitmap* poldbmp=memdc.SelectObject(&bt);
pDC->StretchBlt(rcBt.left,rcBt.top,2,rcBt.Height(),&memdc,0,0,2,bm.bmHeight,SRCCOPY);
pDC->StretchBlt(rcBt.left+2,rcBt.top,rcBt.Width()-13,rcBt.Height(),&memdc,2,0,1,bm.bmHeight,SRCCOPY);
pDC->StretchBlt(rcBt.right-13,rcBt.top,13,rcBt.Height(),&memdc,3,0,13,bm.bmHeight,SRCCOPY);
memdc.SelectObject(poldbmp);

ReleaseDC(pDC);
}

void CKComboBox::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (!m_bOver)
{

CRect rcItem,rcBt;
GetClientRect(&rcItem);
rcBt.left=rcItem.right-m_nOffset-2;
rcBt.top=rcItem.top+2;
rcBt.bottom=rcItem.bottom-2;
rcBt.right=rcItem.right-2;
if(rcBt.PtInRect(point)){
m_bOver =TRUE;
//鼠标在按钮上
m_bOver =TRUE;
//重绘按钮
InvalidateRect(NULL,FALSE);
//跟踪鼠标以得到鼠标离开的消息
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(tme);
tme.hwndTrack = m_hWnd;
tme.dwFlags = TME_LEAVE | TME_HOVER;
tme.dwHoverTime = 1;
_TrackMouseEvent(&tme);
}


}

CComboBox::OnMouseMove(nFlags, point);
}

LRESULT CKComboBox::OnMouseLeave(WPARAM wParam, LPARAM lParam)
{
m_bOver = FALSE;
InvalidateRect(NULL, FALSE);
return 0;
}
kingcom_xu 2003-06-11
  • 打赏
  • 举报
回复
从ccombobox派生一个新类,重载onpaint等消息


//下面是头文件
#if !defined(AFX_KCOMBOBOX_H__F8184796_125E_423A_86CD_BBFECA54E459__INCLUDED_)
#define AFX_KCOMBOBOX_H__F8184796_125E_423A_86CD_BBFECA54E459__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// KComboBox.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CKComboBox window
#define IDB_KCB_DOWN 216
#define IDB_KCB_NORMAL 217
#define IDB_KCB_OVER 218

class CKComboBox : public CComboBox
{
// Construction
public:
CKComboBox();

// Attributes
protected:
int m_nOffset; // offset used during paint.
BOOL m_bLBtnDown; // TRUE if left mouse button is pressed
BOOL m_bOver;
// Operations
protected:
void DrawCombo();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CKComboBox)
//}}AFX_VIRTUAL

// Implementation
public:
virtual ~CKComboBox();

// Generated message map functions
protected:
//{{AFX_MSG(CKComboBox)
// NOTE - the ClassWizard will add and remove member functions here.
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnPaint();

afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg LRESULT OnMouseLeave(WPARAM wParam, LPARAM lParam);
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_KCOMBOBOX_H__F8184796_125E_423A_86CD_BBFECA54E459__INCLUDED_)
cheng_young 2003-06-11
  • 打赏
  • 举报
回复
DrawFrameControl
zwvista 2003-06-11
  • 打赏
  • 举报
回复
CBitmap bitmap
bitmap.LoadOEMBitmap(OBM_COMBO)
cpluser 2003-06-11
  • 打赏
  • 举报
回复
没人知道吗?

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧