// // By adding this message handler, we may use CWnd::GetText() // LRESULT CCheckComboBox::OnGetText(WPARAM wParam, LPARAM lParam) { // Make sure the text is updated RecalcText(); if (lParam == 0) return 0; // Copy the 'fake' window text lstrcpyn((LPTSTR)lParam, m_strText, (INT)wParam); return m_strText.GetLength(); }
LRESULT CCheckComboBox::OnGetText(WPARAM wParam, LPARAM lParam) { RecalcText(); if (lParam == 0) return 0; lstrcpyn((LPSTR)lParam, m_strText, (INT)wParam); return m_strText.GetLength(); }
// // By adding this message handler, we may use CWnd::GetTextLength() // LRESULT CCheckComboBox::OnGetTextLength(WPARAM, LPARAM) { // Make sure the text is updated RecalcText(); return m_strText.GetLength(); }
void CCheckComboBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { HDC dc = lpDrawItemStruct->hDC; CRect rcBitmap = lpDrawItemStruct->rcItem; CRect rcText = lpDrawItemStruct->rcItem; CString strText; // 0 - No check, 1 - Empty check, 2 - Checked INT nCheck = 0; // Check if we are drawing the static portion of the combobox if ((UINT(-1)) == lpDrawItemStruct->itemID || NULL == m_hListBox) { // Make sure the m_strText member is updated RecalcText(); // Get the text strText = m_strText; // Don't draw any boxes on this item nCheck = 0; } // Otherwise it is one of the items else { GetLBText(lpDrawItemStruct->itemID, strText); nCheck = 1 + (GetCheck(lpDrawItemStruct->itemID)); TEXTMETRIC metrics = { 0 }; GetTextMetrics(dc, &metrics); rcBitmap.left = 0; rcBitmap.right = rcBitmap.left + metrics.tmHeight + metrics.tmExternalLeading + 6; rcBitmap.top += 1; rcBitmap.bottom -= 1; rcText.left = rcBitmap.right; } if (nCheck > 0) { SetBkColor(dc, GetSysColor(COLOR_WINDOW)); SetTextColor(dc, GetSysColor(COLOR_WINDOWTEXT)); UINT nState = DFCS_BUTTONCHECK; if (nCheck > 1) { nState |= DFCS_CHECKED; } // Draw the checkmark using DrawFrameControl DrawFrameControl(dc, rcBitmap, DFC_BUTTON, nState); } if (lpDrawItemStruct->itemState & ODS_SELECTED) { SetBkColor(dc, GetSysColor(COLOR_HIGHLIGHT)); SetTextColor(dc, GetSysColor(COLOR_HIGHLIGHTTEXT)); } else { SetBkColor(dc, GetSysColor(COLOR_WINDOW)); SetTextColor(dc, GetSysColor(COLOR_WINDOWTEXT)); } // Erase and draw ExtTextOut(dc, 0, 0, ETO_OPAQUE, &rcText, 0, 0, 0); DrawText(dc, ' ' + strText, strText.GetLength() + 1, &rcText, DT_SINGLELINE|DT_VCENTER|DT_END_ELLIPSIS); if ((lpDrawItemStruct->itemState & (ODS_FOCUS|ODS_SELECTED)) == (ODS_FOCUS|ODS_SELECTED)) DrawFocusRect(dc, &rcText); }
LRESULT CCheckComboBox::OnGetTextLength(WPARAM, LPARAM) { RecalcText(); return m_strText.GetLength(); }
void CCheckComboBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { HDC dc = lpDrawItemStruct->hDC; CRect rcBitmap = lpDrawItemStruct->rcItem; CRect rcText = lpDrawItemStruct->rcItem; CString strText; INT nCheck = 0; if ((LONG)lpDrawItemStruct->itemID < 0) { RecalcText(); strText = m_strText; nCheck = 0; } else { GetLBText(lpDrawItemStruct->itemID, strText); nCheck = 1 + (GetItemData(lpDrawItemStruct->itemID) != 0); TEXTMETRIC metrics; GetTextMetrics(dc, &metrics); rcBitmap.left = 0; rcBitmap.right = rcBitmap.left + metrics.tmHeight + metrics.tmExternalLeading + 6; rcBitmap.top += 1; rcBitmap.bottom -= 1; rcText.left = rcBitmap.right; } if (nCheck > 0) { SetBkColor(dc, GetSysColor(COLOR_WINDOW)); SetTextColor(dc, GetSysColor(COLOR_WINDOWTEXT)); UINT nState = DFCS_BUTTONCHECK; if (nCheck > 1) nState |= DFCS_CHECKED; DrawFrameControl(dc, rcBitmap, DFC_BUTTON, nState); } if (lpDrawItemStruct->itemState & ODS_SELECTED) { SetBkColor(dc, GetSysColor(COLOR_HIGHLIGHT)); SetTextColor(dc, GetSysColor(COLOR_HIGHLIGHTTEXT)); } else { SetBkColor(dc, GetSysColor(COLOR_WINDOW)); SetTextColor(dc, GetSysColor(COLOR_WINDOWTEXT)); } ExtTextOut(dc, 0, 0, ETO_OPAQUE, &rcText, 0, 0, 0); DrawText(dc, ' ' + strText, strText.GetLength() + 1, &rcText, DT_SINGLELINE|DT_VCENTER|DT_END_ELLIPSIS); if ((lpDrawItemStruct->itemState & (ODS_FOCUS|ODS_SELECTED)) == (ODS_FOCUS|ODS_SELECTED)) DrawFocusRect(dc, &rcText); }