资源简介
该资源在VS2008SP1 IDE中编写,主要介绍了如何在VC++中实现复选下拉框,其中包含了CheckComboBox.h和CheckComboBox.cpp两个文件,这两个文件实现了复选下拉框的功能。但作者Margin在使用复选下拉框时发现:在模态对话框中使用时存在一个难以解决问题,多次进入模态子对话框时,复选下拉框将无法正常选择。为解决此问题,作者Margin发现采用非模态子对话框就不会出现上述情况。该资源能帮助你在VC++中正确使用复选下拉框(CCheckComboBox)。

代码片段和文件信息
// CheckComboBox.cpp
//
// Written by Magnus Egelberg (magnus.egelberg@lundalogik.se)
//
// Copyright (C) 1999 Lundalogik AB Sweden. All rights reserved.
//
//
#include “stdafx.h“
#include “CheckComboBox.h“
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static WNDPROC m_pWndProc = 0;
static CCheckComboBox *m_pComboBox = 0;
BEGIN_MESSAGE_MAP(CCheckComboBox CComboBox)
//{{AFX_MSG_MAP(CCheckComboBox)
ON_MESSAGE(WM_CTLCOLORLISTBOX OnCtlColorListBox)
ON_MESSAGE(WM_GETTEXT OnGetText)
ON_MESSAGE(WM_GETTEXTLENGTH OnGetTextLength)
ON_CONTROL_REFLECT(CBN_DROPDOWN ondropDown)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//
// The subclassed COMBOLBOX message handler
//
extern “C“ LRESULT FAR PASCAL ComboBoxListBoxProc(HWND hWnd UINT nMsg WPARAM wParam LPARAM lParam)
{
switch (nMsg) {
case WM_RBUTTONDOWN: {
// If you want to select all/unselect all using the
// right button remove this ifdef. Personally I don‘t really like it
#if FALSE
if (m_pComboBox != 0) {
INT nCount = m_pComboBox->GetCount();
INT nSelCount = 0;
for (INT i = 0; i < nCount; i++) {
if (m_pComboBox->GetCheck(i))
nSelCount++;
}
m_pComboBox->SelectAll(nSelCount != nCount);
// Make sure to invalidate this window as well
InvalidateRect(hWnd 0 FALSE);
m_pComboBox->GetParent()->SendMessage(WM_COMMAND MAKELONG(GetWindowLong(m_pComboBox->m_hWnd GWL_ID) CBN_SELCHANGE) (LPARAM)m_pComboBox->m_hWnd);
}
#endif
break;
}
// Make the combobox always return -1 as the current selection. This
// causes the lpDrawItemStruct->itemID in DrawItem() to be -1
// when the always-visible-portion of the combo is drawn
case LB_GETCURSEL: {
return -1;
}
case WM_CHAR: {
if (wParam == VK_SPACE) {
// Get the current selection
INT nIndex = CallWindowProcA(m_pWndProc hWnd LB_GETCURSEL wParam lParam);
CRect rcItem;
SendMessage(hWnd LB_GETITEMRECT nIndex (LONG)(VOID *)&rcItem);
InvalidateRect(hWnd rcItem FALSE);
// Invert the check mark
m_pComboBox->SetCheck(nIndex !m_pComboBox->GetCheck(nIndex));
// Notify that selection has changed
m_pComboBox->GetParent()->SendMessage(WM_COMMAND MAKELONG(GetWindowLong(m_pComboBox->m_hWnd GWL_ID) CBN_SELCHANGE) (LPARAM)m_pComboBox->m_hWnd);
return 0;
}
break;
}
case WM_LBUTTONDOWN: {
CRect rcClient;
GetClientRect(hWnd rcClient);
CPoint pt;
pt.x = LOWORD(lParam);
pt.y = HIWORD(lParam);
if (PtInRect(rcClient pt)) {
INT nItemHeight = SendMessage(hWnd LB_GETITEMHEIGHT 0 0);
INT nTopIndex = SendMessage(hWnd LB_GETTOPINDEX 0 0);
// Compute which index to check/uncheck
INT nIndex = nTopIndex + pt.y / nItemHeight;
CRect rcItem;
SendMessage(hWnd LB_GETITEMRECT nIndex (LONG)(VOID
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 9894 2012-10-24 17:35 Point29\CheckComboBox.cpp
文件 1800 2012-10-24 17:35 Point29\CheckComboBox.h
文件 105968 2012-10-29 13:56 Point29\Point29.aps
文件 1666 2012-10-29 11:27 Point29\Point29.cpp
文件 451 2012-10-29 11:27 Point29\Point29.h
文件 6409 2012-10-29 13:56 Point29\Point29.rc
文件 879 2012-10-29 11:27 Point29\Point29.sln
..A..H. 20992 2012-10-29 14:34 Point29\Point29.suo
文件 5866 2012-10-29 13:28 Point29\Point29.vcproj
文件 3621 2012-10-29 14:26 Point29\Point29Dlg.cpp
文件 783 2012-10-29 13:44 Point29\Point29Dlg.h
文件 2869 2012-10-29 11:27 Point29\ReadMe.txt
文件 67777 2007-11-28 16:21 Point29\res\Point29.ico
文件 363 2012-10-29 11:27 Point29\res\Point29.rc2
文件 907 2012-10-29 13:42 Point29\resource.h
文件 140 2012-10-29 11:27 Point29\stdafx.cpp
文件 1854 2012-10-29 11:27 Point29\stdafx.h
文件 1019 2012-10-29 13:45 Point29\SubDlg1.cpp
文件 532 2012-10-29 13:45 Point29\SubDlg1.h
文件 1019 2012-10-29 13:59 Point29\SubDlg2.cpp
文件 530 2012-10-29 13:45 Point29\SubDlg2.h
文件 1030 2012-10-29 11:27 Point29\targetver.h
目录 0 2012-10-29 14:35 Point29\res
目录 0 2012-10-29 14:35 Point29
----------- --------- ---------- ----- ----
236369 24
- 上一篇:操作系统课程设计(银行家算法)附报告
- 下一篇:C语言彩票管理系统
相关资源
- VC++ 多线程文件读写操作
- 移木块游戏,可以自编自玩,vc6.0编写
- VC++MFC小游戏实例教程(实例)+MFC类库
- VC++实现CMD命令执行与获得返回信息
- VC++基于OpenGL模拟的一个3维空间模型
- 基于VC++的SolidWorks二次开发SolidWorks
- 派克变换VC++源码(附文档)
- VC++ 串口
- VC++ 大富翁4_大富翁游戏源码
- VC++ 摄像头视频采集与回放源程序
- 转 VC++ 实现电子邮件(Email)发送
- 基于MFC的VC++仿QQ浏览器源码(雏形)
- VC++ 服务程序编写及安装与卸载
- VC++6.0番茄西红柿VAXvirsual assist X完美破
- 基于改进的fcm算法的图像分割vc++
- VC++6.0 绿色版,免安装,非常好用。
- Microsoft Visual C++ 2005 Redistributable Pack
- VC++MFC课程设计的学生成绩管理系统
- 大智慧365DLL插件设计
- VC++6.0汉化包
- VC++完整商业界面源码(再上传)
- VC++编程技术600个大型项目源码.rar
- VC++实现RSA加密算法
- VC++ 中国象棋经典游戏源代码
- 郁金香VC++游戏辅助视频教程
- C语言进阶源码---基于graphics实现图书
- 摄影测量相对定向VC++程序
- VC++数字图像处理典型算法及实现
- VC++酒店客房管理系统 MFC
- 车站计算机联锁vc++6.0程序代码
评论
共有 条评论