|
楼主 |
发表于 2018-7-18 08:15
|
显示全部楼层
有人说是重绘(https://bbs.csdn.net/topics/390142177),CC代码如下,不知道对不对,如何改成VBA哈?
- void CShowComboBox::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
- {
- // TODO: Add your code to determine the size of specified item
- lpMeasureItemStruct->itemHeight = CComboBox::GetItemHeight(0);
- }
-
- void CShowComboBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) //combobo
- {
- // TODO: Add your code to draw the specified item
- CDC *pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
- int nSaveDC=pDC->SaveDC();
- CRect itemRect = lpDrawItemStruct->rcItem;
- int nItem = lpDrawItemStruct->itemID;
-
- if(lpDrawItemStruct->itemAction & ODA_DRAWENTIRE)
- {
- DrawItemBk(pDC,itemRect,nItem, CS_NORMAL); //画正常状态item的背景
- DrawItemImage(pDC,itemRect,nItem,GetItemImage(nItem),CS_NORMAL);
- DrawItemText(pDC,itemRect,nItem,CS_NORMAL);//画正常状态item文
-
- if(!GetItemDisable(nItem))
- {
- DrawItemBk(pDC,itemRect,nItem,CS_DISABLED);
- DrawItemImage(pDC,itemRect,nItem,GetItemImage(nItem),CS_DISABLED);
- DrawItemText(pDC,itemRect,nItem,CS_DISABLED);
- }
- }
-
- if((lpDrawItemStruct->itemState & ODS_SELECTED) &&
- (lpDrawItemStruct->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) )
- {
- DrawItemBk(pDC,itemRect,nItem,CS_HOT);
- DrawItemImage(pDC,itemRect,nItem,GetItemImage(nItem),CS_HOT);
- DrawItemText(pDC,itemRect,nItem,CS_HOT);
- }
-
- if(!(lpDrawItemStruct->itemState & ODS_SELECTED) &&
- (lpDrawItemStruct->itemAction & ODA_SELECT ) )
- {
- DrawItemBk(pDC,itemRect,nItem,CS_SELECT);
- DrawItemImage(pDC,itemRect,nItem,GetItemImage(nItem),CS_SELECT);
- DrawItemText(pDC,itemRect,nItem,CS_SELECT);
- }
-
- pDC->RestoreDC(nSaveDC);
- }
-
- void CShowComboBox::OnPaint(),多处理OnPaint主要是处理edit/static的部分,上边的drawitem是只能处理list中的.
- {
- CPaintDC dc(this); // device context for painting
- CRect rectBk;
- GetClientRect(rectBk);
-
- DrawBorder(&dc,rectBk,GetComboState());
- DrawBackGround(&dc,rectBk,GetComboState());
- DrawDownButton(&dc,rectBk,GetComboState()); //与按钮一样,有正常,HOT,按下和非激活状态
-
- if ( CComboBox::GetCount() >0 && CComboBox::GetCurSel() >= 0 )
- {
- int nState = CS_NORMAL;
- int nItem = CComboBox::GetCurSel();
- GetComboState()== CS_SELECT ? nState = CS_DISABLED : nState = CS_NORMAL ;
- CString strItemText = "" ;
- GetLBText(nItem,strItemText);
- DrawItemText(&dc,rectBk,nItem,strItemText,nState);
- DrawItemImage(&dc,rectBk,nItem,GetItemImage(nItem),nState);
- }
- }
复制代码 |
|