How to Give a 3-D Effect to Windows ControlsLast reviewed: July 22, 1997Article ID: Q69079 |
3.00 3.10
WINDOWS
kbprg
The information in this article applies to:
SUMMARYIt is possible for an application to give edit controls, list boxes, and static text a three-dimensional (3-D) appearance. Each control can be made to appear recessed into the surface of its parent dialog box, or raised above it. This article contains the code necessary to implement this effect.
MORE INFORMATIONThere are three steps required to give a particular control a 3-D appearance:
The following code shows how to use DrawIndent():
... case WM_PAINT: PostMessage(hDlg, WM_COMMAND, IDM_REPAINT, 0L); return FALSE; case WM_COMMAND: switch (wParam) { case IDM_REPAINT: DrawIndent(hDlg, IDD_FIELD1); DrawIndent(hDlg, IDD_FIELD2); ... DrawIndent(hDlg, IDD_FIELDN); break; ...The following is the code for DrawIndent():
void DrawIndent(HWND hDlg, int ID) // Assumptions: // // hDlg is a valid window handle. // ID is a valid control ID. // bMonochrome is a flag that is TRUE for a monochrome system. //{ RECT rRect; HDC hDC; HPEN hOldPen; GetClientRect(GetDlgItem(hDlg, ID), (LPRECT)&rRect); // By modifying the parameters this way, things are centered a bit // better. rRect.left -= 2; rRect.bottom -= 1; rRect.top -= 3; hDC = GetDC(GetDlgItem(hDlg, ID)); // Draw the Shadow hOldPen = SelectObject(hDC, GetStockObject(BLACK_PEN)); MoveTo(hDC, rRect.left-1, rRect.bottom+1); LineTo(hDC, rRect.left-1, rRect.top-1); LineTo(hDC, rRect.right+1, rRect.top-1); if (!bMonochrome) { MoveTo(hDC, rRect.left-2, rRect.bottom+2); LineTo(hDC, rRect.left-2, rRect.top-2); LineTo(hDC, rRect.right+2, rRect.top-2); // On color systems, select the highlight color SelectObject(hDC, GetStockObject(WHITE_PEN)); } // Draw the Highlight (still shadow for mono systems) MoveTo(hDC, rRect.right+1, rRect.top-1); LineTo(hDC, rRect.right+1, rRect.bottom+1); LineTo(hDC, rRect.left-1, rRect.bottom+1); if (!bMonochrome) { MoveTo(hDC, rRect.right+2, rRect.top-2); LineTo(hDC, rRect.right+2, rRect.bottom+2); LineTo(hDC, rRect.left-2, rRect.bottom+2); } // Housekeep SelectObject(hDC, hOldPen); ReleaseDC(GetDlgItem(hDlg, ID), hDC);} For additional information, please see the following article(s) in the Microsoft Knowledge Base:
ARTICLE-ID: Q97361 TITLE : Adding 3-D Controls Using CTL3D.DLL |
Additional reference words: 3.00 3.10
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |