vbgen Level: Moderator
 Registered: 10-10-2002 Posts: 876
|
Subclass for An About Box
hello! aside from the shell about option, you can also go through a little subclassing to get a simpler aboutbox...
Option Explicit
Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As String) As Long
Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const WM_SYSCOMMAND = &H112
Public Const MF_SEPARATOR = &H800&
Public Const MF_STRING = &H0&
Public Const GWL_WNDPROC = (-4)
Public Const IDM_ABOUT As Long = 1010
Public lProcOld As Long
Public Function SysMenuHandler(ByVal hWnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If iMsg = WM_SYSCOMMAND Then
If wParam = IDM_ABOUT Then
MsgBox "About . . .", vbInformation, "About"
Exit Function
End If
End If
SysMenuHandler = CallWindowProc(lProcOld, hWnd, iMsg, wParam, lParam)
End Function
Public Function SubClass(FormName As Form)
Dim lhSysMenu As Long, lRet As Long
lhSysMenu = GetSystemMenu(FormName.hWnd, 0&)
lRet = AppendMenu(lhSysMenu, MF_SEPARATOR, 0&, vbNullString)
lRet = AppendMenu(lhSysMenu, MF_STRING, IDM_ABOUT, "About...")
FormName.Show
lProcOld = SetWindowLong(FormName.hWnd, GWL_WNDPROC, AddressOf SysMenuHandler)
End Function
|
that code goes into a module, or class, so that it can be accessed by other forms...
making public functions is good in the sense that you leave the code inside the module, and your form code looks cleaner! just a thought..
and this code goes into the form...
Option Explicit
Private Sub Form_Load()
Dim d As String
d = subClass(Form1)
End Sub
Private Sub Form_Unload(Cancel As Integer)
SetWindowLong Me.hWnd, GWL_WNDPROC, lProcOld
End Sub
|
go ahead and try it... i think this is cool code, not because it's my post, but because you won't have to have a button or menu just to have an about box.
have fun! i hope all of you like this one.
if you opt to subclass forms, make sure you do not stop the program by hitting the end button on the vb toolbar... or else your IDE will crash... please be careful.
if you do not know what i mean... please post before using this code.
____________________________
Been busy trying to take a second degree <--it's not working out...
|