1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
...SNIP...
void MainWindow::DrawButton(const LPARAM& lParam) // function called during WM_DRAWITEM message for all buttons
{
HRESULT hr = CreateGraphicsResources();
if (SUCCEEDED(hr))
{
auto pdis = (DRAWITEMSTRUCT*)lParam;
std::wstring text = GetButtonText(pdis->CtlID);
pRenderButton->BindDC(pdis->hDC, &pdis->rcItem); // here bind HDC of a button to rendertarget
pRenderButton->BeginDraw();
if (pdis->itemState & ODS_SELECTED)
{
D2D1_RECT_F layoutRect = D2D1::RectF(
static_cast<float>(pdis->rcItem.left + 1.f),
static_cast<float>(pdis->rcItem.top + pdis->rcItem.bottom / 4.f + 1.f),
static_cast<float>(pdis->rcItem.right),
static_cast<float>(pdis->rcItem.bottom));
D2D1_POINT_2F pt1 = D2D1::Point2F(static_cast<float>(pdis->rcItem.left), static_cast<float>(pdis->rcItem.top));
D2D1_POINT_2F pt2 = D2D1::Point2F(static_cast<float>(pdis->rcItem.left), static_cast<float>(pdis->rcItem.bottom));
D2D1_POINT_2F pt3 = D2D1::Point2F(static_cast<float>(pdis->rcItem.right), static_cast<float>(pdis->rcItem.top));
pRenderButton->Clear(D2D1_COLOR_F(D2D1::ColorF(D2D1::ColorF::LightGray)));
pBrush->SetColor(D2D1::ColorF(D2D1::ColorF::DarkGray));
pRenderButton->DrawLine(pt1, pt2, pBrush, 4.f);
pRenderButton->DrawLine(pt1, pt3, pBrush, 4.f);
pBrush->SetColor(D2D1::ColorF(D2D1::ColorF::Black));
pRenderButton->DrawText(
text.c_str(),
static_cast<UINT32>(text.length()),
pTextFormat,
layoutRect, pBrush);
}
hr = pRenderButton->EndDraw();
if (FAILED(hr) || hr == D2DERR_RECREATE_TARGET)
{
DischardGraphicsResources();
}
... SNIP...
| |