BCGSuite下拉AddOption时候鼠标呈漏斗中,状态忙 - 小众知识

BCGSuite下拉AddOption时候鼠标呈漏斗中,状态忙

2015-11-02 10:37:03 苏内容
  标签: BCG/Option/鼠标
阅读:4805
MFC中,

使用bcg grid控件,添加下拉菜单

pGridItem->AddOption(L"Narrow Sector");
pGridItem->AddOption(L"Wider Sector");

下拉菜单的时候,鼠标变为漏斗型,请问怎么回事?

还有,怎么把下拉的菜单项变为不可修改,也就是说只能选择不能修改,


 使用AllowEdit(False) 不行,因为它使得我选择也不能了


自己扩展一个item类.

class CListComboItem : public CBCGPGridItem{
public:
CListComboItem(const _variant_t varValue, CStringList* plstNames = NULL);
protected:
virtual CWnd* CreateInPlaceEdit (CRect rectEdit, BOOL& bDefaultFormat);
virtual CComboBox* CreateCombo (CWnd* pWndParent, CRect rect);
virtual void OnDrawValue (CDC* pDC, CRect rect);

CStringList m_lstNames;
int m_nSelectedItem;
CString m_strVal;
};

/////////////////////////////////////////////////////////////////////////////
// CListCombo window

class CListCombo : public CComboBox{
// Construction
public:
CListCombo(CStringList& lstNames);
CListComboItem* GetListItem(){
return m_pListItem;
}
void SetIconListItem(CListComboItem* pListItem){
m_pListItem=pListItem;
}

// Attributes
protected:
CStringList& m_lstNames;
CListComboItem* m_pListItem;

// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CListCombo)
//}}AFX_VIRTUAL

// Implementation
public:
virtual ~CListCombo();

// Generated message map functions
protected:
//{{AFX_MSG(CListCombo)
afx_msg void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);
afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct);
afx_msg void OnCbnSelchange();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
// CIconListItem class
CListComboItem::CListComboItem(const _variant_t varValue, CStringList* plstNames) : CBCGPGridItem(varValue){
if (plstNames != NULL){
m_lstNames.AddTail(plstNames);
}
POSITION pos = m_lstNames.GetHeadPosition();
for (int i = 0; i < m_lstNames.GetCount(); i++){
AddOption (m_lstNames.GetNext(pos));
}

AllowEdit (1);
}

CComboBox* CListComboItem::CreateCombo(CWnd* pWndParent, CRect rect){
rect.bottom = rect.top + 400;
CListCombo* pWndCombo = new CListCombo(m_lstNames);
if (!pWndCombo->Create (WS_CHILD | CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST | WS_VSCROLL | CBS_OWNERDRAWFIXED | CBS_HASSTRINGS,rect, pWndParent, BCGPROPLIST_ID_INPLACE)){
delete pWndCombo;
return NULL;
}
pWndCombo->SetIconListItem(this);
return pWndCombo;
}

void CListComboItem::OnDrawValue(CDC* pDC, CRect rect){
CBCGPGridCtrl* pGridCtrl = GetOwnerList();
ASSERT_VALID (pGridCtrl);
ASSERT_VALID (pDC);

CString strVal = (LPCTSTR)(_bstr_t) m_varValue;
if (strVal.IsEmpty () || m_lstNames.GetCount () == 0){return;}

int nIndex = -1;
#if _MSC_VER < 1400
_stscanf (strVal, _T("%d"), &nIndex);
#else
_stscanf_s (strVal, _T("%d"), &nIndex);
#endif
if (nIndex < 0){
return;
}

if (!m_lstNames.IsEmpty()){
CFont* pOldFont = pDC->SelectObject(pGridCtrl->GetFont());
CString str = m_lstNames.GetAt(m_lstNames.FindIndex(nIndex));
pDC->DrawText(str, rect, DT_SINGLELINE | DT_VCENTER);
pDC->SelectObject(pOldFont);
}
m_bValueIsTrancated = FALSE;
}

CWnd* CListComboItem::CreateInPlaceEdit(CRect rectEdit, BOOL& bDefaultFormat){
CWnd* pWnd = CBCGPGridItem::CreateInPlaceEdit(rectEdit, bDefaultFormat);
if (pWnd != NULL){
pWnd->ShowWindow(SW_HIDE);
}
return pWnd;
}

/////////////////////////////////////////////////////////////////////////////
// CListCombo

CListCombo::CListCombo(CStringList& lstNames) :m_lstNames (lstNames){
}

CListCombo::~CListCombo(){
}

BEGIN_MESSAGE_MAP(CListCombo, CComboBox)
//{{AFX_MSG_MAP(CListCombo)
ON_WM_DRAWITEM()
ON_WM_MEASUREITEM()
//}}AFX_MSG_MAP
ON_CONTROL_REFLECT(CBN_SELCHANGE, OnCbnSelchange)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CIconCombo message handlers

void CListCombo::OnDrawItem(int /*nIDCtl*/, LPDRAWITEMSTRUCT lpDIS){
CDC* pDC = CDC::FromHandle(lpDIS->hDC);
ASSERT_VALID(pDC);

CRect rect = lpDIS->rcItem;
int nIcon = lpDIS->itemID;

HBRUSH brBackground;
COLORREF clText;

if (lpDIS->itemState & ODS_SELECTED){
brBackground = globalData.brHilite;
clText = globalData.clrTextHilite;
}else{
brBackground = globalData.brWindow; 
clText = globalData.clrWindowText;
}

if (lpDIS->itemAction & (ODA_DRAWENTIRE | ODA_SELECT)){
::FillRect (lpDIS->hDC, &rect, brBackground);
}

if (nIcon < 0){
return;
}

if (!m_lstNames.IsEmpty()){
CString str = m_lstNames.GetAt(m_lstNames.FindIndex(nIcon));
CFont* pOldFont = pDC->SelectObject (&globalData.fontRegular);

pDC->SetBkMode (TRANSPARENT);
pDC->SetTextColor (clText);
pDC->DrawText (str, rect, DT_SINGLELINE | DT_VCENTER);
pDC->SelectObject (pOldFont);
}
}

void CListCombo::OnMeasureItem(int /*nIDCtl*/, LPMEASUREITEMSTRUCT lpMeasureItemStruct){
int nTextWidth = 0;
int nTextHeight = 0;

if (!m_lstNames.IsEmpty()){
nTextHeight = globalData.GetTextHeight();

CClientDC dc (this);
CFont* pOldFont = dc.SelectObject (&globalData.fontRegular);

for (POSITION pos = m_lstNames.GetHeadPosition(); pos != NULL;){
CString str = m_lstNames.GetNext (pos);
nTextWidth = max(nTextWidth, dc.GetTextExtent(str).cx + 2);
}

dc.SelectObject (pOldFont);
}

lpMeasureItemStruct->itemWidth = nTextWidth;
lpMeasureItemStruct->itemHeight = nTextHeight;
}
//*****************************************************************************************
void CListCombo::OnCbnSelchange(){
m_pListItem->SetValue(GetCurSel());

}

CStringList lstDataTypes;
lstDataTypes.AddTail(_T("BIT"));
lstDataTypes.AddTail(_T("BYTE"));
lstDataTypes.AddTail(_T("WORD"));
lstDataTypes.AddTail(_T("DWORD"));
pRow->ReplaceItem (3, new CListComboItem(-1, &lstDataTypes));

直接扣来的.应该没问题.
扩展阅读
相关阅读
© CopyRight 2010-2021, PREDREAM.ORG, Inc.All Rights Reserved. 京ICP备13045924号-1