CColorComboBox
Mike -- MREAMS@cerner.com Friday, December 06, 1996 Environment: VC 4.0, Win95 I am trying to create a custom CComboBox that will show: text,forecolor, and backcolor in both the list portion and the edit portion. So far I have run into one problem and one potential problem. Problem 1: When I use the CBS_DROPDOWN property the list works fine, my items show up with the correct text and colors, however if I use the CBS_DROPDOWNLIST (the style that I want to use) I blow up in the DrawItem Function. The problem is that the lpDIS->itemData is nowhere near the value that I pass it and consequently the pointer I'm trying to cast to it is invalid. Again, this only happens when the CBS_DROPDOWNLIST style is in effect. (I have tried it with both CBS_HASSTRINGS on and off) int CClrComboBox::AddColorString(LPCTSTR lpszString,COLORREF bcr,COLORREF fcr) { CCB_DATA *data = new CCB_DATA; data->lpszString = lpszString; data->bcr = bcr; data->fcr = fcr; return AddString((LPCTSTR)data); } void CClrComboBox::DrawItem(LPDRAWITEMSTRUCT lpDIS) { CDC* pDC = CDC::FromHandle(lpDIS->hDC); COLORREF cr; CString text; CCB_DATA *tmpItem; tmpItem = (CCB_DATA*)lpDIS->itemData; cr = tmpItem->bcr; ... Problem 2: I am wondering what is involved in custom painting the Edit portion of the ComboBox. I had assumed that the dropdown button was non-client but when I overrode OnPaint() the whole edit box disappeared. Do I need to repaint the arrow and handle the dropdown in OnClick or is there an easier way to customize the Edit portion? Thanks, Michael P. Reams (Mike) Cerner Corporation 2900 Rockcreek Parkway Kansas City, MO 64117-2551 (816) 472-1024 Ext. 2138 (816) 221-1024 Fax mreams@cerner.com http://www.cerner.com "To Automate the Process of Managing Health"
Paul.B.Folbrecht@JCI.Com Wednesday, December 11, 1996 #1- Sometimes you get -1 for lpDIS->itemData. You need to check for that. #2- No, you don't need to repaint the arrow, or anything NC. The following code does what you want, I believe: void CGXColorCombo::DrawItem( LPDRAWITEMSTRUCT pDIS ) { CDC* pDC = CDC::FromHandle( pDIS->hDC ); CRect oRect = pDIS->rcItem; COLORREF oClr = (COLORREF) pDIS->itemData; // Draw a colored rect. if ( (int) pDIS->itemID != -1 ) { short nSave = pDC->SaveDC(); CPen oPen; CBrush oBrush; oPen.CreatePen( PS_SOLID, 1, oClr ); oBrush.CreateSolidBrush( oClr ); pDC->SelectObject( &oPen ); pDC->SelectObject( &oBrush ); pDC->Rectangle( oRect ); pDC->RestoreDC( nSave ); } if ( ( pDIS->itemState & ODS_SELECTED ) && ( pDIS->itemAction & ( ODA_SELECT | ODA_DRAWENTIRE ) ) ) { // Item has been selected - hilite frame. COLORREF crHilite = RGB( 0, 0, 0 ); CBrush oBrush( crHilite ); pDC->FrameRect( oRect, &oBrush ); } if ( !( pDIS->itemState & ODS_SELECTED ) && ( pDIS->itemAction & ODA_SELECT ) ) { // Item has been de-selected- remove frame. COLORREF crHilite = RGB( 255, 255, 255 ); CBrush oBrush( crHilite ); pDC->FrameRect( oRect, &oBrush ); } } ______________________________ Reply Separator _________________________________ Subject: CColorComboBox Author: MREAMS@cerner.com at Mailhub Date: 12/9/96 5:26 PM Environment: VC 4.0, Win95 I am trying to create a custom CComboBox that will show: text,forecolor, and backcolor in both the list portion and the edit portion. So far I have run into one problem and one potential problem. Problem 1: When I use the CBS_DROPDOWN property the list works fine, my items show up with the correct text and colors, however if I use the CBS_DROPDOWNLIST (the style that I want to use) I blow up in the DrawItem Function. The problem is that the lpDIS->itemData is nowhere near the value that I pass it and consequently the pointer I'm trying to cast to it is invalid. Again, this only happens when the CBS_DROPDOWNLIST style is in effect. (I have tried it with both CBS_HASSTRINGS on and off) int CClrComboBox::AddColorString(LPCTSTR lpszString,COLORREF bcr,COLORREF fcr) { CCB_DATA *data = new CCB_DATA; data->lpszString = lpszString; data->bcr = bcr; data->fcr = fcr; return AddString((LPCTSTR)data); } void CClrComboBox::DrawItem(LPDRAWITEMSTRUCT lpDIS) { CDC* pDC = CDC::FromHandle(lpDIS->hDC); COLORREF cr; CString text; CCB_DATA *tmpItem; tmpItem = (CCB_DATA*)lpDIS->itemData; cr = tmpItem->bcr; ... Problem 2: I am wondering what is involved in custom painting the Edit portion of the ComboBox. I had assumed that the dropdown button was non-client but when I overrode OnPaint() the whole edit box disappeared. Do I need to repaint the arrow and handle the dropdown in OnClick or is there an easier way to customize the Edit portion? Thanks, Michael P. Reams (Mike) Cerner Corporation 2900 Rockcreek Parkway Kansas City, MO 64117-2551 (816) 472-1024 Ext. 2138 (816) 221-1024 Fax mreams@cerner.com http://www.cerner.com "To Automate the Process of Managing Health"
| Вернуться в корень Архива |