' These flags will activate certain functions that require
' classes that most functions do not need. If you do not
' need to use a function that is triggered by a flag, you
' can set the flag to False, and prevent an unneeded class
' from being loaded.
#Const FlagGlobalAlloc = True
#Const FlagGetSystemPowerStatus = True
#Const FlagGetVersionEx = True
#Const FlagGetCPInfo = True
#Const FlagDeviceContext = True
#Const FlagMetaFile = True
' Sub classes:
Public Metrics As New dwMetrics
Public SysColor As New dwSysColor
'** Functions From Chapter 5 Index
#If Win32 Then
Private Declare Function apiAdjustWindowRect& Lib "user32" Alias "AdjustWindowRect" (lpRect As RECT, ByVal dwStyle As Long, ByVal bMenu As Long)
Private Declare Function apiAdjustWindowRectEx& Lib "user32" Alias "AdjustWindowRectEx" (lpRect As RECT, ByVal dsStyle As Long, ByVal bMenu As Long, ByVal dwEsStyle As Long)
Private Declare Function apiAnyPopup& Lib "user32" Alias "AnyPopup" ()
Private Declare Function apiGetActiveWindow& Lib "user32" Alias "GetActiveWindow" ()
Private Declare Function apiFindWindow& Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String)
Private Declare Function apiGetCapture& Lib "user32" Alias "GetCapture" ()
Private Declare Function apiGetDesktopWindow& Lib "user32" Alias "GetDesktopWindow" ()
Private Declare Function apiGetFocus& Lib "user32" Alias "GetFocus" ()
Private Declare Function apiGetForegroundWindow& Lib "user32" Alias "GetForegroundWindow" ()
Private Declare Function apiGetLastActivePopup& Lib "user32" Alias "GetLastActivePopup" (ByVal hwndOwnder As Long)
Private Declare Function apiWindowFromPoint& Lib "user32" Alias "WindowFromPoint" (ByVal x As Long, ByVal y As Long)
#Else
Private Declare Sub apiAdjustWindowRect Lib "user" Alias "AdjustWindowRec" (lpRect As RECT, ByVal dwStyle As Long, ByVal bMenu As Integer)
Private Declare Sub apiAdjustWindowRectEx Lib "user" Alias "AdjustWindowRectEx" (lpRect As RECT, ByVal dsStyle As Long, ByVal bMenu As Integer, ByVal dwEsStyle As Long)
Private Declare Function apiAnyPopup% Lib "user" Alias "AnyPopup" ()
Private Declare Function apiGetActiveWindow% Lib "user" Alias "GetActiveWindow" ()
Private Declare Function apiFindWindow% Lib "user" Alias "FindWindow" (ByVal lpClassName As Any, ByVal lpWindowName As Any)
Private Declare Function apiGetCapture% Lib "user" Alias "GetCapture" ()
Private Declare Function apiGetDesktopWindow% Lib "user" Alias "GetDesktopWindow" ()
Private Declare Function apiGetFocus% Lib "user" Alias "GetFocus" ()
'function apiGetForegroundWindow is not available in the WIN16 API.
Private Declare Function apiGetLastActivePopup% Lib "user" Alias "GetLastActivePopup" (ByVal hwndOwnder As Integer)
Private Declare Function apiWindowFromPoint% Lib "user" Alias "WindowFromPoint" (ByVal pnt As Any)
#End If 'WIN32
'** Functions From Chapter 6 Index
#If Win32 Then
Private Declare Function apiBeep& Lib "kernel32" Alias "Beep" (ByVal dwFreq As Long, ByVal dwDuration As Long)
Private Declare Function apiCharToOem& Lib "user32" Alias "CharToOemA" (ByVal lpszSrc As String, ByVal lpszDst As String)
Private Declare Function apiCharToOemBuff& Lib "user32" Alias "CharToOemBuffA" (ByVal lpszSrc As String, ByVal lpszDst As String, ByVal cchDstLength As Long)
Private Declare Function apiClipCursor& Lib "user32" Alias "ClipCursor" (lpRect As RECT)
Private Declare Function apiClipCursorBynum& Lib "user32" Alias "ClipCursor" (ByVal lpRect As Long)
Private Declare Function apiExitWindowsEx& Lib "user32" Alias "ExitWindowsEx" (ByVal uFlags As Long, ByVal dwReserved As Long)
Private Declare Function apiGetACP& Lib "kernel32" Alias "GetACP" ()
Private Declare Function apiGetAsyncKeyState% Lib "user32" Alias "GetAsyncKeyState" (ByVal vKey As Long)
Private Declare Function apiGetCaretBlinkTime& Lib "user32" Alias "GetCaretBlinkTime" ()
Private Declare Function apiGetCPInfo& Lib "kernel32" Alias "GetCPInfo" (ByVal CodePage As Long, lpCPInfo As CPINFO)
Private Declare Function apiGetClipCursor& Lib "user32" Alias "GetClipCursor" (lprc As RECT)
Private Declare Function apiGetCommandLine& Lib "kernel32" Alias "GetCommandLineA" ()
Private Declare Function apiGetComputerName& Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long)
Private Declare Function apiGetCursorPos& Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI)
Private Declare Function apiGetDoubleClickTime& Lib "user32" Alias "GetDoubleClickTime" ()
Private Declare Function apiGetInputState& Lib "user32" Alias "GetInputState" ()
Private Declare Function apiGetKBCodePage& Lib "user32" Alias "GetKBCodePage" ()
Private Declare Function apiGetKeyboardLayoutName& Lib "user32" Alias "GetKeyboardLayoutNameA" (ByVal pwszKLID As String)
Private Declare Function apiGetKeyboardLayout& Lib "user32" Alias "GetKeyboardLayout" (ByVal dwLayout As Long)
Private Declare Function apiGetKeyboardState& Lib "user32" Alias "GetKeyboardState" (pbKeyState As Byte)
Private Declare Function apiGetKeyboardType& Lib "user32" Alias "GetKeyboardType" (ByVal nTypeFlag As Long)
Private Declare Function apiGetKeyNameText& Lib "user32" Alias "GetKeyNameTextA" (ByVal lParam As Long, ByVal lpBuffer As String, ByVal nSize As Long)
Private Declare Function apiGetKeyState% Lib "user32" Alias "GetKeyState" (ByVal nVirtKey As Long)
Private Declare Function apiGetOEMCP& Lib "kernel32" Alias "GetOEMCP" ()
Private Declare Function apiGetQueueStatus& Lib "user32" Alias "GetQueueStatus" (ByVal fuFlags As Long)
Private Declare Function apiGetSystemDefaultLangID% Lib "kernel32" Alias "GetSystemDefaultLangID" ()
Private Declare Function apiGetSystemDefaultLCID& Lib "kernel32" Alias "GetSystemDefaultLCID" ()
Private Declare Function apiGetSystemPowerStatus& Lib "kernel32" Alias "GetSystemPowerStatus" (lpSystemPowerStatus As SYSTEM_POWER_STATUS)
Private Declare Function apiGetThreadLocale& Lib "kernel32" Alias "GetThreadLocale" ()
Private Declare Function apiGetUserDefaultLangID% Lib "kernel32" Alias "GetUserDefaultLangID" ()
Private Declare Function apiGetUserDefaultLCID& Lib "kernel32" Alias "GetUserDefaultLCID" ()
Private Declare Function apiGetUserName& Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long)
Private Declare Function apiGetVersion& Lib "kernel32" Alias "GetVersion" ()
Private Declare Function apiGetVersionEx& Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO)
Private Declare Function apiIsValidCodePage& Lib "kernel32" Alias "IsValidCodePage" (ByVal CodePage As Long)
Private Declare Function apiIsValidLocale& Lib "kernel32" Alias "IsValidLocale" (ByVal Locale As Long, ByVal dwFlags As Long)
Private Declare Function apiMessageBeep& Lib "user32" Alias "MessageBeep" (ByVal wType As Long)
Private Declare Function apiSetCaretBlinkTime& Lib "user32" Alias "SetCaretBlinkTime" (ByVal wMSeconds As Long)
Private Declare Function apiSetComputerName& Lib "kernel32" Alias "SetComputerNameA" (ByVal lpComputerName As String)
Private Declare Function apiSetCursorPos& Lib "user32" Alias "SetCursorPos" (ByVal x As Long, ByVal y As Long)
Private Declare Function apiSetDoubleClickTime& Lib "user32" Alias "SetDoubleClickTime" (ByVal wCount As Long)
Private Declare Function apiSetThreadLocale& Lib "kernel32" Alias "SetThreadLocale" (ByVal Locale As Long)
Private Declare Function apiShowCursor& Lib "user32" Alias "ShowCursor" (ByVal bShow As Long)
Private Declare Function apiSwapMouseButton& Lib "user32" Alias "SwapMouseButton" (ByVal bSwap As Long)
#Else
'function apiBeep is not available in the WIN16 API.
'function apiCharToOem is not available in the WIN16 API.
'function apiCharToOemBuff is not available in the WIN16 API.
Private Declare Sub apiClipCursor Lib "user" Alias "ClipCursor" (lpRect As Any)
Private Declare Sub apiClipCursorBynum Lib "user" Alias "ClipCursor" (ByVal lpRect As Long)
'function apiExitWindowsEx is not available in the WIN16 API.
Private Declare Function apiExitWindows% Lib "user" Alias "ExitWindows" (ByVal dwReturnCode&, ByVal Reserved%)
'function apiGetACP is not available in the WIN16 API.
Private Declare Function apiGetAsyncKeyState% Lib "user" Alias "GetAsyncKeyState" (ByVal vKey As Integer)
Private Declare Function apiGetCaretBlinkTime% Lib "user" Alias "GetCaretBlinkTime" ()
'function apiGetCPInfo is not available in the WIN16 API.
Private Declare Sub apiGetClipCursor Lib "user" Alias "GetClipCursor" (lprc As RECT)
'function apiGetCommandLine is not available in the WIN16 API.
'function apiGetComputerName is not available in the WIN16 API.
Private Declare Sub apiGetCursorPos Lib "user" Alias "GetCursorPos" (lpPoint As POINTAPI)
Private Declare Function apiGetDoubleClickTime% Lib "user" Alias "GetDoubleClickTime" ()
Private Declare Function apiGetInputState% Lib "user" Alias "GetInputState" ()
Private Declare Function apiGetKBCodePage% Lib "keyboard.dll" Alias "GetKBCodePage" ()
'function apiGetKeyboardLayoutName is not available in the WIN16 API.
Private Declare Sub apiGetKeyboardState Lib "user" Alias "GetKeyboardState" (LpKeyState As Any)
Private Declare Function apiGetKeyboardType% Lib "keyboard.dll" Alias "GetKeyboardType" (ByVal nTypeFlag As Integer)
Private Declare Function apiGetKeyNameText% Lib "keyboard.dll" Alias "GetKeyNameText" (ByVal lParam As Long, ByVal lpBuffer As String, ByVal nSize As Integer)
Private Declare Function apiGetKeyState% Lib "user" Alias "GetKeyState" (ByVal nVirtKey As Integer)
'Function GetOEMCP is not available in the WIN16 API.
Private Declare Function apiGetQueueStatus& Lib "user" Alias "GetQueueStatus" (ByVal fuFlags As Integer)
'Function GetSystemDefaultLangID is not available in the WIN16 API.
'Function GetSystemDefaultLCID is not available in the WIN16 API.
'Function GetSystemPowerStatus is not available in the WIN16 API.
'Function GetThreadLocale is not available in the WIN16 API.
'Function GetUserDefaultLangID is not available in the WIN16 API.
'Function GetUserDefaultLCID is not available in the WIN16 API.
'Function GetUserName is not available in the WIN16 API.
Private Declare Function apiGetVersion& Lib "kernel" Alias "GetVersion" ()
'Function GetVersionEx is not available in the WIN16 API.
'Function IsValidCodePage is not available in the WIN16 API.
'Function IsValidLocale is not available in the WIN16 API.
Private Declare Sub apiMessageBeep Lib "user" Alias "MessageBeep" (ByVal wType As Integer)
Private Declare Sub apiSetCaretBlinkTime Lib "user" Alias "SetCaretBlinkTime" (ByVal wMSeconds As Integer)
'Function SetComputerName is not available in the WIN16 API.
Private Declare Sub apiSetCursorPos Lib "user" Alias "SetCursorPos" (ByVal x As Integer, ByVal y As Integer)
Private Declare Sub apiSetDoubleClickTime Lib "user" Alias "SetDoubleClickTime" (ByVal wCount As Integer)
'Function SetThreadLocale is not available in the WIN16 API.
Private Declare Function apiShowCursor% Lib "user" Alias "ShowCursor" (ByVal bShow As Integer)
Private Declare Function apiSwapMouseButton% Lib "user" Alias "SwapMouseButton" (ByVal bSwap As Integer)
#End If 'WIN32
'** Functions From Chapter 8 Index
#If Win32 Then
Private Declare Function apiCreateMetaFile& Lib "gdi32" Alias "CreateMetaFileA" (ByVal lpstring As String)
Private Declare Function apiCreatePen& Lib "gdi32" Alias "CreatePen" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long)
Private Declare Function apiGdiFlush& Lib "gdi32" Alias "GdiFlush" ()
Private Declare Function apiGdiGetBatchLimit& Lib "gdi32" Alias "GdiGetBatchLimit" ()
Private Declare Function apiGdiSetBatchLimit& Lib "gdi32" Alias "GdiSetBatchLimit" (ByVal dwLimit As Long)
Private Declare Function apiGetEnhMetaFile& Lib "gdi32" Alias "GetEnhMetaFileA" (ByVal lpszMetaFile As String)
Private Declare Function apiGetMetaFile& Lib "gdi32" Alias "GetMetaFileA" (ByVal lpFileName As String)
#Else
Private Declare Function apiCreateMetaFile% Lib "gdi" Alias "CreateMetaFile" (ByVal lpstring As Any)
Private Declare Function apiCreatePen% Lib "gdi" Alias "CreatePen" (ByVal nPenStyle As Integer, ByVal nWidth As Integer, ByVal crColor As Long)
'function apiGdiFlush is not available in the WIN16 API.
'function apiGdiGetBatchLimit is not available in the WIN16 API.
'function apiGdiSetBatchLimit is not available in the WIN16 API.
'function apiGetEnhMetaFile is not available in the WIN16 API.
Private Declare Function apiGetMetaFile% Lib "gdi" Alias "GetMetaFile" (ByVal lpFileName As String)
#End If 'WIN32
#If Win32 Then
Private Declare Function apiGlobalAlloc& Lib "kernel32" Alias "GlobalAlloc" (ByVal fuFlags As Long, ByVal cdBytes As Long)
Private Declare Function apiMessageBox& Lib "user32" Alias "MessageBox" (ByVal hWnd&, ByVal lpText$, ByVal lpCaption$, ByVal wType&)
Private Declare Function apiGetTickCount& Lib "user32" Alias "GetTickCount" ()
#Else
Private Declare Function apiGlobalAlloc% Lib "kernel" Alias "GlobalAlloc" (ByVal fuFlags As Integer, ByVal cdBytes As Long)
Private Declare Function apiMessageBox% Lib "user" Alias "MessageBox" (ByVal hWnd%, ByVal lpText$, ByVal lpCaption$, ByVal wType%)
Private Declare Function apiGetTickCount& Lib "user" Alias "GetTickCount" ()
#End If 'WIN32
Private Sub RaiseSysError(Optional errval)
If IsMissing(errval) Then
RaiseError DWERR_APIRESULT, "dwSystem"
Else
RaiseError errval, "dwSystem"
End If
End Sub
Public Function CreatePen(ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As dwPen
Attribute CreatePen.VB_HelpID = 2510
Attribute CreatePen.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"