void CRoundButton2::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); ASSERT (pDC != NULL); // Should Buttons be generated? bool bGenerate = !m_rBtnSize.EqualRect(&lpDrawItemStruct->rcItem) || m_bRedraw; // If Rectangles of Button are not the same if (bGenerate) { // Generate Bitmap to hold Buttons GenButtonBMPs(pDC, lpDrawItemStruct->rcItem); // Redraw done m_bRedraw = false; } // Generate DC to draw in Memory CDC *MemDC = new CDC(); MemDC->CreateCompatibleDC(pDC); HGDIOBJ hOldBmp = MemDC->SelectObject(m_tBmpBtn); CString sActualCaption; // Get actual caption GetWindowText(sActualCaption); // Check, if caption has changed if (sActualCaption != m_sOldCaption) bGenerate = true; // Store old caption m_sOldCaption = sActualCaption; // If Rectangles of Button are not the same if (bGenerate) { // Draw Buttons DrawButtonFace(MemDC); // Draw Button-Caption DrawButtonCaption(MemDC); } int nButtonState; nButtonState = BS_ENABLED; if (m_bIsHotButton && m_bMouseOnButton) nButtonState = BS_HOT; if ((lpDrawItemStruct->itemState & ODS_DISABLED) == ODS_DISABLED) nButtonState = BS_DISABLED; else { if ((lpDrawItemStruct->itemState & ODS_SELECTED) == ODS_SELECTED) nButtonState = BS_PRESSED; else { if (this->m_bIsChecked) { nButtonState = BS_CLICKED; } } } CBitmap bitmap2; bitmap2.LoadBitmap(IDB_BITMAP1); BITMAP bmpInfo; bitmap2.GetBitmap(&bmpInfo); CBitmap* pOldBitmap = MemDC->SelectObject(&bitmap2); //int nX = m_rBtnSize.left + (m_rBtnSize.Width() - bmpInfo.bmWidth) / 2; //int nY = m_rBtnSize.top + (m_rBtnSize.Height() - bmpInfo.bmHeight) / 2; // Copy correct Bitmap to Screen for ( int i = 0 ; i<117 ; i++) { MemDC->SelectObject(bitmap2); pDC->BitBlt(0+i,0,bmpInfo.bmWidth,bmpInfo.bmHeight, MemDC,0, 0, SRCCOPY); //MemDC->SelectObject(hOldBmp); MemDC->SelectObject(pOldBitmap); } UINT state = lpDrawItemStruct->itemState; //Get state of the button if ( (state & ODS_SELECTED) ) // If it is pressed pDC->DrawEdge(m_rBtnSize,EDGE_SUNKEN,BF_RECT); // Draw a sunken face }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)