ImageVerifierCode 换一换
格式:DOCX , 页数:10 ,大小:17.72KB ,
资源ID:9256268      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/9256268.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(VC++实现工具栏上添加平面组合框控件.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

VC++实现工具栏上添加平面组合框控件.docx

1、VC+实现工具栏上添加平面组合框控件VC+实现工具栏上添加平面组合框控件网站建设-找友创互联 开网店-找友创互联 0元招收代理【CN域名0.5元】 2008年11月13日 社区交流关键字: xcopy AppBuilder CRecordSet FileMapping File Mapping VC+实现工具栏上添加平面组合框控件。 但是仅仅产生平面组合框是不够的,必须实现组合框的消息响应函数,才能方便地运用组合框。在Vsiaul C+中,消息响应函数通常都是用类向导来实现,但是此处由于组合框是用函数创建的,所以必须亲自动手来写代码,也并不麻烦,与类向导生成的代码格式是一样的,可以参照来写。下

2、面代码定义了组合框的选择变化消息响应函数:/BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)/AFX_MSG_MAP(CMainFrame)ON_WM_CREATE()ON_CBN_SELENDOK(ID_TOOL_ZOOM, OnSelectZoomed)/AFX_MSG_MAPEND_MESSAGE_MAP()/afx_msg void OnSelectZoomed();二、编程步骤1、启动Visual C+6.0,生成一个单文档项目,将该项目命名为ToolBar;2、通过资源编辑器新增一个工具按钮,Caption设置为空,ID资源标志符命名为ID_TOOL

3、_ZOOM;3、启动Class Wizard从CToolBar派生一个新类CMainToolBar;4、在MainFrm.h文件中添加#include MainToolBar.h语句,然后找到 CToolBar m_wndToolBar语句,用CMainToolBar代替CToolBar;5、添加代码,编译运行程序。三、程序代码/ FlatComboBox.h : header file#if !defined(FLATCOMBOBOX_H_INCLUDED)#define FLATCOMBOBOX_H_INCLUDED#if _MSC_VER 1000#pragma once#endif /

4、 _MSC_VER 1000#define FC_DRAWNORMAL 0x00000001#define FC_DRAWRAISED 0x00000002#define FC_DRAWPRESSD 0x00000004/ CFlatComboBox windowclass CFlatComboBox : public CComboBox/ Constructionpublic:CFlatComboBox();/ Attributespublic:bool m_bLBtnDown;COLORREF m_clrHilite;COLORREF m_clrShadow;COLORREF m_clrD

5、kShad;COLORREF m_clrButton;/ Operationspublic:void DrawCombo(DWORD dwStyle, COLORREF clrTopLeft,COLORREF clrBottomRight);int Offset();/ Overrides/ ClassWizard generated virtual function overrides/AFX_VIRTUAL(CFlatComboBox)/AFX_VIRTUAL/ Implementationpublic:virtual CFlatComboBox();/ Generated message

6、 map functionsprotected:/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_MSGDECLARE_MESSAGE_MAP();#endif

7、 / !defined(FLATCOMBOBOX_H_INCLUDED)/#include stdafx.h#include FlatComboBox.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/ CFlatComboBoxCFlatComboBox:CFlatComboBox()m_bLBtnDown = false;CFlatComboBox:CFlatComboBox()BEGIN_MESSAGE_MAP(CFlatComboBox, CComboBox)

8、/AFX_MSG_MAP(CFlatComboBox)ON_WM_MOUSEMOVE()ON_WM_LBUTTONDOWN()ON_WM_LBUTTONUP()ON_WM_TIMER()ON_WM_PAINT()/AFX_MSG_MAPEND_MESSAGE_MAP()/ CFlatComboBox message handlersvoid CFlatComboBox:OnMouseMove(UINT nFlags, CPoint point)SetTimer(1,10,NULL);CComboBox:OnMouseMove(nFlags, point);void CFlatComboBox:

9、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 r

10、cItem;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.Pt

11、InRect(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), :GetSysCol

12、or(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* p

13、DC = 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(COLO

14、R_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_BT

15、NFACE),: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),:Ge

