⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 combogridctrl.cpp

📁 SQLBig5BugTool 宽字符操作问题
💻 CPP
字号:
// ComboGridCtrl.cpp: implementation of the CComboGridCtrl class.
//
// This is a demo of how to override CGridCtrl in order to offer
// other editing capabilities such as a drop down list
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ComboGridCtrl.h"
#include "InPlaceList.h"
#include <algorithm>

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

BEGIN_MESSAGE_MAP(CComboGridCtrl, CGridCtrl)
    //{{AFX_MSG_MAP(CComboGridCtrl)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()


//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CComboGridCtrl::CComboGridCtrl()
{
	m_comboBoxStyle=CBS_DROPDOWN;

	m_pIComboGridCtrlCB=0;
}

CComboGridCtrl::~CComboGridCtrl()
{
}

//////////////////////////////////////////////////////////////////////
// Overrides modified by huangjianxiong at 2003-5-17
//////////////////////////////////////////////////////////////////////

void CComboGridCtrl::CreateInPlaceEditControl(CRect& rect, DWORD dwStyle, UINT nID,
                                              int nRow, int nCol,
                                              LPCTSTR szText, int nChar)
{
	BOOL bComboCol=IsColumnCombo(nCol);

	// InPlaceList and auto-deletes itself
	if(bComboCol)
	{
		CStringArray saComboStrList;
		if(m_pIComboGridCtrlCB)
		{
			m_pIComboGridCtrlCB->GetComboStrList(this,nRow,nCol,saComboStrList);
		}
		new CInPlaceList(this, rect,
                     //CBS_DROPDOWNLIST,    // Uncomment for dropdown list style
                     m_comboBoxStyle,          // Uncomment for dropdown style
                     //CBS_SIMPLE,          // Uncomment for simple style
                     nID,                   // ID of control being created
                     nRow, nCol, 
                     saComboStrList, szText, nChar);
	}
	else
	{
		CGridCtrl::CreateInPlaceEditControl(rect,dwStyle,nID,nRow,nCol,szText,nChar);
	}
}

//****************************************************************
//	function:make a specified column can be edit by combo select
//	param: 1 int iCol[in]: specify the column
//		   2 CArrayString & comStr[in]:string list
//	return:	BOOL bSuccess
//*****************************************************************
BOOL CComboGridCtrl::AddComboColumn(int iCol)
{
	if(iCol<GetFixedColumnCount()) 
		return FALSE;
	
	m_ComboColIndexList.push_back(iCol);
	return TRUE;
}

BOOL CComboGridCtrl::SetItemText(int nRow, int nCol, LPCTSTR str)
{	
	if(IsColumnCombo(nCol)&&(nRow>=GetFixedRowCount()))
	{
		CStringArray saComboStrList;
		if(m_pIComboGridCtrlCB)
		{
			m_pIComboGridCtrlCB->GetComboStrList(this,nRow,nCol,saComboStrList);
		}
		
		for(int i=0;i<saComboStrList.GetSize();i++)
		{
			if(saComboStrList.GetAt(i)==str)
			{
				return CGridCtrl::SetItemText(nRow,nCol,str);
			}
		}
		return FALSE;
	}
	else
	{		
		return CGridCtrl::SetItemText(nRow,nCol,str);
	}
}

BOOL CComboGridCtrl::IsColumnCombo(const int nCol)
{
	return (m_ComboColIndexList.end()!=std::find(m_ComboColIndexList.begin(),m_ComboColIndexList.end(),nCol));
}

BOOL CComboGridCtrl::SetItem(GV_ITEM *pItem)
{
   if (!pItem) 
        return FALSE;
    CGridCell* pCell = GetCell(pItem->row, pItem->col);
    if (!pCell) 
        return FALSE;

    if (pItem->mask & GVIF_TEXT)  
	{		
		BOOL bFind=FALSE;
		if(IsColumnCombo(pItem->col))
		{
			if(pItem->row<GetFixedRowCount())
			{
				bFind=TRUE;
			}
			else
			{
				CStringArray saComboStrList;
				if(m_pIComboGridCtrlCB)
				{
					m_pIComboGridCtrlCB->GetComboStrList(this,pItem->row, pItem->col,saComboStrList);
				}

				for(int i=0;i<saComboStrList.GetSize();i++)
				{
					if(saComboStrList.GetAt(i)==pItem->szText)
					{
						bFind=TRUE;
					}
				}
			}
			if(!bFind)
			{
				return FALSE;
			}
		}

		pCell->szText=pItem->szText;			
	}
    if (pItem->mask & GVIF_PARAM)  pCell->lParam  = pItem->lParam;
    if (pItem->mask & GVIF_IMAGE)  pCell->iImage  = pItem->iImage;
    if (pItem->mask & GVIF_STATE)  pCell->state   = pItem->state;
    if (pItem->mask & GVIF_FORMAT) pCell->nFormat = pItem->nFormat;
    if (pItem->mask & GVIF_BKCLR)  pCell->crBkClr = pItem->crBkClr;
    if (pItem->mask & GVIF_FGCLR)  pCell->crFgClr = pItem->crFgClr;
    if (pItem->mask & GVIF_FONT)   memcpy(&(pCell->lfFont), &(pItem->lfFont), sizeof(LOGFONT));

    return TRUE;
}

//********************************************************
//	set combobox style
//********************************************************
void CComboGridCtrl::SetComboBoxStyle(DWORD dwStyle)
{
	m_comboBoxStyle=dwStyle;
}

void CComboGridCtrl::SetIComboGridCtrlCB(IComboGridCtrlCB *pIComboGridCtrlCB)
{
	m_pIComboGridCtrlCB=pIComboGridCtrlCB;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -