Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » CExtComboBox DrawItem() Collapse All
Subject Author Date
John Ritzenthaler Jan 28, 2009 - 2:20 PM

I’m using a class derived from CExtComboBox in a toolbar with Owner drawing.  When the list is initially dropped, all rows are blank.  as you move the mouse down over the list, the rows are drawn correctly.  It works fine when derived from CComboBox.  Here’s the DrawItem logic()


 void CRXComboMeas::DrawItem(LPDRAWITEMSTRUCT lpDraw)

{

 COLORREF   crBkgrd;

 COLORREF   crText;

 CDC*    pDC   = CDC::FromHandle(lpDraw->hDC);


 if (m_nItemHt < 0)

  SizeCalc();

 if (lpDraw->itemState & ODS_SELECTED)

 {

  crBkgrd = GetSysColor(COLOR_HIGHLIGHT);

  crText = GetSysColor(COLOR_HIGHLIGHTTEXT);

 }

 else

 {

  crBkgrd = GetSysColor(COLOR_WINDOW);

  crText = GetSysColor(COLOR_WINDOWTEXT);

 }

 pDC->FillSolidRect(&lpDraw->rcItem, crBkgrd);

 TRACE(_T("itemdata=0x%lx\n"), (long)lpDraw->itemData);

 if ((lpDraw->itemData != -1) && (lpDraw->itemData != 0))

 {

  RECT    rectQty  = lpDraw->rcItem;

  RECT    rectDesc = lpDraw->rcItem;

  CString    strQty;

  CRVwDoxTko*   pTko  = m_pBarTko->DoxTkoMeasGet();

  const CRVwMeasInfo* pMeasInfo = (const CRVwMeasInfo*)(lpDraw->itemData);


  pDC->SetTextColor(crText);

  rectQty.right = rectQty.left + m_nMeasWd;

  rectDesc.left = rectQty.right + 8;

  pMeasInfo->TkoQtyFmtGet(pTko, &strQty);

  pDC->DrawText(strQty, -1, &rectQty, DT_RIGHT|DT_SINGLELINE|DT_VCENTER);

  pDC->DrawText(pMeasInfo->DescGet(), -1, &rectDesc,

   DT_LEFT|DT_NOPREFIX|DT_SINGLELINE|DT_VCENTER);

 }

 if (lpDraw->itemState & ODS_FOCUS)

  pDC->DrawFocusRect(&lpDraw->rcItem);

}


The TRACE() shows that lpDraw->itemData is passed as zero, so nothing is drawn.  As I move the cursor down the list, itemData is passed with the correct value and the display is correct.  The static display (when the list isn’t shown) is fine.


I load up the Combo well before the list is exposed.   


 

Technical Support Jan 29, 2009 - 12:44 PM

Thank you for reporting the very interesting issue. To fix it please update the source code for the following method:

LRESULT CExtComboBoxPopupListBox::WindowProc( UINT message, WPARAM wParam, LPARAM lParam )
{
            switch( message )
            {
            case (WM_USER+555):
                        MoveWindow( &m_rcWndRestore );
            return 0L;
            case WM_PRINT:
            case WM_PRINTCLIENT:
                        if( m_bFirstActivationInvocation )
                        {
                                    m_bFirstActivationInvocation = false;
                                    if( ! m_bSimpleModeComboBox )
                                    {
                                                GetWindowRect( &m_rcWndRestore );
                                                MoveWindow( -32000, -32000, 0, 0 );
                                                PostMessage( (WM_USER+555) );
                                    }
                        }
                        if( ! m_bSimpleModeComboBox )
                                    return 0L;
            break;
            case WM_ERASEBKGND:
            if(         (GetStyle() & LBS_OWNERDRAWFIXED) != 0 
                        ||           (GetStyle() & LBS_OWNERDRAWVARIABLE) != 0 
                        )
                        return TRUE;
            break;
            case WM_PAINT:
            if(         (GetStyle() & LBS_OWNERDRAWFIXED) != 0 
                        ||           (GetStyle() & LBS_OWNERDRAWVARIABLE) != 0 
                        )
            {
                        CPaintDC dcPaint( this );
                        CRect rcClient;
                        GetClientRect( &rcClient );
                        CExtMemoryDC dc(
                                    &dcPaint,
                                    &rcClient
                                    );
                        dc.FillSolidRect(
                                    &rcClient,
                                    m_pCB->PmBridge_GetPM()->GetColor( COLOR_WINDOW, this )
                                    );

                        CFont * pFont = GetFont();
                        ASSERT( pFont != NULL );
                        CFont * pOldFont = dc.SelectObject( pFont );

                        INT nCount = m_pCB->GetCount();
                        INT nTopIndex = ((CListBox*)this)->GetTopIndex();
                        for( INT nItem = nTopIndex; nItem < nCount; nItem++ )
                        {
                                    DRAWITEMSTRUCT dis;
                                    ::memset( &dis, 0, sizeof( DRAWITEMSTRUCT ) );
                                    dis.CtlType = ODT_LISTBOX;
                                    dis.CtlID = GetDlgCtrlID();
                                    dis.itemID = nItem;
                                    dis.hDC = dc.GetSafeHdc();
                                    ((CListBox*)this)->GetItemRect( nItem, &dis.rcItem );
                                    dis.itemAction = ODA_DRAWENTIRE;
                                    dis.hwndItem = GetSafeHwnd();
                                    dis.itemData = m_pCB->GetItemData( nItem );

                                    if( rcClient.bottom < dis.rcItem.top )
                                                break;

                                    if( ((CListBox*)this)->GetSel( nItem ) > 0 )
                                                dis.itemState |= ODS_SELECTED;
                                    if( ((CListBox*)this)->GetCurSel() == nItem )
                                                dis.itemState |= ODS_FOCUS;

                                    m_pCB->SendMessage( 
                                                WM_DRAWITEM, 
                                                (WPARAM)GetDlgCtrlID(), 
                                                (LPARAM)&dis 
                                                );
                        }

                        dc.SelectObject( pOldFont );

                        return TRUE;
            }
            break;
            } // switch( message )
LRESULT lResult = CWnd::WindowProc( message, wParam, lParam );
LONG nFrame = RDW_FRAME;
            switch( message )
            {
            case WM_VSCROLL:
            case WM_HSCROLL:
                        nFrame = 0L;
            case WM_SHOWWINDOW:
            case WM_WINDOWPOSCHANGED:
                        RedrawWindow(
                                    NULL,
                                    NULL,
                                    RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASE|RDW_ERASENOW|nFrame
                                    );
            break;
            } // switch( message )
            return lResult;
}

John Ritzenthaler Jan 29, 2009 - 3:42 PM

That fixed it.  Thanks.