16、tSysColor(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

17、_BTNSHADOW),:GetSysColor(COLOR_BTNHIGHLIGHT);break;ReleaseDC(pDC);int CFlatComboBox:Offset()/ Thanks to Todd Brannam for this suggestion.return :GetSystemMetrics(SM_CXHTHUMB);/ MainToolBar.h: interface for the CMainToolBar class.#if !defined(AFX_MAINTOOLBAR_H_76CF28F4_005F_11D7_8F58_00E04C0BECE6_INC

18、LUDED_)#define AFX_MAINTOOLBAR_H_76CF28F4_005F_11D7_8F58_00E04C0BECE6_INCLUDED_#if _MSC_VER 1000#pragma once#endif / _MSC_VER 1000#include FlatComboBox.hclass CMainToolBar : public CToolBarpublic:CMainToolBar();virtual CMainToolBar();public:CFlatComboBox m_wndZoom;#endif/ MainToolBar.cpp: implementa

19、tion of the CMainToolBar class.#include stdafx.h#include ToolBar.h#include MainToolBar.h#ifdef _DEBUG#undef THIS_FILEstatic char THIS_FILE=_FILE_;#define new DEBUG_NEW#endifCMainToolBar:CMainToolBar()CMainToolBar:CMainToolBar()/int CMainFrame:OnCreate(LPCREATESTRUCT lpCreateStruct)if (CFrameWnd:OnCr

20、eate(lpCreateStruct) = -1)return -1;if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE |CBRS_TOP| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY |CBRS_SIZE_DYNAMIC) |!m_wndToolBar.LoadToolBar(IDR_MAINFRAME)TRACE0(Failed to create toolbarn);return -1; / fail to createif (!m_wndStatusBar.

21、Create(this) | !m_wndStatusBar.SetIndicators(indicators,sizeof(indicators)/sizeof(UINT)TRACE0(Failed to create status barn);return -1; / fail to create/ TODO: Delete these three lines if you dont want the toolbar to be dockablem_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);EnableDocking(CBRS_ALIGN_ANY);

22、DockControlBar(&m_wndToolBar);int index = 0;RECT rect;/找到指定的工具项while(m_wndToolBar.GetItemID(index)!=ID_TOOL_ZOOM)index+;/设置指定工具项的宽度并获取新的区域 80是宽度m_wndToolBar.SetButtonInfo(index, ID_TOOL_ZOOM, TBBS_SEPARATOR, 80);m_wndToolBar.GetItemRect(index, &rect);/设置位置rect.top+=2;rect.bottom += 200;/ 创建并显示if (!m

23、_wndToolBar.m_wndZoom.Create(WS_CHILD|WS_VISIBLE |CBS_AUTOHSCROLL|CBS_DROPDOWNLIST |CBS_HASSTRINGS ,rect, &m_wndToolBar, ID_TOOL_ZOOM)TRACE0(Failed to create combo-boxn);return FALSE;m_wndToolBar.m_wndZoom.ShowWindow(SW_SHOW);/填充内容m_wndToolBar.m_wndZoom.AddString(25%);m_wndToolBar.m_wndZoom.AddStrin

24、g(50%);m_wndToolBar.m_wndZoom.AddString(75%);m_wndToolBar.m_wndZoom.AddString(100%);m_wndToolBar.m_wndZoom.AddString(125%);m_wndToolBar.m_wndZoom.AddString(150%);m_wndToolBar.m_wndZoom.AddString(175%);m_wndToolBar.m_wndZoom.AddString(200%);m_wndToolBar.m_wndZoom.SetCurSel(3);return 0;void CMainFrame:OnSelectZoomed()CString strContent;m_wndToolBar.m_wndZoom.GetWindowText(strContent);AfxMessageBox(strContent);四、小结为了实现OFFICE2000风格的工具条,本实例介了一种比较巧妙的方法,利用Visual C+6.0已有的开发环境支持,在工具条中加入了平面组合框控件,并实现了组合框的消息响应,用户选择组合框中的某一项后,会弹出一个对话框,提示用户所选择的信息。

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1