Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Aug 20, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Giving Forms a 3-D Look

It's not widely known that you can use CTL3D.DLL (or CTL3DV2.DLL) to give 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 deregister before it ends. The Ctl3DInit and Ctl3DExit functions take care of this when you pass them the hWnd property of any form in your program. To add the 3-D effect to a form, call the Ctl3DForm subroutine with the form's name as the parameter.
Ctl3DForm works its magic by calling GetWindowLong and SetWindowLong to set the form's DS_MODALFRAME style bit. Then it calls Ctl3DSubclassDlgEx to 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 BorderStyle is 3 (FIXED_DOUBLE). You can achieve some, uh, unusual effects by trying it on forms with other BorderStyles.
Phil Weber
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date