' 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 FlagGetDC = True ' uses dwDeviceContext
#Const FlagRegion = True ' uses dwRegion
Private iHwnd As Long ' Window handle assigned to this object
Private iLeft As Long ' These are for API Foundation Library Standard compatibility
Private iTop As Long
Private iWidth As Long
Private iHeight As Long
'********************Located In Chapter 5 Function Index *************************
#If Win32 Then
Private Declare Function apiIsWindowEnabled& Lib "user32" Alias "IsWindowEnabled" (ByVal hwnd As Long)
Private Declare Function apiGetDesktopWindow& Lib "user32" Alias "GetDesktopWindow" ()
Private Declare Function apiGetForegroundWindow& Lib "user32" Alias "GetForegroundWindow" ()
Private Declare Function apiGetParent& Lib "user32" Alias "GetParent" (ByVal hwnd As Long)
Private Declare Function apiGetTopWindow& Lib "user32" Alias "GetTopWindow" (ByVal hwnd As Long)
Private Declare Function apiGetWindow& Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wCmd As Long)
Private Declare Function apiGetWindowLong& Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long)
Private Declare Function apiGetWindowRect& Lib "user32" Alias "GetWindowRect" (ByVal hwnd As Long, lpRect As RECT)
Private Declare Function apiIsWindowUnicode& Lib "user32" Alias "IsWindowUnicode" (ByVal hwnd As Long)
Private Declare Function apiIsWindowVisible& Lib "user32" Alias "IsWindowVisible" (ByVal hwnd As Long)
Private Declare Function apiInvalidateRect& Lib "user32" Alias "InvalidateRect" (ByVal hwnd As Long, lpRect As RECT, ByVal bErase As Long)
Private Declare Function apiInvalidateRectBynum& Lib "user32" Alias "InvalidateRect" (ByVal hwnd As Long, ByVal lpRect As Long, ByVal bErase As Long)
Private Declare Function apiIsChild& Lib "user32" Alias "IsChild" (ByVal hWndParent As Long, ByVal hwnd As Long)
Private Declare Function apiIsIconic& Lib "user32" Alias "IsIconic" (ByVal hwnd As Long)
Private Declare Function apiIsZoomed& Lib "user32" Alias "IsZoomed" (ByVal hwnd As Long)
Private Declare Function apiLockWindowUpdate& Lib "user32" Alias "LockWindowUpdate" (ByVal hwndLock As Long)
Private Declare Function apiMoveWindow& Lib "user32" Alias "MoveWindow" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long)
Private Declare Function apiOpenIcon& Lib "user32" Alias "OpenIcon" (ByVal hwnd As Long)
Private Declare Function apiRedrawWindow& Lib "user32" Alias "RedrawWindow" (ByVal hwnd As Long, lprcUpdate As RECT, ByVal hRgnUpdate As Long, ByVal fuRedraw As Long)
Private Declare Function apiReleaseCapture& Lib "user32" Alias "ReleaseCapture" ()
Private Declare Function apiScreenToClient& Lib "user32" Alias "ScreenToClient" (ByVal hwnd As Long, lpPoint As POINTAPI)
Private Declare Function apiScrollWindow& Lib "user32" Alias "ScrollWindow" (ByVal hwnd As Long, ByVal XAmount As Long, ByVal YAmount As Long, lpRect As RECT, lpClipRect As RECT)
Private Declare Function apiScrollWindowByval& Lib "user32" Alias "ScrollWindow" (ByVal hwnd As Long, ByVal XAmount As Long, ByVal YAmount As Long, ByVal lpRect As Long, ByVal lpClipRect As Long)
Private Declare Function apiScrollWindowEx& Lib "user32" Alias "ScrollWindowEx" (ByVal hwnd As Long, ByVal dx As Long, ByVal dy As Long, lprcScroll As RECT, lprcClip As RECT, ByVal hRgnUpdate As Long, lprcUpdate As RECT, ByVal fuScroll As Long)
Private Declare Function apiScrollWindowExByval& Lib "user32" Alias "ScrollWindowEx" (ByVal hwnd As Long, ByVal dx As Long, ByVal dy As Long, ByVal lprcScroll As Long, ByVal lprcClip As Long, ByVal hRgnUpdate As Long, ByVal lprcUpdate As Long, ByVal fuScroll As Long)
Private Declare Function apiSetActiveWindow& Lib "user32" Alias "SetActiveWindow" (ByVal hwnd As Long)
Private Declare Function apiSetCapture& Lib "user32" Alias "SetCapture" (ByVal hwnd As Long)
Private Declare Function apiSetFocus& Lib "user32" Alias "SetFocus" (ByVal hwnd As Long)
Private Declare Function apiSetForegroundWindow& Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Long)
Private Declare Function apiSetParent& Lib "user32" Alias "SetParent" (ByVal hWndChild As Long, ByVal hWndNewParent As Long)
Private Declare Function apiSetWindowPos& Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Private Declare Function apiSetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
Private Declare Function apiSetWindowText& Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String)
Private Declare Function apiSetWindowWord% Lib "user32" Alias "SetWindowWord" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal wNewWord As Integer)
Private Declare Function apiShowOwnedPopups& Lib "user32" Alias "ShowOwnedPopups" (ByVal hwnd As Long, ByVal fshow As Long)
Private Declare Function apiShowWindow& Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long)
Private Declare Function apiShowWindowAsync& Lib "user32" Alias "ShowWindowAsync" (ByVal hwnd As Long, ByVal nCmdShow As Long)
Private Declare Function apiValidateRect& Lib "user32" (ByVal hwnd As Long, lpRect As RECT)
Private Declare Function apiValidateRectBynum& Lib "user32" Alias "ValidateRect" (ByVal hwnd As Long, ByVal lpRect As Long)
Private Declare Function apiArrangeIconicWindows& Lib "user32" Alias "ArrangeIconicWindows" (ByVal hwnd As Long)
Private Declare Function apiChildWindowFromPoint& Lib "user32" Alias "ChildWindowFromPoint" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long)
Private Declare Function apiChildWindowFromPointEx& Lib "user32" Alias "ChildWindowFromPointEx" (ByVal hWndParent As Long, ByVal ptx As Long, ByVal pty As Long, ByVal uFlags As Long)
Private Declare Function apiGetClassName& Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long)
Private Declare Function apiGetClassLong& Lib "user32" Alias "GetClassLongA" (ByVal hwnd As Long, ByVal nIndex As Long)
Private Declare Function apiFlashWindow& Lib "user32" Alias "FlashWindow" (ByVal hwnd As Long, ByVal bInvert As Long)
Private Declare Function apiFindWindowEx& Lib "user32" Alias "FindWindowExA" (ByVal hWndParent As Long, ByVal hWndChildAfter As Long, ByVal lpClassName As String, ByVal lpWindowName As String)
Private Declare Function apiEnableWindow& Lib "user32" Alias "EnableWindow" (ByVal hwnd As Long, ByVal fEnable As Long)
Private Declare Function apiCloseWindow& Lib "user32" Alias "CloseWindow" (ByVal hwnd As Long)
Private Declare Function apiClientToScreen& Lib "user32" Alias "ClientToScreen" (ByVal hwnd As Long, lpPoint As POINTAPI)
Private Declare Function apiDestroyWindow Lib "user32" Alias "DestroyWindow" (ByVal hwnd As Long) As Boolean
Private Declare Function apiBringWindowToTop& Lib "user32" Alias "BringWindowToTop" (ByVal hwnd As Long)
Private Declare Function apiWindowFromPoint& Lib "user32" Alias "WindowFromPoint" (ByVal x As Long, ByVal y As Long)
Private Declare Function apiGetClientRect& Lib "user32" Alias "GetClientRect" (ByVal hwnd As Long, lpRect As RECT)
Private Declare Function apiGetWindowText& Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long)
Private Declare Function apiGetWindowTextLength& Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long)
Private Declare Function apiIsWindow& Lib "user32" Alias "IsWindow" (ByVal hwnd As Long)
Private Declare Function apiUpdateWindow& Lib "user32" Alias "UpdateWindow" (ByVal hwnd As Long)
Private Declare Function apiInvalidateRgn& Lib "user32" Alias "InvalidateRgn" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bErase As Long)
Private Declare Function apiSendMessage& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal nMsg As Integer, ByVal wParam As Long, ByVal lParam As Long)
Private Declare Sub apiDragAcceptFiles Lib "shell32.dll" Alias "DragAcceptFiles" (ByVal hwnd As Long, ByVal accept As Boolean)
#Else
Private Declare Function apiIsWindowEnabled% Lib "user" Alias "IsWindowEnabled" (ByVal hwnd As Integer)
Private Declare Function apiGetParent% Lib "user" Alias "GetParent" (ByVal hwnd As Integer)
Private Declare Function apiGetDesktopWindow% Lib "user" Alias "GetDesktopWindow" ()
Private Declare Function apiGetTopWindow% Lib "user" Alias "GetTopWindow" (ByVal hwnd As Integer)
Private Declare Function apiGetWindow% Lib "user" Alias "GetWindow" (ByVal hwnd As Integer, ByVal wCmd As Integer)
Private Declare Function apiGetWindowLong& Lib "user" Alias "GetWindowLong" (ByVal hwnd As Integer, ByVal nIndex As Integer)
Private Declare Sub apiGetWindowRect Lib "user" Alias "GetWindowRect" (ByVal hwnd As Integer, lpRect As RECT)
'Function IsWindowUnicode is not available in the WIN16 API.
Private Declare Function apiIsWindowVisible% Lib "user" Alias "IsWindowVisible" (ByVal hwnd As Integer)
Private Declare Sub apiInvalidateRect Lib "user" Alias "InvalidateRect" (ByVal hwnd As Integer, lpRect As RECT, ByVal bErase As Integer)
Private Declare Sub apiInvalidateRectBynum Lib "user" Alias "InvalidateRect" (ByVal hwnd As Integer, ByVal lpRect As Long, ByVal bErase As Integer)
Private Declare Function apiIsChild% Lib "user" Alias "IsChild" (ByVal hWndParent As Integer, ByVal hwnd As Integer)
Private Declare Function apiIsIconic% Lib "user" Alias "IsIconic" (ByVal hwnd As Integer)
Private Declare Function apiIsZoomed% Lib "user" Alias "IsZoomed" (ByVal hwnd As Integer)
Private Declare Function apiLockWindowUpdate% Lib "user" Alias "LockWindowUpdate" (ByVal hwnd As Integer)
Private Declare Sub apiMoveWindow Lib "user" Alias "MoveWindow" (ByVal hwnd As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal bRepaint As Integer)
Private Declare Function apiOpenIcon% Lib "user" Alias "OpenIcon" (ByVal hwnd As Integer)
Private Declare Function apiRedrawWindow% Lib "user" Alias "RedrawWindow" (ByVal hwnd As Integer, lprcUpdate As RECT, ByVal hRgnUpdate As Integer, ByVal fuRedraw As Integer)
Private Declare Sub apiReleaseCapture Lib "user" Alias "ReleaseCapture" ()
Private Declare Sub apiScreenToClient Lib "user" (ByVal hwnd As Integer, lpPoint As POINTAPI)
Private Declare Sub apiScrollWindow Lib "user" Alias "ScrollWindow" (ByVal hwnd As Integer, ByVal XAmount As Integer, ByVal YAmount As Integer, lpRect As RECT, lpClipRect As RECT)
Private Declare Sub apiScrollWindowByval Lib "user" Alias "ScrollWindow" (ByVal hwnd As Long, ByVal XAmount As Integer, ByVal YAmount As Integer, ByVal lpRect As Long, ByVal lpClipRect As Long)
Private Declare Sub apiScrollWindowEx Lib "user" Alias "ScrollWindowEx" (ByVal hwnd As Integer, ByVal dx As Integer, ByVal dy As Integer, lprcScroll As RECT, lprcClip As RECT, ByVal hRgnUpdate As Integer, lprcUpdate As RECT, ByVal fuScroll As Integer)
Private Declare Function apiSetActiveWindow% Lib "user" Alias "SetActiveWindow" (ByVal hwnd As Integer)
Private Declare Function apiSetCapture% Lib "user" Alias "SetCapture" (ByVal hwnd As Integer)
Private Declare Function apiSetFocus% Lib "user" Alias "SetFocus" (ByVal hwnd As Integer)
'Function SetForegroundWindow is not available in the WIN16 API.
Private Declare Function apiSetParent% Lib "user" Alias "SetParent" (ByVal hWndChild As Integer, ByVal hWndNewParent As Integer)
Private Declare Sub apiSetWindowPos Lib "user" Alias "SetWindowPos " (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer)
Private Declare Sub apiSetWindowText Lib "user" Alias "SetWindowText" (ByVal hwnd As Integer, ByVal lpString As String)
' are those indexes supposed to be long?
Private Declare Function apiSetWindowLong% Lib "user" Alias "SetWindowLong" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
Private Declare Function apiSetWindowWord% Lib "user" Alias "SetWindowWord" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal wNewWord As Integer)
Private Declare Sub apiShowOwnedPopups Lib "user" Alias "ShowOwnedPopups" (ByVal hwnd As Integer, ByVal fshow As Integer)
Private Declare Function apiShowWindow% Lib "user" Alias "ShowWindow" (ByVal hwnd As Integer, ByVal nCmdShow As Integer)
'Function ShowWindowAsync is not available in the WIN16 API.
Private Declare Sub apiValidateRect Lib "user" (ByVal hwnd As Integer, lpRect As RECT)
Private Declare Sub apiValidateRectBynum Lib "user" Alias "ValidateRect" (ByVal hwnd As Integer, ByVal lpRect As Long)
Private Declare Function apiArrangeIconicWindows% Lib "user" Alias "ArrangeIconicWindows" (ByVal hwnd As Integer)
Private Declare Sub apiBringWindowToTop Lib "user" Alias "BringWindowToTop " (ByVal hwnd As Integer)
Private Declare Function apiChildWindowFromPoint% Lib "user" Alias "ChildWindowFromPoint" (ByVal hwnd As Integer, ByVal pnt As Any)
'Function ChildWindowFromPointEx is not available in the WIN16 API.
Private Declare Function apiGetClassName% Lib "user" Alias "GetClassName" (ByVal hwnd As Integer, ByVal lpClassName As String, ByVal nMaxCount As Integer)
Private Declare Function apiFlashWindow% Lib "user" Alias "FlashWindow" (ByVal hwnd As Integer, ByVal bInvert As Integer)
Private Declare Function apiEnableWindow% Lib "user" Alias "EnableWindow" (ByVal hwnd As Integer, ByVal aBOOL As Integer)
Private Declare Sub apiCloseWindow Lib "user" Alias "CloseWindow" (ByVal hwnd As Integer)
Private Declare Function apiDestroyWindow% Lib "user" Alias "DestroyWindow" (ByVal hwnd As Integer)
Private Declare Sub apiClientToScreen Lib "user" Alias "ClientToScreen" (ByVal hwnd As Integer, lpPoint As POINTAPI)
Private Declare Function apiWindowFromPoint% Lib "user" Alias "WindowFromPoint" (ByVal pnt As Any)
Private Declare Function apiGetClientRect% Lib "user" Alias "GetClientRect" (ByVal hwnd As Integer, lpRect As RECT)
Private Declare Function apiGetWindowText% Lib "user" Alias "GetWindowText" (ByVal hwnd As Integer, ByVal lpString As String, ByVal aint As Integer)
Private Declare Function apiGetWindowTextLength% Lib "user" Alias "GetWindowTextLength" (ByVal hwnd As Integer)
Private Declare Function apiIsWindow% Lib "user" Alias "IsWindow" (ByVal hwnd As Integer)
Private Declare Sub apiUpdateWindow Lib "user" Alias "UpdateWindow" (ByVal hwnd As Integer)
Private Declare Function apiGetClassLong& Lib "user" Alias "GetClassLong" (ByVal hwnd As Integer, ByVal nIndex As Integer)
Private Declare Function apiInvalidateRgn% Lib "user" Alias "InvalidateRgn" (ByVal hwnd As Integer, ByVal hRgn As Integer, ByVal bErase As Integer)
Private Declare Function apiSendMessage& Lib "user" Alias "SendMessage" (ByVal hwnd As Integer, ByVal nMsg As Integer, ByVal wParam As Integer, ByVal lParam As Long)
Private Declare Sub apiDragAcceptFiles Lib "shell.dll" Alias "DragAcceptFiles" (ByVal hwnd As Integer, ByVal accept As Boolean)
#End If 'WIN16
Private Sub RaiseWinError(Optional errval)
If IsMissing(errval) Then
RaiseError DWERR_APIRESULT, "dwWindow"
Else
RaiseError errval, "dwWindow"
End If
End Sub
Public Property Get hwnd() As Long
hwnd = iHwnd
End Property
Public Property Let hwnd(vNewValue As Long)
Dim tmpDwRect As New dwRECT
If vNewValue = 0 Then
iHwnd = vNewValue
Exit Property
End If
If apiIsWindow(vNewValue) = 0 Then
RaiseWinError 380
Exit Property
End If
iHwnd = vNewValue
Set tmpDwRect = GetWindowRect()
iLeft = tmpDwRect.left
iTop = tmpDwRect.top
iWidth = tmpDwRect.right - tmpDwRect.left
iHeight = tmpDwRect.bottom - tmpDwRect.top
Set tmpDwRect = Nothing
End Property
Public Sub BringWindowToTop()
Attribute BringWindowToTop.VB_HelpID = 2804
Attribute BringWindowToTop.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
Dim ret&
If iHwnd = 0 Then RaiseWinError DWERR_UNINITIALIZED
#If Win32 Then
ret& = apiBringWindowToTop(iHwnd)
If ret& = 0 Then RaiseWinError
#Else
apiBringWindowToTop iHwnd
#End If
End Sub
Public Function GetWindowTextLength() As Long
Attribute GetWindowTextLength.VB_HelpID = 2953
Attribute GetWindowTextLength.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
If iHwnd = 0 Then RaiseWinError DWERR_UNINITIALIZED
' lprcScroll As dwRECT, lprcClip As dwRECT, hRgnUpdate As dwRegion, lprcUpdate As dwRECT, fuScroll as long
Public Sub ScrollWindowEx(ByVal dx As Long, ByVal dy As Long, Optional lprcScroll As Variant, Optional lprcClip As Variant, Optional hRgnUpdate As Variant, Optional lprcUpdate As Variant, Optional fuScroll As Variant)
Attribute ScrollWindowEx.VB_HelpID = 2941
Attribute ScrollWindowEx.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
Dim ret&
Dim tempRect1 As RECT
Dim tempRect2 As RECT
Dim tempRect3 As RECT
Dim tempflags As Long
If iHwnd = 0 Then RaiseWinError DWERR_UNINITIALIZED