|
'A total of 6 files
'Project file ClassWindow.vbp
Type=Exe
Module=ModuleMain; ModuleMain.bas
Class=Class_Form; Class_Form.cls
Class=Class_Screen; Class_Screen.cls
Module=ModuleTrusteeship; ModuleTrusteeship.bas
Class=Class_Main; Class_Main.cls
Startup="Sub Main"
HelpFile=""
Title="ClassWindow"
ExeName32="ClassWindow.exe"
Command32=""
Name="ClassWindow"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="FREE"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=-1
CodeViewDebugInfo=0
NoAliasing=-1
BoundsCheck=-1
OverflowCheck=-1
FlPointCheck=-1
FDIVCheck=-1
UnroundedFP=-1
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
[MS Transaction Server]
AutoRefresh=1
'Standard module ModuleTrusteeship.bas
Attribute VB_Name = "ModuleTrusteeship"
'Management module
Option Explicit
'Structure
Private Type WNDCLASS'form structure
style As Long
lpfnwndproc As Long
cbClsextra As Long
cbWndExtra2 As Long
hInstance As Long
hIcon As Long
hCursor As Long
hbrBackground As Long
lpszMenuName As String
lpszClassName As String
End Type
Private Type POINTAPI'Coordinate structure
x As Long
y As Long
End Type
Private Type Msg'message structure
hWnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
'API function
Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
Private Declare Function GetCommandLine Lib "kernel32" Alias "GetCommandLineA" () As String
Private Declare Function RegisterClass Lib "user32" Alias "RegisterClassA" (Class As WNDCLASS) As Long
Private Declare Function CreateWindowEx Lib "user32.dll" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
Private Declare Function GetDC Lib "user32.dll" (ByVal hWnd As Long) As Long
Private Declare Function GetMessage Lib "user32.dll" Alias "GetMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
Private Declare Function TranslateMessage Lib "user32.dll" (lpMsg As Msg) As Long
Private Declare Function DispatchMessage Lib "user32.dll" Alias "DispatchMessageA" (lpMsg As Msg) As Long
Private Declare Function DefWindowProc Lib "user32.dll" Alias "DefWindowProcA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hWnd As Long) As Long
'Attributes
Public CommandLine As String'Command line
Public hInstance As Long'Instance
Public ErrDescription As String'error description
'Event hosting form
Private IForm As Class_Form
'Managed function
Public Function Trusteeship(ByRef EventForm As Class_Form) As Boolean
'Class instantiation
Set IForm = EventForm
hInstance = GetModuleHandle(vbNull)'Get the module handle
CommandLine = GetCommandLine()'Get command line parameters
Const WinClassName = "MyWinClass"'Define the window class name
Dim WC As WNDCLASS'Set form parameters
With WC
.hIcon = 0'The form icon Use LoadIcon(hInstance, ID) to load the RES icon
.hCursor = 0'The form cursor uses LoadCursor(hInstance, ID) to load the RES cursor
.lpszMenuName = vbNullString'The form menu uses LoadMenu(hInstance,ID) to load the RES menu
.hInstance = hInstance'instance
.cbClsextra = 0
.cbWndExtra2 = 0
.style = 0
.hbrBackground = 16
.lpszClassName = WinClassName'Class name
.lpfnwndproc = GetAddress(AddressOf WinProc)'message function address
End With
'Registration form class
If RegisterClass(WC) = 0 Then ErrDescription = "RegisterClass Faild.": Exit Function
'Get the form handle
With IForm
.hWnd = CreateWindowEx(0&, WinClassName, .Caption, .WindowStyle, .Left, .Top, .Width, .Height, 0, 0, hInstance, ByVal 0&)
If .hWnd = 0 Then ErrDescription = "CreateWindowEx Faild.": Exit Function
.hDC = GetDC(.hWnd)'Get the GDI handle of the form
.Visible = True'Display form
Dim WinMsg As Msg'message structure
'Message loop
Do While GetMessage(WinMsg, .hWnd, 0, 0)> 0
TranslateMessage WinMsg
DispatchMessage WinMsg
DoEvents
Loop
End With
'return value
Trusteeship = True
End Function
'Form process
Private Function WinProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Const WM_CREATE =&H1
Const WM_COMMAND =&H111
Const WM_CLOSE =&H10
Const WM_MOUSEMOVE =&H200
Const WM_SIZE =&H5
Dim bRet As Boolean'Get the return value
With IForm
Select Case wMsg
Case WM_CREATE
Call .ICreate
Case WM_COMMAND
Call .ICommand(wParam, lParam)
Case WM_CLOSE
Call .IUnload(bRet)
If bRet = True Then Exit Function
DestroyWindow .hWnd'Destroy the window
Case WM_MOUSEMOVE
Call .IMouseMove(LoWord(lParam), HiWord(lParam))
Case WM_SIZE
Call .IResize
Case Else
WinProc = DefWindowProc(hWnd, wMsg, wParam, lParam)
End Select
End With
End Function
'Take address
Private Function GetAddress(Address) As Long
GetAddress = Address
End Function
'Low word
Private Function LoWord(ByVal DWord As Long) As Integer
If DWord And&H8000&Then
LoWord = DWord Or&HFFFF0000
Else
LoWord = DWord And&HFFFF&
End If
End Function
'High word
Private Function HiWord(ByVal DWord As Long) As Integer
HiWord = (DWord And&HFFFF0000)\65536
End Function |
|