一派护法 十九级 |
【补充】 ODA_DRAWENTIRE部分采用GDI+双缓冲后的代码: /* ** Draw the bitmap and text for the list box item. ** Draw a rectangle around the bitmap if it is selected. **/ void Dlg2_DrawItem(HWND hDlg, LPARAM lParam) { LPDRAWITEMSTRUCT lpDis = (LPDRAWITEMSTRUCT)lParam; switch (lpDis->itemAction) { case ODA_SELECT: case ODA_DRAWENTIRE: if (lpDis->itemID != -1) { // Create compatible graphic int width = lpDis->rcItem.right - lpDis->rcItem.left; int height = lpDis->rcItem.bottom - lpDis->rcItem.top; Bitmap bmpMem(width, height); Graphics gpMem(&bmpMem);
// Main Drawing int color; if (lpDis->itemState & ODS_SELECTED) color = COLOR_HIGHLIGHT; // when selected else color = COLOR_WINDOW; // when not selected character.Display(&gpMem, lpDis->itemID, 0, 0, 0, color, ICON_PADDING_H, ICON_PADDING_V);
// Copy to screen Graphics graphics(lpDis->hDC); graphics.DrawImage(&bmpMem, lpDis->rcItem.left, lpDis->rcItem.top, width, height); } // If there are no list box items, skip break; case ODA_FOCUS: DrawFocusRect(lpDis->hDC, &lpDis->rcItem); break; } } 【Character类】 #include "stdafx.h" #include "Character.h"
Character::Character(void) { width = height = 32; }
Character::~Character(void) { }
void Character::Close(void) { width = height = 32; }
void Character::Display(Graphics *graphics, int row, int column, int x, int y) { graphics->DrawImage(image, x, y, column * width, row * height, width, height, UnitPixel); }
void Character::Display(Graphics *graphics, int row, int column, int x, int y, COLORREF color, int horizontalPadding, int verticalPadding) { Color colorObj; colorObj.SetFromCOLORREF(color); SolidBrush brush(colorObj); graphics->FillRectangle(&brush, x, y, width + 2 * horizontalPadding, height + 2 * verticalPadding); Display(graphics, row, column, x + horizontalPadding, y + verticalPadding); }
void Character::Display(Graphics *graphics, int row, int column, int x, int y, int sysColor, int horizontalPadding, int verticalPadding) { COLORREF color = GetSysColor(sysColor); Display(graphics, row, column, x, y, color, horizontalPadding, verticalPadding); }
UINT Character::GetHeight(void) { return height; }
UINT Character::GetWidth(void) { return width; }
void Character::Open(LPTSTR filename) { Open(wstring(filename)); }
void Character::Open(wstring filename) { fileName = filename; image = Image::FromFile(filename.c_str()); fileWidth = image->GetWidth(); fileHeight = image->GetHeight(); width = fileWidth / IMG_COUNT_H; height = fileHeight / IMG_COUNT_V; }
|