社区
界面
帖子详情
自绘的CComboBox,怎样绘制右边有三角符号的下拉按钮?
cpluser
2003-06-11 11:24:05
谢谢!
...全文
279
8
打赏
收藏
自绘的CComboBox,怎样绘制右边有三角符号的下拉按钮?
谢谢!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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
打赏
举报
回复
没人知道吗?
Visual C++ 编程资源大全(源码 控件)
这个类已经替你做好了,它可是有正常、平面、下推几种风格的,快使用它吧(25KB)<END><br>4,TransBut.zip 实现背景透明的
按钮
类(306KB)<END><br>5,AviButton.zip 这个类库可以在
按钮
上显示AVI动画,很酷的(68KB...
Mobile开发之路_之小总结 好呀!!!!!!!!!
1,从那种基本类中继承的函数 变异时都会自动被调用 2,void *memset(void *s,int c,size_t n) 总的作用:将已开辟内存...//把ID_EDITSXM这个控件和字符串 ID_EDITSXM映射起来
下拉
菜单 D
演练VC中的COMMON一族(转贴)之三
6.3.7 工具条的消息映射技巧 如果工具条上的
按钮
都存在对应的菜单命令,那么可以直接利用类向导ClassWizard 进行命令消息的映射,否则必须通过手工的方法来进行命令
按钮
的消息映射。由于同一工具栏的命令
按钮
都存在...
VC常用控件用法(转载)
1.表头控制 Header Control 2.图像列表控制 Image List 3.列表控制和视 List Control&List View 4.树控制和视 Tree Control&Tree View 5....旋转
按钮
控制 Spin Button Control 10.状态条控制 Statu
Visual Studio 2012 - Visual C++ MFC 类
实现有一个值的动画对象功能。 CAnimationVariable 类 表示动画变量。 CAnimationVariableChangeHandler 类 实现回调,它在动画变量值更改时由动画 API 调用。 ...
界面
15,979
社区成员
115,896
社区内容
发帖
与我相关
我的任务
界面
VC/MFC 界面
复制链接
扫一扫
分享
社区描述
VC/MFC 界面
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章