devxlogo

Giving Forms a 3-D Look

Giving Forms a 3-D Look

It’s not widely known that you can use CTL3D.DLL (or CTL3DV2.DLL) togive your VB forms the same 3-D look of Microsoft’s Office suite of applications.First, your app must register with CTL3D at startup and deregisterbefore it ends. The Ctl3DInit and Ctl3DExit functions take care of thiswhen you pass them the hWnd property of any form in your program. To addthe 3-D effect to a form, call the Ctl3DForm subroutine with the form’sname as the parameter.
Ctl3DForm works its magic by calling GetWindowLong and SetWindowLongto set the form’s DS_MODALFRAME style bit. Then it calls Ctl3DSubclassDlgExto connect the form to CTL3D’s drawing routines:

 DefInt A-Z Option Explicit Global Const BUTTON_FACE = &H8000000F Global Const FIXED_DOUBLE = 3 Global Const DS_MODALFRAME = &H80& Global Const GWL_STYLE = (-16) Global Const GWW_HINSTANCE = (-6) Declare Function Ctl3dAutoSubclass Lib _ "CTL3D.DLL" (ByVal hInst) Declare Function Ctl3dSubclassDlgEx Lib _ "CTL3D.DLL" (ByVal hWnd, ByVal Flags&) Declare Function Ctl3dRegister Lib _ "CTL3D.DLL" (ByVal hInst) Declare Function Ctl3dUnregister Lib _ "CTL3D.DLL" (ByVal hInst) Declare Function GetWindowLong& Lib "User" _ (ByVal hWnd, ByVal nIndex) Declare Function GetWindowWord Lib "User" _ (ByVal hWnd, ByVal nIndex) Declare Function SetWindowLong& Lib "User" _ (ByVal hWnd, ByVal nIndex, ByVal dwNewLong&) Sub Ctl3DInit (hWnd As Integer) Dim hInst As Integer Dim iResult As Integer hInst = GetWindowWord(hWnd, GWW_HINSTANCE) iResult = Ctl3dRegister(hInst) iResult = Ctl3dAutoSubclass(hInst) End Sub Sub Ctl3DExit (hWnd As Integer) Dim hInst As Integer Dim iResult As Integer hInst = GetWindowWord(hWnd, GWW_HINSTANCE) iResult = Ctl3dUnregister(hInst) End Sub Sub Ctl3DForm (frm As Form) Dim hWnd As Integer Dim iResult As Integer Dim lStyle As Long hWnd = frm.hWnd If frm.BorderStyle = FIXED_DOUBLE Then frm.BackColor = BUTTON_FACE lStyle = GetWindowLong(hWnd, GWL_STYLE) lStyle = lStyle Or DS_MODALFRAME lStyle = SetWindowLong(hWnd, GWL_STYLE, lStyle) iResult = Ctl3dSubclassDlgEx(hWnd, 0) End If End Sub 

Ctl3DForm will only “3-D-ize” forms whose BorderStyleis 3 (FIXED_DOUBLE). You can achieve some, uh, unusual effects bytrying it on forms with other BorderStyles.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist