void COptionTreeImagePopUp::OnPaint() { // Make sure options aren't NULL if (m_otImageOption == NULL) { return; } // Declare variables CPaintDC dc(this); CDC* pDCMem = new CDC; CBitmap bpMem; CBitmap *bmOld; CRect rcClient, rcButton, rcImage; COLORREF crOld; HGDIOBJ hOldBrush; HGDIOBJ hOld; int nOldBack; // Get client rectangle GetClientRect(rcClient); // Create DC pDCMem->CreateCompatibleDC(&dc); // Create bitmap bpMem.CreateCompatibleBitmap(&dc, rcClient.Width(), rcClient.Height()); // Select bitmap bmOld = pDCMem->SelectObject(&bpMem); // Set background mode nOldBack = pDCMem->SetBkMode(TRANSPARENT); // Set text color crOld = pDCMem->SetTextColor(GetSysColor(COLOR_WINDOWTEXT)); // Select font hOld = pDCMem->SelectObject(m_otImageOption->GetNormalFont()); // Select brush hOldBrush = pDCMem->SelectObject(GetSysColorBrush(COLOR_BTNFACE)); // Fill background pDCMem->PatBlt(rcClient.left, rcClient.top, rcClient.right, rcClient.bottom, PATCOPY); // Go through all images for (int i = 0; i < m_pImageList->GetImageCount(); i++) { // -- Get rectangle rcImage = m_rcRectangles.GetAt(i); // -- Button // -- -- Hover if (rcImage.PtInRect(m_pHover) == TRUE) { rcButton = rcImage; rcButton.InflateRect(3, 3, 3, 3); pDCMem->DrawEdge(rcButton, BDR_RAISEDINNER, BF_RECT); } // -- -- Selected else if (m_nSelected == i) { rcButton = rcImage; rcButton.InflateRect(3, 3, 3, 3); for (long i = rcButton.top; i < rcButton.bottom; i++) { _DrawSelectRect(pDCMem->GetSafeHdc(), rcButton.left, i, rcButton.Width()); } pDCMem->DrawEdge(rcButton, BDR_SUNKENOUTER, BF_RECT); } // -- Draw image m_pImageList->Draw(pDCMem, i, CPoint(rcImage.left, rcImage.top), ILD_NORMAL); } // Draw text if (m_pImageList->GetImageCount() == 0) { pDCMem->DrawText(_T("No Images."), rcClient, DT_SINGLELINE | DT_CENTER | DT_VCENTER); } // Draw edge pDCMem->DrawEdge(rcClient, EDGE_RAISED, BF_RECT); // Copy to screen dc.BitBlt(0, 0, rcClient.Width(), rcClient.Height(), pDCMem, 0, 0, SRCCOPY); // Restore GDI ojects pDCMem->SelectObject(bmOld); pDCMem->SelectObject(hOldBrush); pDCMem->SetBkMode(nOldBack); pDCMem->SelectObject(hOld); pDCMem->SetTextColor(crOld); // Delete objects if (pDCMem->GetSafeHdc() != NULL) { pDCMem->DeleteDC(); } delete pDCMem; if (bpMem.GetSafeHandle() != NULL) { bpMem.DeleteObject(); } }
void COptionTreeColorPopUp::DrawCell(CDC* pDC, int nIndex) { // For the Custom Text area if (m_strCustomText.GetLength() && nIndex == OT_COLOR_CUSTOMBOXVALUE) { // -- The extent of the actual text button CRect rcTextButton = m_rcCustomTextRect; rcTextButton.top += 2 * m_nMargin; // -- Fill background pDC->FillSolidRect(rcTextButton, ::GetSysColor(COLOR_3DFACE)); // -- Draw horizontal line pDC->FillSolidRect(m_rcCustomTextRect.left + 2 * m_nMargin, m_rcCustomTextRect.top, m_rcCustomTextRect.Width()-4*m_nMargin, 1, ::GetSysColor(COLOR_3DSHADOW)); pDC->FillSolidRect(m_rcCustomTextRect.left + 2 * m_nMargin, m_rcCustomTextRect.top + 1, m_rcCustomTextRect.Width()-4*m_nMargin, 1, ::GetSysColor(COLOR_3DHILIGHT)); rcTextButton.DeflateRect(1,1); // -- Fill background if (m_nChosenColorSel == nIndex && m_nCurrentSel != nIndex) { pDC->FillSolidRect(rcTextButton, ::GetSysColor(COLOR_3DLIGHT)); } else { pDC->FillSolidRect(rcTextButton, ::GetSysColor(COLOR_3DFACE)); } // -- Draw button if (m_nCurrentSel == nIndex) { pDC->DrawEdge(rcTextButton, BDR_RAISEDINNER, BF_RECT); } // -- Draw custom text CFont *pOldFont = (CFont*) pDC->SelectObject(&m_fFont); int nOldBack = pDC->SetBkMode(TRANSPARENT); pDC->DrawText(m_strCustomText, rcTextButton, DT_CENTER | DT_VCENTER | DT_SINGLELINE); // -- Restore pDC->SelectObject(pOldFont); pDC->SetBkMode(nOldBack); return; } // For the Default Text area if (m_strDefaultText.GetLength() && nIndex == OT_COLOR_DEFAULTBOXVALUE) { // -- Fill background pDC->FillSolidRect(m_rcDefaultTextRect, ::GetSysColor(COLOR_3DFACE)); // -- The extent of the actual text button CRect rcTextButton = m_rcDefaultTextRect; rcTextButton.DeflateRect(1,1); // -- Fill background if (m_nChosenColorSel == nIndex && m_nCurrentSel != nIndex) { for (long i = rcTextButton.top; i < rcTextButton.bottom; i++) { _DrawSelectRect(pDC->GetSafeHdc(), rcTextButton.left, i, rcTextButton.Width()); } } else { pDC->FillSolidRect(rcTextButton, ::GetSysColor(COLOR_3DFACE)); } // -- Draw thin line around text CRect rcLineRect = rcTextButton; CPen pen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW)); CPen* pOldPen = pDC->SelectObject(&pen); // -- Calculate the rectangle rcLineRect.left += 3; rcLineRect.right -= 3; rcLineRect.top += 2; rcLineRect.bottom -= 3; // -- Restore pDC->SelectStockObject(NULL_BRUSH); pDC->Rectangle(rcLineRect); pDC->SelectObject(pOldPen); if (pen.GetSafeHandle() != NULL) { pen.DeleteObject(); } // -- Draw button if (m_nCurrentSel == nIndex) { pDC->DrawEdge(rcTextButton, BDR_RAISEDINNER, BF_RECT); } else if (m_nChosenColorSel == nIndex) { pDC->DrawEdge(rcTextButton, BDR_SUNKENOUTER, BF_RECT); } // -- Draw custom text CFont *pOldFont = (CFont*) pDC->SelectObject(&m_fFont); int nOldBack = pDC->SetBkMode(TRANSPARENT); pDC->DrawText(m_strDefaultText, rcTextButton, DT_CENTER | DT_VCENTER | DT_SINGLELINE); // -- Restore pDC->SelectObject(pOldFont); pDC->SetBkMode(nOldBack); // -- Select and realize the palette CPalette* pOldPalette = NULL; if (pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE) { pOldPalette = pDC->SelectPalette(&m_plPalette, FALSE); pDC->RealizePalette(); } // -- Draw sample cell of default color CRect rcSample; rcSample.left = rcLineRect.left; rcSample.right = rcSample.left + m_nBoxSize; rcSample.top = rcLineRect.top; rcSample.bottom = rcLineRect.top + m_nBoxSize; rcSample.DeflateRect(m_nMargin + 1, m_nMargin + 1); // -- Create objects CBrush brush(PALETTERGB(GetRValue(m_crDefault), GetGValue(m_crDefault), GetBValue(m_crDefault))); CPen penSample; penSample.CreatePen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW)); CBrush* pOldBrush = (CBrush*) pDC->SelectObject(&brush); CPen* pOldSamplePen = (CPen*) pDC->SelectObject(&penSample); // Draw the cell color pDC->Rectangle(rcSample); // Restore pDC->SelectObject(pOldBrush); pDC->SelectObject(pOldSamplePen); if (brush.GetSafeHandle() != NULL) { brush.DeleteObject(); } if (penSample.GetSafeHandle() != NULL) { penSample.DeleteObject(); } if (pOldPalette && pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE) { pDC->SelectPalette(pOldPalette, FALSE); } return; } // Declare variables CRect rcCell; if (!GetCellRect(nIndex, rcCell)) { return; } // -- Select and realize the palette CPalette* pOldPalette = NULL; if (pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE) { pOldPalette = pDC->SelectPalette(&m_plPalette, FALSE); pDC->RealizePalette(); } // -- Fill background if (m_nChosenColorSel == nIndex && m_nCurrentSel != nIndex) { for (long i = rcCell.top; i < rcCell.bottom; i++) { _DrawSelectRect(pDC->GetSafeHdc(), rcCell.left, i, rcCell.Width()); } } else { pDC->FillSolidRect(rcCell, ::GetSysColor(COLOR_3DFACE)); } // Draw button if (m_nCurrentSel == nIndex) { pDC->DrawEdge(rcCell, BDR_RAISEDINNER, BF_RECT); } else if (m_nChosenColorSel == nIndex) { pDC->DrawEdge(rcCell, BDR_SUNKENOUTER, BF_RECT); } // Create objects CBrush brush(PALETTERGB(GetRValue(GetColor(nIndex)), GetGValue(GetColor(nIndex)), GetBValue(GetColor(nIndex)))); CPen pen; pen.CreatePen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW)); CBrush* pOldBrush = (CBrush*) pDC->SelectObject(&brush); CPen* pOldPen = (CPen*) pDC->SelectObject(&pen); // Draw the cell color rcCell.DeflateRect(m_nMargin + 1, m_nMargin + 1); pDC->Rectangle(rcCell); // Restore pDC->SelectObject(pOldBrush); pDC->SelectObject(pOldPen); if (brush.GetSafeHandle() != NULL) { brush.DeleteObject(); } if (pen.GetSafeHandle() != NULL) { pen.DeleteObject(); } if (pOldPalette && pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE) { pDC->SelectPalette(pOldPalette, FALSE); } }