资源简介
基于老外的CheckComboBox,因业务不满足,自己另外修改封装的两个控件。一个可输入,一个不可输入,支持checkAll,显示内容更改等。
代码片段和文件信息
// CheckComboBox.cpp
//
// Written by Magnus Egelberg (magnus.egelberg@lundalogik.se)
//
// Copyright (C) 1999 Lundalogik AB Sweden. All rights reserved.
//
//
#include “stdafx.h“
#include “CheckCombo.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_GETITEMR
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-01-09 15:37 CheckComboBox重绘\
目录 0 2018-01-09 15:36 CheckComboBox重绘\CheckComboBox\
目录 0 2018-01-09 15:37 CheckComboBox重绘\CheckComboBox1\
文件 25672 2017-12-25 16:08 CheckComboBox重绘\CheckComboBox1\CheckComboBox.cpp
文件 2967 2017-10-30 10:11 CheckComboBox重绘\CheckComboBox1\CheckComboBox.h
文件 6513 2018-01-09 15:38 CheckComboBox重绘\CheckComboBox1\截图.jpg
目录 0 2018-01-09 15:40 CheckComboBox重绘\CheckComboBox2\
文件 26637 2017-12-26 18:13 CheckComboBox重绘\CheckComboBox2\CheckComboCtrl.cpp
文件 2882 2017-12-26 18:17 CheckComboBox重绘\CheckComboBox2\CheckComboCtrl.h
文件 7298 2018-01-09 15:39 CheckComboBox重绘\CheckComboBox2\截图.jpg
文件 9920 2017-12-25 14:06 CheckComboBox重绘\CheckComboBox\CheckComboBox.cpp
文件 1800 1999-11-16 13:29 CheckComboBox重绘\CheckComboBox\CheckComboBox.h
文件 11628 2018-01-09 15:34 CheckComboBox重绘\CheckComboBox\截图.jpg
评论
共有 条评论