LRESULT CDocList::OnDrawItem(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { UINT idCtl = wParam; LPDRAWITEMSTRUCT lpDraw = (LPDRAWITEMSTRUCT)lParam; if (!lpDraw || idCtl != IDC_NEWDOC_LIST) return S_OK; if (lpDraw->itemID < 0 || lpDraw->itemID >= MAX_ITEMS) return S_OK; bool bGrayed = !!((lpDraw->itemState & (ODS_GRAYED | ODS_DISABLED))); bool bHilighted = !!((lpDraw->itemState & (ODS_SELECTED | ODS_CHECKED)) && !bGrayed); bool bFocus = !!((lpDraw->itemState & (ODS_FOCUS)) && !bGrayed); int idIcon = m_idIcons[lpDraw->itemID]; bool bEnabled = m_bIconsEnabled[lpDraw->itemID]; char szString[MAX_PATH]; SendMessage(LB_GETTEXT, lpDraw->itemID, (LPARAM)szString); // Draw the background FillRect(lpDraw->hDC, &lpDraw->rcItem, CAGBrush(COLOR_WINDOW, eSystem)); // Draw the icon RECT rect = lpDraw->rcItem; InflateRect(&rect, -4, -2); HICON hIcon = ::LoadIcon(_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(idIcon)); ::DrawIconEx(lpDraw->hDC, rect.left, rect.top, hIcon, 0/*cxWidth*/, 0/*cyWidth*/, 0/*istepIfAniCur*/, NULL/*hbrFlickerFreeDraw*/, DI_NORMAL); ::DeleteObject(hIcon); // Draw the text int iOldMode = ::SetBkMode(lpDraw->hDC, TRANSPARENT ); COLORREF lOldColor = ::SetTextColor(lpDraw->hDC, (bEnabled ? ::GetSysColor(COLOR_WINDOWTEXT) : GetSysColor(COLOR_BTNSHADOW))); rect.left += (ITEM_HEIGHT+2); ::DrawText(lpDraw->hDC, szString, lstrlen(szString), &rect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_NOPREFIX); ::SetBkMode(lpDraw->hDC, iOldMode); ::SetTextColor(lpDraw->hDC, lOldColor); // Draw the selection rectangle if (bHilighted) { if (bEnabled) ::FrameRect(lpDraw->hDC, &lpDraw->rcItem, CAGBrush(BLACK_BRUSH, eStock)); else int a = 0; } return S_OK; }
LRESULT CColorCombo::OnDrawItem(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { UINT idControl = wParam; LPDRAWITEMSTRUCT pDrawItem = (LPDRAWITEMSTRUCT)lParam; if (!pDrawItem) return false; RECT rect = pDrawItem->rcItem; CAGBrush Brush(GetBkColor(pDrawItem->hDC)); ::FillRect(pDrawItem->hDC, &rect, Brush); ::InflateRect(&rect, -2, -1); COLORREF Color = RGB(255,255,255); if ((int)pDrawItem->itemID != -1) Color = (COLORREF)GetItemData(pDrawItem->itemID); if (Color == CLR_NONE || Color == CLR_DEFAULT) { HFONT hFont = (HFONT)::GetStockObject(ANSI_VAR_FONT); HFONT hOldFont = (HFONT)::SelectObject(pDrawItem->hDC, hFont); LPCSTR strText = (Color == CLR_NONE ? "Custom..." : "Off"); ::ExtTextOut(pDrawItem->hDC, rect.left, rect.top, ETO_CLIPPED | ETO_OPAQUE, &rect, strText, lstrlen(strText), NULL); ::SelectObject(pDrawItem->hDC, hOldFont); } else { ::FillRect(pDrawItem->hDC, &rect, CAGBrush(Color)); bool bDropDownItem = !(pDrawItem->itemState & ODS_COMBOBOXEDIT); if (bDropDownItem) { LPCSTR szColorName = GetColorName(Color); if (szColorName) { HFONT hFont = (HFONT)::GetStockObject(ANSI_VAR_FONT); HFONT hOldFont = (HFONT)::SelectObject(pDrawItem->hDC, hFont); int iOldMode = ::SetBkMode(pDrawItem->hDC, TRANSPARENT); int iGray = (299 * GetRValue(Color)) + (587 * GetGValue(Color)) + (114 * GetBValue(Color)); // NTSC conversion COLORREF TextColor = (iGray >= 127500 ? RGB(0,0,0) : RGB(255,255,255)); COLORREF lOldColor = ::SetTextColor(pDrawItem->hDC, TextColor); rect.left += 2; ::DrawText(pDrawItem->hDC, szColorName, lstrlen(szColorName), &rect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_NOPREFIX); rect.left -= 2; ::SetTextColor(pDrawItem->hDC, lOldColor); ::SetBkMode(pDrawItem->hDC, iOldMode); ::SelectObject(pDrawItem->hDC, hOldFont); } } } if (pDrawItem->itemState & ODS_FOCUS || pDrawItem->itemState & ODS_SELECTED) { ::FrameRect(pDrawItem->hDC, &rect, Brush); ::InflateRect(&rect, +1, +1); ::DrawFocusRect(pDrawItem->hDC, &rect); } return 0; }
LRESULT CToolsCtlPanel::OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { HDC hDC = (HDC)wParam; if (!hDC) { bHandled = false; return S_OK; } CImage Image(_AtlBaseModule.GetResourceInstance(), IDB_TOOLPANEL_AG, "GIF"); HBITMAP hBitmap = Image.GetBitmapHandle(); if (!hBitmap) { bHandled = false; return S_OK; } HDC hMemDC = ::CreateCompatibleDC(hDC); HBITMAP hOldBitmap = (HBITMAP)::SelectObject(hMemDC, hBitmap); BITMAP bm; ::GetObject(hBitmap, sizeof(bm), &bm); RECT rect; ::GetClientRect(m_hWnd, &rect); ::FillRect(hDC, &rect, CAGBrush(WHITE_BRUSH, eStock)); int dx1 = bm.bmWidth / 2; int dx2 = bm.bmWidth - dx1; for (int x=0; x < WIDTH(rect); x += dx2) ::BitBlt(hDC, x, 0, dx2, bm.bmHeight, hMemDC, dx2, 0, SRCCOPY); // Paint the ends PaintLeftEdge(hDC, dx1, bm.bmHeight, hMemDC); ::SelectObject(hMemDC, hOldBitmap); ::DeleteDC(hMemDC); return S_OK; }
LRESULT CPagePanel::OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { HDC hDC = (HDC)wParam; if (!hDC) { bHandled = false; return S_OK; } if (m_hBitmap) { CImage Image(_AtlBaseModule.GetResourceInstance(), (m_pCtp->IsHpUI() ? IDB_CTLPANELBG_HP : IDR_NAVTOOLBAR_BG), "GIF"); m_hBitmap = Image.GetBitmapHandle(true/*bTakeOver*/); } if (!m_hBitmap) { bHandled = false; return S_OK; } HDC hMemDC = ::CreateCompatibleDC(hDC); HBITMAP hOldBitmap = (HBITMAP)::SelectObject(hMemDC, m_hBitmap); BITMAP bm; ::GetObject(m_hBitmap, sizeof(bm), &bm); RECT rect; ::GetClientRect(m_hWnd, &rect); ::FillRect(hDC, &rect, CAGBrush(WHITE_BRUSH, eStock)); ::BitBlt(hDC, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY); ::SelectObject(hMemDC, hOldBitmap); ::DeleteDC(hMemDC); return S_OK; }
void CPictureListView::DrawListViewThumbnails() { // Set the length of the space between thumbnails // You can also calculate and set it based on the length of your list control // Hold the window update to avoid flicking SetRedraw(FALSE); // Reset the image list for (int i=0; i<m_ImageList.GetImageCount(); i++) m_ImageList.Remove(i); // Remove all items from list view if (GetItemCount()) DeleteAllItems(); // Draw the thumbnails i = 0; for (int nIndex = 0; nIndex < MAX_NUM_PICTURES; nIndex++) { CAGSymImage* pImage = m_pParent->GetEnvelopeWizard()->m_pGraphics[nIndex]; if (!pImage) continue; BITMAPINFOHEADER* pDib = pImage->GetDib(); if (!pDib) continue; // Borrow our dib header to create our thumbnail bitmap int nWidth = pDib->biWidth; int nHeight = pDib->biHeight; pDib->biWidth = m_nThumbnailSize; pDib->biHeight = m_nThumbnailSize; // Create thumbnail bitmap section HBITMAP hBitmap = ::CreateDIBSection(NULL, (BITMAPINFO*)pDib, DIB_RGB_COLORS, NULL, NULL, 0); // Restore the dib header pDib->biWidth = nWidth; pDib->biHeight = nHeight; // Select the thumbnail bitmap into screen dc HDC hMemDC = ::CreateCompatibleDC(NULL); HGDIOBJ hOldObj = ::SelectObject(hMemDC, hBitmap); // Set stretch mode ::SetStretchBltMode(hMemDC, COLORONCOLOR); int dx = m_nThumbnailSize; int dy = m_nThumbnailSize; ScaleToFit(&dx, &dy, nWidth, nHeight, true/*bUseSmallerFactor*/); // Populate the thumbnail bitmap bits RECT rect = {0, 0, m_nThumbnailSize, m_nThumbnailSize}; ::FillRect(hMemDC, &rect, CAGBrush(RGB(255,255,255))); ::StretchDIBits(hMemDC, (m_nThumbnailSize - dx)/2, (m_nThumbnailSize - dy)/2, dx, dy, 0, 0, nWidth, nHeight, DibPtr(pDib), (BITMAPINFO*)pDib, DIB_RGB_COLORS, SRCCOPY); // Restore DC object ::SelectObject(hMemDC, hOldObj); // Clean up ::DeleteObject(hMemDC); // Add the bitmap to our image list m_ImageList.Add(hBitmap); // Set the image file name as item text InsertItem(i, "", i); // Get the current item position POINT pt; GetItemPosition(i, &pt); // Shift the thumbnail to desired position pt.x = 0; pt.y = i * m_nThumbnailSize; SetItemPosition(i, pt); i++; } // Show the new thumbnails //j Arrange(LVA_ALIGNLEFT); SetRedraw(TRUE); }
LRESULT CDocWindow::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { PAINTSTRUCT PaintStruct; HDC hPaintDC = ::BeginPaint(m_hWnd, &PaintStruct); if (!hPaintDC) return E_FAIL; if (!m_pClientDC || m_ImageArray.GetSize() <= 0) { ::FillRect(hPaintDC, &PaintStruct.rcPaint, CAGBrush(BACKGOUND_COLOR)); // Draw the text int iOldMode = ::SetBkMode(hPaintDC, TRANSPARENT); COLORREF lOldColor = ::SetTextColor(hPaintDC, RGB(0,0,0)); //j ::GetSysColor(COLOR_WINDOWTEXT) CRect rect; GetClientRect(&rect); CString strVersion; strVersion.Format(IDS_PROJNAME); strVersion += " "; strVersion += VER_PRODUCT_VERSION_STR; ::DrawText(hPaintDC, strVersion, lstrlen(strVersion), &rect, DT_RIGHT|DT_BOTTOM|DT_SINGLELINE|DT_NOPREFIX); ::DrawText(hPaintDC, m_strBackgroundMessage, lstrlen(m_strBackgroundMessage), &rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_NOPREFIX); ::SetBkMode(hPaintDC, iOldMode); ::SetTextColor(hPaintDC, lOldColor); ::EndPaint(m_hWnd, &PaintStruct); return E_FAIL; } // If the off-screen is 'dirty', redraw the page into it if (m_pClientDC->GetDirty()) { HDC hDC = m_pClientDC->GetHDC(); // Draw the document background and 'furniture' { // Calculate the border rectangle CRect rPageView = m_PageViewRect; rPageView.InflateRect(1, 1); // Add the border pixel // Before drawing anything, open up the offscreen clipping to include a border pixel and drop shadow HRGN hClipRegion = m_pClientDC->SaveClipRegion(); CRect rClipRect = rPageView; rClipRect.right += m_ShadowSize.cx; // Add the drop shadow rClipRect.bottom += m_ShadowSize.cy; m_pClientDC->SetClipRect(rClipRect); // Draw the page background and the border pixel ::FillRect(hDC, &rPageView, CAGBrush(WHITE_BRUSH, eStock)); ::FrameRect(hDC, &rPageView, CAGBrush(192,192,192)); // Light gray // Draw the drop shadow on the right CRect r( rPageView.right, rPageView.top + m_ShadowSize.cy, rPageView.right + m_ShadowSize.cx, rPageView.bottom + m_ShadowSize.cy); ::FillRect(hDC, &r, CAGBrush(LTGRAY_BRUSH, eStock)); // Draw the drop shadow on the bottom r.SetRect( rPageView.left + m_ShadowSize.cx, rPageView.bottom, rPageView.right + m_ShadowSize.cx, rPageView.bottom + m_ShadowSize.cy); ::FillRect(hDC, &r, CAGBrush(LTGRAY_BRUSH, eStock)); m_pClientDC->RestoreClipRegion(hClipRegion); } // Draw all the images for (int i = 0; i < m_ImageArray.GetSize(); i++) m_ImageArray[i]->Draw(*m_pClientDC, 0); // See if the selected object wants the event m_Select.Paint(hDC); // Draw the grid CSize PageSize(m_PageRect.Width(), m_PageRect.Height()); m_Grid.Draw(hDC, m_pClientDC->GetViewToDeviceMatrix(), PageSize); m_pClientDC->SetDirty(false); } // Blt from the offscreen to the screen m_pClientDC->Blt(hPaintDC, PaintStruct.rcPaint); ::EndPaint(m_hWnd, &PaintStruct); return S_OK; }