WinapiZone.net




Tutorials > WinAPI > Functions > Draw3dRect

Draw3dRect

The Draw3dRect is a MFC function (member of the CDC class) that draws a 3d rect with two different color on the top left border and on the bottom right border.
void Draw3DRect(HDC hdc, LPRECT destRect, COLORREF topLeftColor, COLORREF bottomRightColor) { HPEN topLeftPen = CreatePen(PS_SOLID, 1, topLeftColor); HPEN bottomRightPen = CreatePen(PS_SOLID, 1, bottomRightColor); POINT pt[3]; SelectObject(hdc, topLeftPen); pt[0].x = destRect->left; pt[0].y = destRect->bottom-1; pt[1].x = destRect->left; pt[1].y = destRect->top; pt[2].x = destRect->right; pt[2].y = destRect->top; Polyline(hdc, (LPPOINT)&pt, 3); SelectObject(hdc, bottomRightPen); pt[0].x = destRect->left; pt[0].y = destRect->bottom-1; pt[1].x = destRect->right; pt[1].y = destRect->bottom-1; pt[2].x = destRect->right; pt[2].y = destRect->top; Polyline(hdc, (LPPOINT)&pt, 3); DeleteObject(topLeftPen); DeleteObject(bottomRightPen); }

Arguments

hdc
A handle to the device context where to draw the 3d rect
destRect
A pointer to a RECT structure that specify the rect of the device context where to draw the 3d rect
topLeftColor
The color of the top left border of the rect
bottomRightColor
The color of the bottom right border of the rect

Example

RECT rect = {0,0,20,20};

HDC hdc = GetDC(hwnd);
Draw3dRect(hdc, gripper, &rect, GetSysColor(COLOR_3DHIGHLIGHT), GetSysColor(COLOR_3DSHADOW));
ReleaseDC(hwnd, hdc);

Comments

No comments yet.

Your comment:

Name:
E-mail or homepage:
Captcha:
captcha

Script by Alex



This page was last modified 34 months, 3 weeks, 2 days and 9 hours ago