VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "dwDeviceContext"
Attribute VB_Creatable = True
Attribute VB_Exposed = True
Option Explicit

' Class dwDeviceContext
' Device context object control and configuration class
' Copyright (c) 1996 by Desaware Inc.
' Part of the Desaware API Classes Library

' 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 FlagBitmap = True ' uses dwBitmap
#Const FlagGetDeviceCaps = True ' uses dwDevCaps
#Const FlagPlayEnhMetaFileRecord = True ' uses dwHandleTable and dwEnhMetaRecord
#Const FlagMetaFile = True ' all functions that use dwMetafile

' A number of functions require a group of data in a single
' parameter.  This task is traditionally handled by an array.
' Visual Basic 4.0 has a new data type called a Collection.
' This class library uses Collections, but if you prefer
' arrays, or your program uses arrays extensivly, then setting
' this flag to True will switch those functions to their
' array-using equivalents.
#Const FlagUseArrayNotCollection = False


#If Win32 Then
Private iHDC As Long
#Else
Private iHDC As Integer
#End If

' Who owns this DC?
' 0 - This DC is via GetDC
' 1 - This DC is via CreateDC or CreateCompatibleDC
' 2 - This DC is via direct setting
' 3 - This DC is a regular metafile
' 4 - This DC is an enhanced metafile
Public DCsource%

Public DeviceCaps As New dwDevCaps

' Currently selected objects
Private iCurrentBrush As dwBrush
Private iCurrentPen As dwPen

Private OriginalBrush As Long
Private OriginalPen As Long

#If FlagBitmap Then
Private OriginalBitmap As Long
Private iCurrentBitmap As dwBitmap
#End If

' InitialSaveDC - On assign or GetDC we do an initial SaveDC
' to store original VB state. This also makes sure
' all objects are selected out when we delete/destroy the DC
Private InitialSaveDC As Long

' Which window (if any) owns this device context?
Private objwnd As dwWindow


'**  Functions Chapter 7 Index

#If Win32 Then
Private Declare Function apiCreateCompatibleDC& Lib "gdi32" Alias "CreateCompatibleDC" (ByVal hDC As Long)
Private Declare Function apiCreateDC& Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As DEVMODE)
Private Declare Function apiCreateDCByVal& Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As Long)
Private Declare Function apiCreateDCBynum& Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As Long)
Private Declare Function apiDeleteDC& Lib "gdi32" Alias "DeleteDC" (ByVal hDC As Long)
Private Declare Function apiDPtoLP& Lib "gdi32" Alias "DPtoLP" (ByVal hDC As Long, lpPoint As POINTAPI, ByVal nCount As Long)
Private Declare Function apiExcludeClipRect& Lib "gdi32" Alias "ExcludeClipRect" (ByVal hDC As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long)
Private Declare Function apiExcludeUpdateRgn& Lib "user32" Alias "ExcludeUpdateRgn" (ByVal hDC As Long, ByVal hwnd As Long)
Private Declare Function apiExtSelectClipRgn& Lib "gdi32" Alias "ExtSelectClipRgn" (ByVal hDC As Long, ByVal hRgn As Long, ByVal fnMode As Long)
Private Declare Function apiFillRgn& Lib "gdi32" Alias "FillRgn" (ByVal hDC As Long, ByVal hRgn As Long, ByVal hBrush As Long)
Private Declare Function apiFrameRgn& Lib "gdi32" Alias "FrameRgn" (ByVal hDC As Long, ByVal hRgn As Long, ByVal hBrush As Long, ByVal nWidth As Long, ByVal nHeight As Long)
Private Declare Function apiGetBoundsRect& Lib "gdi32" Alias "GetBoundsRect" (ByVal hDC As Long, lprcBounds As RECT, ByVal Flags As Long)
Private Declare Function apiGetClipBox& Lib "gdi32" Alias "GetClipBox" (ByVal hDC As Long, lpRect As RECT)
Private Declare Function apiGetClipRgn& Lib "gdi32" Alias "GetClipRgn" (ByVal hDC As Long, ByVal hRgn As Long)
Private Declare Function apiGetDCOrgEx& Lib "gdi32" Alias "GetDCOrgEx" (ByVal hDC As Long, lpPoint As POINTAPI)
Private Declare Function apiGetDeviceCaps& Lib "gdi32" Alias "GetDeviceCaps" (ByVal hDC As Long, ByVal nIndex As Long)
Private Declare Function apiGetMapMode& Lib "gdi32" Alias "GetMapMode" (ByVal hDC As Long)
Private Declare Function apiGetRgnBox& Lib "gdi32" Alias "GetRgnBox" (ByVal hRgn As Long, lpRect As RECT)
Private Declare Function apiGetUpdateRgn& Lib "user32" Alias "GetUpdateRgn" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal fErase As Long)
Private Declare Function apiGetViewportExtEx& Lib "gdi32" Alias "GetViewportExtEx" (ByVal hDC As Long, lpSize As SIZE)
Private Declare Function apiGetViewportOrgEx& Lib "gdi32" Alias "GetViewportOrgEx" (ByVal hDC As Long, lpPoint As POINTAPI)
Private Declare Function apiGetWindowDC& Lib "user32" Alias "GetWindowDC" (ByVal hwnd As Long)
Private Declare Function apiGetWindowExtEx& Lib "gdi32" Alias "GetWindowExtEx" (ByVal hDC As Long, lpSize As SIZE)
Private Declare Function apiGetWindowOrgEx& Lib "gdi32" Alias "GetWindowOrgEx" (ByVal hDC As Long, lpPoint As POINTAPI)
Private Declare Function apiIntersectClipRect& Lib "gdi32" Alias "IntersectClipRect" (ByVal hDC As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long)
Private Declare Function apiInvertRgn& Lib "gdi32" Alias "InvertRgn" (ByVal hDC As Long, ByVal hRgn As Long)
Private Declare Function apiLPtoDP& Lib "gdi32" Alias "LPtoDP" (ByVal hDC As Long, lpPoint As POINTAPI, ByVal nCount As Long)
Private Declare Function apiOffsetClipRgn& Lib "gdi32" Alias "OffsetClipRgn" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long)
Private Declare Function apiOffsetViewportOrgEx& Lib "gdi32" Alias "OffsetViewportOrgEx" (ByVal hDC As Long, ByVal nX As Long, ByVal nY As Long, lpPoint As POINTAPI)
Private Declare Function apiOffsetWindowOrgEx& Lib "gdi32" Alias "OffsetWindowOrgEx" (ByVal hDC As Long, ByVal nX As Long, ByVal nY As Long, lpPoint As POINTAPI)
Private Declare Function apiPaintRgn& Lib "gdi32" Alias "PaintRgn" (ByVal hDC As Long, ByVal hRgn As Long)
Private Declare Function apiPtVisible& Lib "gdi32" Alias "PtVisible" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long)
Private Declare Function apiRectVisible& Lib "gdi32" Alias "RectVisible" (ByVal hDC As Long, lpRect As RECT)
Private Declare Function apiRestoreDC& Lib "gdi32" Alias "RestoreDC" (ByVal hDC As Long, ByVal nSavedDC As Long)
Private Declare Function apiSaveDC& Lib "gdi32" Alias "SaveDC" (ByVal hDC As Long)
Private Declare Function apiScaleViewportExtEx& Lib "gdi32" Alias "ScaleViewportExtEx" (ByVal hDC As Long, ByVal nXnum As Long, ByVal nXdenom As Long, ByVal nYnum As Long, ByVal nYdenom As Long, lpSize As SIZE)
Private Declare Function apiScaleWindowExtEx& Lib "gdi32" Alias "ScaleWindowExtEx" (ByVal hDC As Long, ByVal nXnum As Long, ByVal nXdenom As Long, ByVal nYnum As Long, ByVal nYdenom As Long, lpSize As SIZE)
Private Declare Function apiScrollDC& Lib "user32" Alias "ScrollDC" (ByVal hDC As Long, ByVal dx As Long, ByVal dy As Long, lprcScroll As RECT, lprcClip As RECT, ByVal hRgnUpdate As Long, lprcUpdate As RECT)
Private Declare Function apiSelectClipRgn& Lib "gdi32" Alias "SelectClipRgn" (ByVal hDC As Long, ByVal hRgn As Long)
Private Declare Function apiSetBoundsRect& Lib "gdi32" Alias "SetBoundsRect" (ByVal hDC As Long, lprcBounds As RECT, ByVal Flags As Long)
Private Declare Function apiSetMapMode& Lib "gdi32" Alias "SetMapMode" (ByVal hDC As Long, ByVal nMapMode As Long)
Private Declare Function apiSetViewportExtEx& Lib "gdi32" Alias "SetViewportExtEx" (ByVal hDC As Long, ByVal nX As Long, ByVal nY As Long, lpSize As SIZE)
Private Declare Function apiSetViewportOrgEx& Lib "gdi32" Alias "SetViewportOrgEx" (ByVal hDC As Long, ByVal nX As Long, ByVal nY As Long, lpPoint As POINTAPI)
Private Declare Function apiSetWindowExtEx& Lib "gdi32" Alias "SetWindowExtEx" (ByVal hDC As Long, ByVal nX As Long, ByVal nY As Long, lpSize As SIZE)
Private Declare Function apiSetWindowOrgEx& Lib "gdi32" Alias "SetWindowOrgEx" (ByVal hDC As Long, ByVal nX As Long, ByVal nY As Long, lpPoint As POINTAPI)
Private Declare Function apiWindowFromDC& Lib "user32" Alias "WindowFromDC" (ByVal hDC As Long)
#Else
Private Declare Function apiCreateCompatibleDC% Lib "gdi" Alias "CreateCompatibleDC" (ByVal hDC As Integer)
Private Declare Function apiCreateDC% Lib "gdi" Alias "CreateDC" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As Long)
Private Declare Function apiCreateDCByVal% Lib "gdi" Alias "CreateDC" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As Long)
Private Declare Function apiDeleteDC% Lib "gdi" Alias "DeleteDC" (ByVal hDC As Integer)
Private Declare Function apiDPtoLP% Lib "gdi" Alias "DPtoLP" (ByVal hDC As Integer, lpPoints As POINTAPI, ByVal nCount As Integer)
Private Declare Function apiExcludeClipRect% Lib "gdi" Alias "ExcludeClipRect" (ByVal hDC As Integer, ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer)
Private Declare Function apiExcludeUpdateRgn% Lib "user" Alias "ExcludeUpdateRgn" (ByVal hDC As Integer, ByVal hwnd As Integer)
'Function ExtSelectClipRgn is not available in the WIN16 API.
Private Declare Function apiFillRgn% Lib "gdi" Alias "FillRgn" (ByVal hDC As Integer, ByVal hRgn As Integer, ByVal hBrush As Integer)
Private Declare Function apiFrameRgn% Lib "gdi" Alias "FrameRgn" (ByVal hDC As Integer, ByVal hRgn As Integer, ByVal hBrush As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer)
Private Declare Function apiGetBoundsRect% Lib "gdi" Alias "GetBoundsRect" (ByVal hDC As Integer, lprcBounds As RECT, ByVal Flags As Integer)
Private Declare Function apiGetClipBox% Lib "gdi" Alias "GetClipBox" (ByVal hDC As Integer, lpRect As RECT)
'Function GetClipRgn is not available in the WIN16 API.
'Function GetDCOrgEx is not available in the WIN16 API.
Private Declare Function apiGetDeviceCaps% Lib "gdi" Alias "GetDeviceCaps" (ByVal hDC As Integer, ByVal nIndex As Integer)
Private Declare Function apiGetMapMode% Lib "gdi" Alias "GetMapMode" (ByVal hDC As Integer)
Private Declare Function apiGetRgnBox% Lib "gdi" Alias "GetRgnBox" (ByVal hRgn As Integer, lpRect As RECT)
Private Declare Function apiGetUpdateRgn% Lib "user" Alias "GetUpdateRgn" (ByVal hwnd As Integer, ByVal hRgn As Integer, ByVal fErase As Integer)
Private Declare Function apiGetViewportExtEx% Lib "gdi" Alias "GetViewportExtEx" (ByVal hDC As Integer, lpSize As SIZE)
Private Declare Function apiGetViewportOrgEx% Lib "gdi" Alias "GetViewportOrgEx" (ByVal hDC As Integer, lpSize As SIZE)
Private Declare Function apiGetWindowDC% Lib "user" Alias "GetWindowDC" (ByVal hwnd As Integer)
Private Declare Function apiGetWindowExtEx% Lib "gdi" Alias "GetWindowExtEx" (ByVal hDC As Integer, lpSize As SIZE)
Private Declare Function apiGetWindowOrgEx% Lib "gdi" Alias "GetWindowOrgEx" (ByVal hDC As Integer, lpSize As SIZE)
Private Declare Function apiIntersectClipRect% Lib "gdi" Alias "IntersectClipRect" (ByVal hDC As Integer, ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer)
Private Declare Function apiInvertRgn% Lib "gdi" Alias "InvertRgn" (ByVal hDC As Integer, ByVal hRgn As Integer)
Private Declare Function apiLPtoDP% Lib "gdi" Alias "LPtoDP" (ByVal hDC As Integer, lpPoints As POINTAPI, ByVal nCount As Integer)
Private Declare Function apiOffsetClipRgn% Lib "gdi" Alias "OffsetClipRgn" (ByVal hDC As Integer, ByVal x As Integer, ByVal y As Integer)
Private Declare Function apiOffsetViewportOrgEx% Lib "gdi" Alias "OffsetViewportOrgEx" (ByVal hDC As Integer, ByVal x As Integer, ByVal y As Integer, lpPoint As POINTAPI)
Private Declare Function apiOffsetWindowOrgEx% Lib "gdi" Alias "OffsetWindowOrgEx" (ByVal hDC As Integer, ByVal x As Integer, ByVal y As Integer, lpPoint As POINTAPI)
Private Declare Function apiPaintRgn% Lib "gdi" Alias "PaintRgn" (ByVal hDC As Integer, ByVal hRgn As Integer)
Private Declare Function apiPtVisible% Lib "gdi" Alias "PtVisible" (ByVal hDC As Integer, ByVal x As Integer, ByVal y As Integer)
Private Declare Function apiRectVisible% Lib "gdi" Alias "RectVisible" (ByVal hDC As Integer, lpRect As RECT)
Private Declare Function apiRestoreDC% Lib "gdi" Alias "RestoreDC" (ByVal hDC As Integer, ByVal nSavedDC As Integer)
Private Declare Function apiSaveDC% Lib "gdi" Alias "SaveDC" (ByVal hDC As Integer)
Private Declare Function apiScaleViewportExtEx& Lib "gdi" Alias "ScaleViewportExtEx" (ByVal hDC As Integer, ByVal nXnum As Integer, ByVal nXdenom As Integer, ByVal nYnum As Integer, ByVal nYdenom As Integer, lpSize As SIZE)
Private Declare Function apiScaleWindowExtEx& Lib "gdi" Alias "ScaleWindowExtEx" (ByVal hDC As Integer, ByVal nXnum As Integer, ByVal nXdenom As Integer, ByVal nYnum As Integer, ByVal nYdenom As Integer, lpSize As SIZE)
Private Declare Function apiScrollDC% Lib "user" Alias "ScrollDC" (ByVal hDC As Integer, ByVal dx As Integer, ByVal dy As Integer, lprcScroll As RECT, lprcClip As RECT, ByVal hRgnUpdate As Integer, lprcUpdate As RECT)
Private Declare Function apiSelectClipRgn% Lib "gdi" Alias "SelectClipRgn" (ByVal hDC As Integer, ByVal hRgn As Integer)
Private Declare Function apiSetBoundsRect% Lib "gdi" Alias "SetBoundsRect" (ByVal hDC As Integer, lprcBounds As RECT, ByVal Flags As Integer)
Private Declare Function apiSetMapMode% Lib "gdi" Alias "SetMapMode" (ByVal hDC As Integer, ByVal nMapMode As Integer)
Private Declare Function apiSetViewportExtEx% Lib "gdi" Alias "SetViewportExtEx" (ByVal hDC As Integer, ByVal nX As Integer, ByVal nY As Integer, lpSize As SIZE)
Private Declare Function apiSetViewportOrgEx% Lib "gdi" Alias "SetViewportOrgEx" (ByVal hDC As Integer, ByVal x As Integer, ByVal y As Integer, lpSize As SIZE)
Private Declare Function apiSetWindowExtEx% Lib "gdi" Alias "SetWindowExtEx" (ByVal hDC As Integer, ByVal x As Integer, ByVal y As Integer, lpSize As SIZE)
Private Declare Function apiSetWindowOrgEx% Lib "gdi" Alias "SetWindowOrgEx" (ByVal hDC As Integer, ByVal x As Integer, ByVal y As Integer, lpSize As SIZE)
'Function WindowFromDC is not available in the WIN16 API.
#End If 'WIN32

'**Functions Chapter 8 Reference

#If Win32 Then
Private Declare Function apiDrawEdge& Lib "user32" Alias "DrawEdge" (ByVal hDC As Long, qrc As RECT, ByVal edge As Long, ByVal grfFlags As Long)
Private Declare Function apiGetBrushOrgEx& Lib "gdi32" Alias "GetBrushOrgEx" (ByVal hDC As Long, lpPoint As POINTAPI)
Private Declare Function apiPaintDesktop Lib "user32" Alias "PaintDesktop" (ByVal hDC As Long)
Private Declare Function apiSelectClipPath& Lib "gdi32" Alias "SelectClipPath" (ByVal hDC As Long, ByVal iMode As Long)
Private Declare Function apiAbortPath& Lib "gdi32" Alias "AbortPath" (ByVal hDC As Long)
Private Declare Function apiAngleArc& Lib "gdi32" Alias "AngleArc" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal dwRadius As Long, ByVal eStartAngle As Double, ByVal eSweepAngle As Double)
Private Declare Function apiArc& Lib "gdi32" Alias "Arc" (ByVal hDC As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long, ByVal X3 As Long, ByVal Y3 As Long, ByVal X4 As Long, ByVal Y4 As Long)
Private Declare Function apiArcTo& Lib "gdi32" Alias "ArcTo" (ByVal hDC As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long, ByVal X3 As Long, ByVal Y3 As Long, ByVal X4 As Long, ByVal Y4 As Long)
Private Declare Function apiBeginPath& Lib "gdi32" Alias "BeginPath" (ByVal hDC As Long)
Private Declare Function apiCancelDC& Lib "gdi32" Alias "CancelDC" (ByVal hDC As Long)
Private Declare Function apiChord& Lib "gdi32" Alias "Chord" (ByVal hDC As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long, ByVal X3 As Long, ByVal Y3 As Long, ByVal X4 As Long, ByVal Y4 As Long)
Private Declare Function apiCloseEnhMetaFile& Lib "gdi32" Alias "CloseEnhMetaFile" (ByVal hDC As Long)
Private Declare Function apiCloseMetaFile& Lib "gdi32" Alias "CloseMetaFile" (ByVal hMF As Long)
Private Declare Function apiCloseFigure& Lib "gdi32" Alias "CloseFigure" (ByVal hDC As Long)
Private Declare Function apiCopyEnhMetaFile& Lib "gdi32" Alias "CopyEnhMetaFileA" (ByVal hemfSrc As Long, ByVal lpszFile As String)
Private Declare Function apiCreateEnhMetaFile& Lib "gdi32" Alias "CreateEnhMetaFileA" (ByVal hdcRef As Long, ByVal lpFileName As String, lpRect As RECT, ByVal lpDescription As String)
Private Declare Function apiDeleteEnhMetaFile& Lib "gdi32" Alias "DeleteEnhMetaFile" (ByVal hemf As Long)
Private Declare Function apiDeleteMetaFile& Lib "gdi32" Alias "DeleteMetaFile" (ByVal hMF As Long)
Private Declare Function apiDeleteObject& Lib "gdi32" Alias "DeleteObject" (ByVal hObject As Long)
Private Declare Function apiDrawEscape& Lib "gdi32" Alias "DrawEscape" (ByVal hDC As Long, ByVal nEscape As Long, ByVal cbInput As Long, ByVal lpszInData As String)
Private Declare Function apiDrawFocusRect& Lib "user32" Alias "DrawFocusRect" (ByVal hDC As Long, lpRect As RECT)
Private Declare Function apiEllipse& Lib "gdi32" Alias "Ellipse" (ByVal hDC As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long)
Private Declare Function apiEndPath& Lib "gdi32" Alias "EndPath" (ByVal hDC As Long)
Private Declare Function apiExtFloodFill& Lib "gdi32" Alias "ExtFloodFill" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long, ByVal wFillType As Long)
Private Declare Function apiFillPath& Lib "gdi32" Alias "FillPath" (ByVal hDC As Long)
Private Declare Function apiFillRect& Lib "user32" Alias "FillRect" (ByVal hDC As Long, lpRect As RECT, ByVal hBrush As Long)
Private Declare Function apiFlattenPath& Lib "gdi32" Alias "FlattenPath" (ByVal hDC As Long)
Private Declare Function apiFloodFill& Lib "gdi32" Alias "FloodFill" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long)
Private Declare Function apiFrameRect& Lib "user32" Alias "FrameRect" (ByVal hDC As Long, lpRect As RECT, ByVal hBrush As Long)
Private Declare Function apiGdiComment& Lib "gdi32" Alias "GdiComment" (ByVal hDC As Long, ByVal cbSize As Long, lpData As Byte)
Private Declare Function apiGetArcDirection& Lib "gdi32" Alias "GetArcDirection" (ByVal hDC As Long)
Private Declare Function apiGetBkColor& Lib "gdi32" Alias "GetBkColor" (ByVal hDC As Long)
Private Declare Function apiGetBkMode& Lib "gdi32" Alias "GetBkMode" (ByVal hDC As Long)
Private Declare Function apiGetCurrentPositionEx& Lib "gdi32" Alias "GetCurrentPositionEx" (ByVal hDC As Long, lpPoint As POINTAPI)
Private Declare Function apiGetMiterLimit& Lib "gdi32" Alias "GetMiterLimit" (ByVal hDC As Long, peLimit As Single)
Private Declare Function apiGetNearestColor& Lib "gdi32" Alias "GetNearestColor" (ByVal hDC As Long, ByVal crColor As Long)
Private Declare Function apiGetPath& Lib "gdi32" Alias "GetPath" (ByVal hDC As Long, lpPoint As POINTAPI, lpTypes As Byte, ByVal nSize As Long)
Private Declare Function apiGetPixel& Lib "gdi32" Alias "GetPixel" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long)
Private Declare Function apiGetPolyFillMode& Lib "gdi32" Alias "GetPolyFillMode" (ByVal hDC As Long)
Private Declare Function apiGetROP2& Lib "gdi32" Alias "GetROP2" (ByVal hDC As Long)
Private Declare Function apiInvertRect& Lib "user32" Alias "InvertRect" (ByVal hDC As Long, lpRect As RECT)
Private Declare Function apiLineTo& Lib "gdi32" Alias "LineTo" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long)
Private Declare Function apiMoveToEx& Lib "gdi32" Alias "MoveToEx" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI)
Private Declare Function apiPathToRegion& Lib "gdi32" Alias "PathToRegion" (ByVal hDC As Long)
Private Declare Function apiPie& Lib "gdi32" Alias "Pie" (ByVal hDC As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long, ByVal X3 As Long, ByVal Y3 As Long, ByVal X4 As Long, ByVal Y4 As Long)
Private Declare Function apiPlayEnhMetaFile& Lib "gdi32" Alias "PlayEnhMetaFile" (ByVal hDC As Long, ByVal hemf As Long, lpRect As RECT)
Private Declare Function apiPlayEnhMetaFileRecord& Lib "gdi32" Alias "PlayEnhMetaFileRecord" (ByVal hDC As Long, lpHandleTable As HANDLETABLE, lpEnhMetaRecord As ENHMETARECORD, ByVal nHandles As Long)
Private Declare Function apiPlayMetaFile& Lib "gdi32" Alias "PlayMetaFile" (ByVal hDC As Long, ByVal hMF As Long)
Private Declare Function apiPolyBezier& Lib "gdi32" Alias "PolyBezier" (ByVal hDC As Long, lppt As POINTAPI, ByVal cPoints As Long)
Private Declare Function apiPolyBezierTo& Lib "gdi32" Alias "PolyBezierTo" (ByVal hDC As Long, lppt As POINTAPI, ByVal cCount As Long)
Private Declare Function apiPolyDraw& Lib "gdi32" Alias "PolyDraw" (ByVal hDC As Long, lppt As POINTAPI, lpbTypes As Byte, ByVal cCount As Long)
Private Declare Function apiPolygon& Lib "gdi32" Alias "Polygon" (ByVal hDC As Long, lpPoint As POINTAPI, ByVal nCount As Long)
Private Declare Function apiPolyline& Lib "gdi32" Alias "Polyline" (ByVal hDC As Long, lpPoint As POINTAPI, ByVal nCount As Long)
Private Declare Function apiPolylineTo& Lib "gdi32" Alias "PolylineTo" (ByVal hDC As Long, lppt As POINTAPI, ByVal cCount As Long)
Private Declare Function apiPolyPolyline& Lib "gdi32" Alias "PolyPolyline" (ByVal hDC As Long, lppt As POINTAPI, lpdwPolyPoints As Long, ByVal cCount As Long)
Private Declare Function apiRectangle& Lib "gdi32" Alias "Rectangle" (ByVal hDC As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long)
Private Declare Function apiRoundRect& Lib "gdi32" Alias "RoundRect" (ByVal hDC As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long, ByVal X3 As Long, ByVal Y3 As Long)
Private Declare Function apiSetBkColor& Lib "gdi32" Alias "SetBkColor" (ByVal hDC As Long, ByVal crColor As Long)
Private Declare Function apiSetArcDirection& Lib "gdi32" Alias "SetArcDirection" (ByVal hDC As Long, ByVal ArcDirection As Long)
Private Declare Function apiSetBkMode& Lib "gdi32" Alias "SetBkMode" (ByVal hDC As Long, ByVal nBkMode As Long)
Private Declare Function apiSetBrushOrgEx& Lib "gdi32" Alias "SetBrushOrgEx" (ByVal hDC As Long, ByVal nXOrg As Long, ByVal nYOrg As Long, lppt As POINTAPI)
Private Declare Function apiSetMiterLimit& Lib "gdi32" Alias "SetMiterLimit" (ByVal hDC As Long, ByVal eNewLimit As Single, peOldLimit As Single)
Private Declare Function apiSetPixel& Lib "gdi32" Alias "SetPixel" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long)
Private Declare Function apiSetPixelV& Lib "gdi32" Alias "SetPixelV" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long)
Private Declare Function apiSetPolyFillMode& Lib "gdi32" Alias "SetPolyFillMode" (ByVal hDC As Long, ByVal nPolyFillMode As Long)
Private Declare Function apiSetROP2& Lib "gdi32" Alias "SetROP2" (ByVal hDC As Long, ByVal nDrawMode As Long)
Private Declare Function apiStrokeAndFillPath& Lib "gdi32" Alias "StrokeAndFillPath" (ByVal hDC As Long)
Private Declare Function apiStrokePath& Lib "gdi32" Alias "StrokePath" (ByVal hDC As Long)
Private Declare Function apiWidenPath& Lib "gdi32" Alias "WidenPath" (ByVal hDC As Long)
#Else
'Function AbortPath is not available in the WIN16 API.
'Function AngleArc is not available in the WIN16 API.
Private Declare Function apiGetBrushOrgEx% Lib "gdi32" Alias "GetBrushOrgEx" (ByVal hDC As Integer, lpPoint As POINTAPI)
Private Declare Function apiArc% Lib "gdi" Alias "Arc" (ByVal hDC As Integer, ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer, ByVal X3 As Integer, ByVal Y3 As Integer, ByVal X4 As Integer, ByVal Y4 As Integer)
Private Declare Function apiChord% Lib "gdi" Alias "Chord" (ByVal hDC As Integer, ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer, ByVal X3 As Integer, ByVal Y3 As Integer, ByVal X4 As Integer, ByVal Y4 As Integer)
Private Declare Function apiCloseMetaFile% Lib "gdi" Alias "CloseMetaFile" (ByVal hMF As Integer)
Private Declare Function apiDeleteMetaFile% Lib "gdi" Alias "DeleteMetaFile" (ByVal hMF As Integer)
Private Declare Function apiDeleteObject% Lib "gdi" Alias "DeleteObject" (ByVal hObject As Integer)
Private Declare Sub apiDrawFocusRect Lib "user" Alias "DrawFocusRect" (ByVal hDC As Integer, lpRect As RECT)
Private Declare Function apiEllipse% Lib "gdi" Alias "Ellipse" (ByVal hDC As Integer, ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer)
Private Declare Function apiExtFloodFill% Lib "gdi" Alias "ExtFloodFill" (ByVal hDC As Integer, ByVal x As Integer, ByVal y As Integer, ByVal crColor As Long, ByVal wFillType As Integer)
Private Declare Function apiFillRect% Lib "user" Alias "FillRect" (ByVal hDC As Integer, lpRect As RECT, ByVal hBrush As Integer)
Private Declare Function apiFloodFill% Lib "gdi" Alias "FloodFill" (ByVal hDC As Integer, ByVal x As Integer, ByVal y As Integer, ByVal crColor As Long)
Private Declare Function apiFrameRect% Lib "user" Alias "FrameRect" (ByVal hDC As Integer, lpRect As RECT, ByVal hBrush As Integer)
Private Declare Function apiGetBkColor& Lib "gdi" Alias "GetBkColor" (ByVal hDC As Integer)
Private Declare Function apiGetBkMode% Lib "gdi" Alias "GetBkMode" (ByVal hDC As Integer)
Private Declare Function apiGetCurrentPositionEx% Lib "gdi" Alias "GetCurrentPositionEx" (ByVal hDC As Integer, lpPoint As POINTAPI)
Private Declare Function apiGetNearestColor& Lib "gdi" Alias "GetNearestColor" (ByVal hDC As Integer, ByVal crColor As Long)
Private Declare Function apiGetPixel& Lib "gdi" Alias "GetPixel" (ByVal hDC As Integer, ByVal x As Integer, ByVal y As Integer)
Private Declare Function apiGetPolyFillMode% Lib "gdi" Alias "GetPolyFillMode" (ByVal hDC As Integer)
Private Declare Function apiGetROP2% Lib "gdi" Alias "GetROP2" (ByVal hDC As Integer)
Private Declare Sub apiInvertRect Lib "user" Alias "InvertRect" (ByVal hDC As Integer, lpRect As RECT)
Private Declare Function apiLineTo% Lib "gdi" Alias "LineTo" (ByVal hDC As Integer, ByVal x As Integer, ByVal y As Integer)
Private Declare Function apiMoveTo& Lib "gdi" Alias "MoveTo" (ByVal hDC As Integer, ByVal x As Integer, ByVal y As Integer)
Private Declare Function apiMoveToEx% Lib "gdi" Alias "MoveToEx" (ByVal hDC As Integer, ByVal nX As Integer, ByVal nY As Integer, lpPoint As POINTAPI)
Private Declare Function apiPie% Lib "gdi" Alias "Pie" (ByVal hDC As Integer, ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer, ByVal X3 As Integer, ByVal Y3 As Integer, ByVal X4 As Integer, ByVal Y4 As Integer)
Private Declare Function apiPlayMetaFile% Lib "gdi" Alias "PlayMetaFile" (ByVal hDC As Integer, ByVal hMF As Integer)
Private Declare Function apiPolygon% Lib "gdi" Alias "Polygon" (ByVal hDC As Integer, lpPoints As POINTAPI, ByVal nCount As Integer)
Private Declare Function apiPolyline% Lib "gdi" Alias "Polyline" (ByVal hDC As Integer, lpPoints As POINTAPI, ByVal nCount As Integer)
Private Declare Function apiRectangle% Lib "gdi" Alias "Rectangle" (ByVal hDC As Integer, ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer)
Private Declare Function apiRoundRect% Lib "gdi" Alias "RoundRect" (ByVal hDC As Integer, ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer, ByVal X3 As Integer, ByVal Y3 As Integer)
Private Declare Function apiSetBkColor& Lib "gdi" Alias "SetBkColor" (ByVal hDC As Integer, ByVal crColor As Long)
Private Declare Function apiSetBkMode% Lib "gdi" Alias "SetBkMode" (ByVal hDC As Integer, ByVal nBkMode As Integer)
Private Declare Function apiSetBrushOrg& Lib "gdi" Alias "SetBrushOrg" (ByVal hDC As Integer, ByVal nXOrg As Integer, ByVal nYOrg As Integer)
Private Declare Function apiSetPixel& Lib "gdi" Alias "SetPixel" (ByVal hDC As Integer, ByVal x As Integer, ByVal y As Integer, ByVal crColor As Long)
Private Declare Function apiSetPolyFillMode% Lib "gdi" Alias "SetPolyFillMode" (ByVal hDC As Integer, ByVal nPolyFillMode As Integer)
Private Declare Function apiSetROP2% Lib "gdi" Alias "SetROP2" (ByVal hDC As Integer, ByVal nDrawMode As Integer)
#End If 'WIN32


#If Win32 Then
Private Declare Function apiBitBlt& Lib "gdi32" Alias "BitBlt" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal XSrc As Long, ByVal YSrc As Long, ByVal dwRop As Long)
Private Declare Function apiMaskBlt& Lib "gdi32" Alias "MaskBlt" (ByVal hdcDest As Long, ByVal nXDest As Long, ByVal nYDest As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hdcSrc As Long, ByVal nXSrc As Long, ByVal nYSrc As Long, ByVal hbmMask As Long, ByVal xMask As Long, ByVal yMask As Long, ByVal dwRop As Long)
Private Declare Function apiPlgBlt& Lib "gdi32" Alias "PlgBlt" (ByVal hdcDest As Long, lpPoint As POINTAPI, ByVal hdcSrc As Long, ByVal nXSrc As Long, ByVal nYSrc As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hbmMask As Long, ByVal xMask As Long, ByVal yMask As Long)
Private Declare Function apiPatBlt& Lib "gdi32" Alias "PatBlt" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal dwRop As Long)
Private Declare Function apiStretchBlt& Lib "gdi32" Alias "StretchBlt" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal XSrc As Long, ByVal YSrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long)
Private Declare Function apiReleaseDC& Lib "user32" Alias "ReleaseDC" (ByVal hwnd As Long, ByVal hDC As Long)
Private Declare Function apiGetDC& Lib "user32" Alias "GetDC" (ByVal hwnd As Long)
Private Declare Function apiGetDCEx& Lib "user32" Alias "GetDCEx" (ByVal hwnd As Long, ByVal hrgnClip As Long, ByVal fdwOptions As Long)
Private Declare Function apiSelectObject& Lib "gdi32" Alias "SelectObject" (ByVal hDC As Long, ByVal hObject As Long)
Private Declare Function apiGetStockObject& Lib "gdi32" Alias "GetStockObject" (ByVal nIndex As Long)
#Else
Private Declare Function apiReleaseDC% Lib "user" Alias "ReleaseDC" (ByVal hwnd As Integer, ByVal hDC As Integer)
Private Declare Function apiGetDC% Lib "user" Alias "GetDC" (ByVal hwnd As Integer)
Private Declare Function apiGetDCEx% Lib "user" Alias "GetDCEx" (ByVal hwnd As Integer, ByVal hrgnClip As Integer, ByVal fdwOptions As Long)
Private Declare Function apiSelectObject% Lib "gdi" Alias "SelectObject" (ByVal hDC As Integer, ByVal hObject As Integer)
Private Declare Function apiGetStockObject% Lib "gdi" Alias "GetStockObject" (ByVal nIndex As Integer)
Private Declare Function apiBitBlt% Lib "gdi" Alias "BitBlt" (ByVal hDestDC As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal XSrc As Integer, ByVal YSrc As Integer, ByVal dwRop As Long)
Private Declare Function apiPatBlt% Lib "gdi" Alias "PatBlt" (ByVal hDC As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal dwRop As Long)
Private Declare Function apiStretchBlt% Lib "gdi" Alias "StretchBlt" (ByVal hDC As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal XSrc As Integer, ByVal YSrc As Integer, ByVal nSrcWidth As Integer, ByVal nSrcHeight As Integer, ByVal dwRop As Long)
#End If 'WIN32


Private Sub RaiseHdcError(Optional errval)
    Dim useerr%
    If IsMissing(errval) Then
        RaiseHdcError DWERR_APIRESULT
    Else
        RaiseError errval, "dwDeviceContext"
    End If
End Sub

' Clear out the current device context setting,
' deselecting any current objects
Private Sub ClearDC()
    
    If iHDC = 0 Then Exit Sub ' Already clear
    
    ' Clear selected objects
#If FlagBitmap = True Then
    SelectObjectBitmap Nothing
#End If
    SelectObjectBrush Nothing
    SelectObjectPen Nothing
    
    ' If we stored the initial state, restore now
    If InitialSaveDC <> 0 Then
        Call apiRestoreDC(iHDC, InitialSaveDC)
        InitialSaveDC = 0
    End If
    Select Case DCsource
        Case 0  ' GetDC
                Call apiReleaseDC(objwnd.hwnd, iHDC)
        Case 1  ' CreateDC
                Call apiDeleteDC(iHDC)
        Case 2  ' Assigment - Do nothing
        Case 3  ' Metafile: Kill it
                Call apiDeleteMetaFile(apiCloseMetaFile(iHDC))
        Case 4  ' Enhanced metafile - same as above
                #If Win32 Then
                    Call apiDeleteEnhMetaFile(apiCloseEnhMetaFile(iHDC))
                #Else
                    RaiseHdcError DWERR_NOTINWIN16
                #End If
    End Select
    iHDC = 0
    DCsource = -1
    Set objwnd = Nothing
        
End Sub

Public Property Get hDC() As Long
    hDC = iHDC
End Property

' Intended for direct setting from the hDC property
' of a form, picture control, printer object or metafile.
Public Property Let hDC(vNewValue As Long)
    If DCsource <> 3 Then ' if not a metafile
        If apiGetMapMode(vNewValue) = 0 Then RaiseHdcError 380
        DCsource = 2    ' Direct setting
        InitialSaveDC = apiSaveDC(iHDC)    ' Save initial state
        ClearDC         ' Clear existing DC info
    End If
    iHDC = vNewValue
    DeviceCaps.InitDevCaps iHDC
End Property

Public Property Get IsMetafile() As Boolean
    If DCsource = 3 Or DCsource = 4 Then IsMetafile = True
End Property

Private Sub Class_Terminate()
    ClearDC
End Sub

' Use GetDC on an existing window
Public Sub GetDC(wnd As dwWindow)
Attribute GetDC.VB_HelpID = 2922
Attribute GetDC.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    If wnd.hwnd = 0 Then RaiseHdcError 380
    ClearDC
    iHDC = apiGetDC(wnd.hwnd)
    DCsource = 0
    If iHDC = 0 Then RaiseHdcError DWERR_NODCAVAILABLE
    InitialSaveDC = apiSaveDC(iHDC)
    Set objwnd = wnd
    DeviceCaps.InitDevCaps iHDC
End Sub

Public Sub SelectObjectBrush(br As dwBrush)
    Dim oldBrush&
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    
    If br Is Nothing Then   ' Clear existing brush
        ' No brush selected
        If iCurrentBrush Is Nothing Then Exit Sub
        Call apiSelectObject(iHDC, OriginalBrush)
        Set iCurrentBrush = Nothing
    Else
        oldBrush = apiSelectObject(iHDC, br.hBrush)
        If OriginalBrush = 0 Then OriginalBrush = oldBrush
        Set iCurrentBrush = br
    End If
End Sub

#If FlagBitmap = True Then
Public Sub SelectObjectBitmap(bm As dwBitmap)
    Dim oldbitmap&
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    
    If bm Is Nothing Then   ' Clear existing bitmap
        ' No bitmap selected
        If iCurrentBitmap Is Nothing Then Exit Sub
        Call apiSelectObject(iHDC, OriginalBitmap)
        Set iCurrentBitmap = Nothing
    Else
        oldbitmap = apiSelectObject(iHDC, bm.hBitmap)
        If OriginalBitmap = 0 Then OriginalBitmap = oldbitmap
        Set iCurrentBitmap = bm
    End If
End Sub
#End If ' FlagBitmap

Public Sub SelectObjectPen(pn As dwPen)
    Dim oldPen&
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    
    If pn Is Nothing Then   ' Clear existing pen
        ' No pen selected
        If iCurrentPen Is Nothing Then Exit Sub
        Call apiSelectObject(iHDC, OriginalPen)
        Set iCurrentPen = Nothing
    Else
        oldPen = apiSelectObject(iHDC, pn.hPen)
        If OriginalPen = 0 Then OriginalPen = oldPen
        Set iCurrentPen = pn
    End If
End Sub

#If FlagMetaFile Then
Public Function CloseMetafile() As dwMetaFile
Attribute CloseMetafile.VB_HelpID = 2487
Attribute CloseMetafile.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim newMetafile As New dwMetaFile
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    If DCsource <> 3 And DCsource <> 4 Then RaiseHdcError DWERR_NOTMETAFILEDC
    
    newMetafile.InitializeMetafile apiCloseMetaFile(iHDC), False
    Set CloseMetafile = newMetafile
End Function
#End If ' FlagMetafile

#If FlagMetaFile Then
Public Function CloseEnhMetaFile() As dwMetaFile
Attribute CloseEnhMetaFile.VB_HelpID = 2639
Attribute CloseEnhMetaFile.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim newMetafile As New dwMetaFile
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    If ((DCsource = 3) Or (DCsource = 4)) Then RaiseHdcError DWERR_NOTMETAFILEDC
    
    newMetafile.InitializeMetafile apiCloseEnhMetaFile(iHDC), True
    Set CloseEnhMetaFile = newMetafile
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Function
#End If ' FlagMetafile

Public Function PathToRegion() As dwRegion
Attribute PathToRegion.VB_HelpID = 2697
Attribute PathToRegion.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim newRegion As New dwRegion
    
    newRegion.hRegion = apiPathToRegion(iHDC)
    If GetLastError <> 0 Then RaiseHdcError
    Set PathToRegion = newRegion
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Function

Public Function CreateCompatibleDC() As dwDeviceContext
Attribute CreateCompatibleDC.VB_HelpID = 2495
Attribute CreateCompatibleDC.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    Dim tmpHDC As New dwDeviceContext
    
    If iHDC = 0 Then RaiseHdcError
    
    ret& = apiCreateCompatibleDC(iHDC)
    If ret& = 0 Then RaiseHdcError
    tmpHDC.hDC = ret&
    Set CreateCompatibleDC = tmpHDC
End Function
         
Public Sub CreateDC(lpDriverName As String, lpDeviceName As String, lpOutput As String, lpInitData As dwDevMode)
Attribute CreateDC.VB_HelpID = 2496
Attribute CreateDC.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret As Long
#Else
    Dim ret As Integer
#End If
    Dim tmpDevMode As DEVMODE
    
    lpOutput = ""
    If lpInitData Is Nothing Then
        ret = apiCreateDCByVal(lpDriverName, lpDeviceName, lpOutput, 0)
    Else
        #If Win32 Then
            lpInitData.CopyToDEVMODE agGetAddressForObject(tmpDevMode.dmDeviceName)
            ret = apiCreateDC(lpDriverName, lpDeviceName, lpOutput, tmpDevMode)
        #Else
            ret = apiCreateDC(lpDriverName, lpDeviceName, lpOutput, agGetAddressForObject(tmpDevMode.dmDeviceName))
        #End If
    End If
    If ret = 0 Then RaiseHdcError
    DCsource = 1
    iHDC = ret
    DeviceCaps.InitDevCaps iHDC
End Sub

#If FlagUseArrayNotCollection Then
Public Sub DPtoLP(lpPoints() As dwPoint, ByVal nCount)
Attribute DPtoLP.VB_HelpID = 2696
Attribute DPtoLP.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim tempPoints() As POINTAPI
    Dim ret&
    Dim i As Integer

    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ReDim tempPoints(nCount - 1)
    For i = 0 To nCount - 1
        tempPoints(i).x = lpPoints(i).x
        tempPoints(i).y = lpPoints(i).y
    Next i
    ret& = apiDPtoLP(iHDC, tempPoints(0), nCount)
    If ret& = 0 Then RaiseHdcError
    For i = 0 To nCount - 1
        lpPoints(i).x = tempPoints(i).x
        lpPoints(i).y = tempPoints(i).y
    Next i
End Sub
#Else ' use Collection version
' colPoints should be a collection of dwPoints
Public Sub DPtoLP(colPoints As Collection)
    Dim tempPoints() As POINTAPI
    Dim ret&
    Dim i As Integer
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ReDim tempPoints(colPoints.count - 1)
    For i = 1 To colPoints.count
        tempPoints(i - 1).x = colPoints(i).x
        tempPoints(i - 1).y = colPoints(i).y
    Next i
    ret& = apiDPtoLP(iHDC, tempPoints(0), colPoints.count)
    If ret& = 0 Then RaiseHdcError
    For i = 1 To colPoints.count
        colPoints(i).x = tempPoints(i - 1).x
        colPoints(i).y = tempPoints(i - 1).y
    Next i
End Sub
#End If ' FlagUseArrayNotCollection

Public Function ExcludeClipRect(pRect As dwRECT) As Long
Attribute ExcludeClipRect.VB_HelpID = 2528
Attribute ExcludeClipRect.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiExcludeClipRect(iHDC, pRect.left, pRect.top, pRect.right, pRect.bottom)
    If ret& = ERRORAPI Then RaiseHdcError
    ExcludeClipRect = ret&
End Function

Public Function ExcludeUpdateRgn(hwnd As dwWindow) As Long
Attribute ExcludeUpdateRgn.VB_HelpID = 2930
Attribute ExcludeUpdateRgn.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiExcludeUpdateRgn(iHDC, hwnd.hwnd)
    If ret& = ERRORAPI Then RaiseHdcError
    ExcludeUpdateRgn = ret&
End Function

Public Function ExtSelectClipRgn(hRgn As dwRegion, ByVal fnMode) As Long
Attribute ExtSelectClipRgn.VB_HelpID = 2608
Attribute ExtSelectClipRgn.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiExtSelectClipRgn(iHDC, hRgn.hRegion, fnMode)
    If ret& = ERRORAPI Then RaiseHdcError
    ExtSelectClipRgn = ret&
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Function

Public Sub FillRegion(hRgn As dwRegion, hBrush As dwBrush)
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiFillRgn(iHDC, hRgn.hRegion, hBrush.hBrush)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Sub FrameRgn(hRgn As dwRegion, hBrush As dwBrush, ByVal nWidth, ByVal nHeight)
Attribute FrameRgn.VB_HelpID = 2532
Attribute FrameRgn.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiFrameRgn(iHDC, hRgn.hRegion, hBrush.hBrush, nWidth, nHeight)
    If ret& = 0 Then RaiseHdcError
End Sub

' ???:This returns unusually large numbers.
Public Function GetBoundsRect(ByVal Flags) As dwRECT
Attribute GetBoundsRect.VB_HelpID = 2540
Attribute GetBoundsRect.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim tempRect As RECT
    Dim newRect As New dwRECT
    Dim ret&

    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiGetBoundsRect(iHDC, tempRect, Flags)
    If ret& = 0 Then RaiseHdcError
    newRect.SetRect tempRect.top, tempRect.left, tempRect.bottom, tempRect.right
    Set GetBoundsRect = newRect
End Function

Public Function GetClipBox() As dwRECT
Attribute GetClipBox.VB_HelpID = 2546
Attribute GetClipBox.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim tempRect As RECT
    Dim newRect As New dwRECT
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiGetClipBox(iHDC, tempRect)
    If ret& = 0 Then RaiseHdcError
    newRect.SetRect tempRect.left, tempRect.top, tempRect.right, tempRect.bottom
    Set GetClipBox = newRect
End Function

Public Sub GetClipRgn(hRgn As dwRegion)
Attribute GetClipRgn.VB_HelpID = 2547
Attribute GetClipRgn.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiGetClipRgn(iHDC, hRgn.hRegion)
    If ret& = 1 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub

Public Function GetDCOrgEx() As dwPoint
Attribute GetDCOrgEx.VB_HelpID = 2715
Attribute GetDCOrgEx.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim tmpPoint As POINTAPI
    Dim newPoint As New dwPoint
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    GetDCOrgEx = apiGetDCOrgEx(iHDC, tmpPoint)
    If ret& = 0 Then RaiseHdcError
    newPoint.x = tmpPoint.x
    newPoint.y = tmpPoint.y
    Set GetDCOrgEx = newPoint
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Function

#If FlagGetDeviceCaps = True Then
Public Function GetDeviceCaps() As dwDevCaps
Attribute GetDeviceCaps.VB_HelpID = 2551
Attribute GetDeviceCaps.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    Set GetDeviceCaps = DeviceCaps
End Function
#End If 'FlagGetDeviceCaps

Public Function GetMapMode()
Attribute GetMapMode.VB_HelpID = 2556
Attribute GetMapMode.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiGetMapMode(iHDC)
    If ret& = 0 Then RaiseHdcError
    GetMapMode = ret&
#Else
    Dim ret%
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret% = apiGetMapMode(iHDC)
    If ret% = 0 Then RaiseHdcError
    GetMapMode = ret%
#End If
End Function

Public Function GetRgnBox(hRgn As dwRegion) As dwRECT
Attribute GetRgnBox.VB_HelpID = 2568
Attribute GetRgnBox.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim newRect As New dwRECT
    Dim tempRect As RECT
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiGetRgnBox(hRgn.hRegion, tempRect)
    If ret& = 0 Then RaiseHdcError
    newRect.SetRect tempRect.left, tempRect.top, tempRect.right, tempRect.bottom
    Set GetRgnBox = newRect
End Function

Public Function GetUpdateRegion(hwnd As dwWindow, ByVal fErase As Boolean) As dwRegion
Attribute GetUpdateRegion.VB_HelpID = 2929
Attribute GetUpdateRegion.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim newRegion As New dwRegion
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiGetUpdateRgn(iHDC, newRegion.hRegion, fErase)
    If ret& = 0 Then RaiseHdcError
    Set GetUpdateRegion = newRegion
End Function

Public Function GetViewportExtEx() As dwPoint
Attribute GetViewportExtEx.VB_HelpID = 2579
Attribute GetViewportExtEx.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim newSize As New dwPoint
    Dim tempSize As SIZE
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiGetViewportExtEx(iHDC, tempSize)
    newSize.cx = tempSize.cx
    newSize.cy = tempSize.cy
    Set GetViewportExtEx = newSize
End Function

Public Function GetViewportOrgEx() As dwPoint
Attribute GetViewportOrgEx.VB_HelpID = 2580
Attribute GetViewportOrgEx.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim newPoint As New dwPoint
#If Win32 Then
    Dim tempPoint As POINTAPI
#Else
    Dim tempPoint As SIZE
#End If
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiGetViewportOrgEx(iHDC, tempPoint)
    If ret& = 0 Then RaiseHdcError
#If Win32 Then
    newPoint.x = tempPoint.x
    newPoint.y = tempPoint.y
#Else
    newPoint.x = tempPoint.cx
    newPoint.y = tempPoint.cy
#End If
    Set GetViewportOrgEx = newPoint
End Function

Public Sub GetWindowDC(wnd As dwWindow)
Attribute GetWindowDC.VB_HelpID = 2924
Attribute GetWindowDC.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    If wnd.hwnd = 0 Then RaiseHdcError 380
    ClearDC
    iHDC = apiGetWindowDC(wnd.hwnd)
    DCsource = 0
    If iHDC = 0 Then RaiseHdcError DWERR_NODCAVAILABLE
    Set objwnd = wnd
    DeviceCaps.InitDevCaps iHDC
End Sub

Public Function GetWindowExtEx() As dwPoint
Attribute GetWindowExtEx.VB_HelpID = 2581
Attribute GetWindowExtEx.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim tempSize As SIZE
    Dim tempExt As New dwPoint
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiGetWindowExtEx(iHDC, tempSize)
    If ret& = 0 Then RaiseHdcError
    tempExt.cx = tempSize.cx
    tempExt.cy = tempSize.cy
    Set GetWindowExtEx = tempExt
End Function

Public Function GetWindowOrgEx() As dwPoint
Attribute GetWindowOrgEx.VB_HelpID = 2582
Attribute GetWindowOrgEx.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim tempPoint As POINTAPI
#Else
    Dim tempPoint As SIZE
#End If
    Dim tempOrg As New dwPoint
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiGetWindowOrgEx(iHDC, tempPoint)
    If ret& = 0 Then RaiseHdcError
#If Win32 Then
    tempOrg.x = tempPoint.x
    tempOrg.y = tempPoint.y
#Else
    tempOrg.x = tempPoint.cx
    tempOrg.y = tempPoint.cy
#End If
    Set GetWindowOrgEx = tempOrg
End Function

Public Function IntersectClipRect(pRect As dwRECT) As Long
Attribute IntersectClipRect.VB_HelpID = 2583
Attribute IntersectClipRect.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiIntersectClipRect(iHDC, pRect.left, pRect.top, pRect.right, pRect.bottom)
    If ret& = ERRORAPI Then RaiseHdcError
    IntersectClipRect = ret&
End Function

Public Sub InvertRgn(hRgn As dwRegion)
Attribute InvertRgn.VB_HelpID = 2584
Attribute InvertRgn.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiInvertRgn(iHDC, hRgn.hRegion)
    If ret& = 0 Then RaiseHdcError
End Sub

#If FlagUseArrayNotCollection Then
Public Sub LPtoDP(lpPoints() As dwPoint, ByVal nCount)
Attribute LPtoDP.VB_HelpID = 2697
Attribute LPtoDP.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim tempPoints() As POINTAPI
    Dim ret&
    Dim i As Integer
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ReDim tempPoints(nCount - 1)
    For i = 0 To nCount - 1
        tempPoints(i).x = lpPoints(i).x
        tempPoints(i).y = lpPoints(i).y
    Next i
    ret& = apiLPtoDP(iHDC, tempPoints(0), nCount)
    If ret& = 0 Then RaiseHdcError
    For i = 0 To nCount - 1
        lpPoints(i).x = tempPoints(i).x
        lpPoints(i).y = tempPoints(i).y
    Next i
End Sub
#Else ' use collection version
' colPoints should be a collection of dwPoints
Public Sub LPtoDP(colPoints As Collection, ByVal nCount)
    Dim tempPoints() As POINTAPI
    Dim ret&
    Dim i As Integer
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ReDim tempPoints(colPoints.count - 1)
    For i = 1 To colPoints.count
        tempPoints(i - 1).x = colPoints(i).x
        tempPoints(i - 1).y = colPoints(i).y
    Next i
    ret& = apiLPtoDP(iHDC, tempPoints(0), colPoints.count)
    If ret& = 0 Then RaiseHdcError
    For i = 1 To colPoints.count
        colPoints(i).x = tempPoints(i - 1).x
        colPoints(i).y = tempPoints(i - 1).y
    Next i
End Sub
#End If ' FlagUseArrayNotCollection

Public Function OffsetClipRgn(pPoint As dwPoint) As Long
Attribute OffsetClipRgn.VB_HelpID = 2588
Attribute OffsetClipRgn.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
     
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiOffsetClipRgn(iHDC, pPoint.x, pPoint.y)
    If ret& = ERRORAPI Then RaiseHdcError
    OffsetClipRgn = ret&
End Function

Public Sub OffsetViewportOrgEx(ByVal nX, ByVal nY, lpPoint As dwPoint)
Attribute OffsetViewportOrgEx.VB_HelpID = 2707
Attribute OffsetViewportOrgEx.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim tempPoint As POINTAPI
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    tempPoint.x = lpPoint.x
    tempPoint.y = lpPoint.y
    ret& = apiOffsetViewportOrgEx(iHDC, nX, nY, tempPoint)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Sub PaintRgn(hRgn As dwRegion)
Attribute PaintRgn.VB_HelpID = 2593
Attribute PaintRgn.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiPaintRgn(iHDC, hRgn.hRegion)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Function PtVisible(pPoint As dwPoint) As Long
Attribute PtVisible.VB_HelpID = 2596
Attribute PtVisible.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiPtVisible(iHDC, pPoint.x, pPoint.y)
    If ret& = 0 Then
        PtVisible = False
    Else
        PtVisible = True
    End If
End Function

Public Sub RectVisible(rRect As dwRECT)
Attribute RectVisible.VB_HelpID = 2597
Attribute RectVisible.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim tempRect As RECT
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    rRect.CopyToRECT agGetAddressForObject(tempRect.left)
    ret& = apiRectVisible(iHDC, tempRect)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Sub RestoreDC(ByVal nSavedDC)
Attribute RestoreDC.VB_HelpID = 2600
Attribute RestoreDC.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiRestoreDC(iHDC, nSavedDC)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Function SaveDC()
Attribute SaveDC.VB_HelpID = 2606
Attribute SaveDC.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret As Long
#Else
    Dim ret As Integer
#End If
        
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret = apiSaveDC(iHDC)
    If ret = 0 Then RaiseHdcError
    SaveDC = ret
End Function

Public Sub ScaleViewportExtEx(ByVal nXnum, ByVal nXdenom, ByVal nYnum, ByVal nYdenom, lpSize As dwPoint)
Attribute ScaleViewportExtEx.VB_HelpID = 2710
Attribute ScaleViewportExtEx.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim tempSize As SIZE
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    tempSize.cx = lpSize.cx
    tempSize.cy = lpSize.cy
    ret& = apiScaleViewportExtEx(iHDC, nXnum, nXdenom, nYnum, nYdenom, tempSize)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Sub ScaleWindowExtEx(ByVal nXnum, ByVal nXdenom, ByVal nYnum, ByVal nYdenom, lpSize As dwPoint)
Attribute ScaleWindowExtEx.VB_HelpID = 2709
Attribute ScaleWindowExtEx.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim tempSize As SIZE
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    tempSize.cx = lpSize.cx
    tempSize.cy = lpSize.cy
    ret& = apiScaleWindowExtEx(iHDC, nXnum, nXdenom, nYnum, nYdenom, tempSize)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Sub ScrollDC(ByVal dx, ByVal dy, lprcScroll As dwRECT, lprcClip As dwRECT, ByVal hRgnUpdate, lprcUpdate As dwRECT)
Attribute ScrollDC.VB_HelpID = 2940
Attribute ScrollDC.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim tempRect1 As RECT
    Dim tempRect2 As RECT
    Dim tempRect3 As RECT
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    lprcScroll.CopyToRECT agGetAddressForObject(tempRect1.left)
    lprcClip.CopyToRECT agGetAddressForObject(tempRect2.left)
    lprcUpdate.CopyToRECT agGetAddressForObject(tempRect3.left)
    ret& = apiScrollDC(iHDC, dx, dy, tempRect1, tempRect2, hRgnUpdate.hRegion, tempRect3)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Sub SelectClipRgn(hRgn As dwRegion)
Attribute SelectClipRgn.VB_HelpID = 2607
Attribute SelectClipRgn.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiSelectClipRgn(iHDC, hRgn.hRegion)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Function SetBoundsRect(lprcBounds As dwRECT, ByVal Flags) As Long
Attribute SetBoundsRect.VB_HelpID = 2615
Attribute SetBoundsRect.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim tempRect As RECT
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    lprcBounds.CopyToRECT agGetAddressForObject(tempRect.left)
    ret& = apiSetBoundsRect(iHDC, tempRect, Flags)
    If ret& = 0 Then RaiseHdcError
    SetBoundsRect = ret&
End Function

Public Function SetMapMode(ByVal nMapMode) As Long
Attribute SetMapMode.VB_HelpID = 2620
Attribute SetMapMode.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiSetMapMode(iHDC, nMapMode)
    If ret& = 0 Then RaiseHdcError
    SetMapMode = ret&
End Function

Public Sub SetViewportExtEx(ByVal nX, ByVal nY, lpSize As dwPoint)
Attribute SetViewportExtEx.VB_HelpID = 2703
Attribute SetViewportExtEx.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim tempSize As SIZE
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    tempSize.cx = lpSize.cx
    tempSize.cy = lpSize.cy
    ret& = apiSetViewportExtEx(iHDC, nX, nY, tempSize)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Sub SetViewportOrgEx(ByVal nX, ByVal nY, lpPoint As dwPoint)
Attribute SetViewportOrgEx.VB_HelpID = 2704
Attribute SetViewportOrgEx.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim tempPoint As POINTAPI
#Else
    Dim tempPoint As SIZE
#End If
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
#If Win32 Then
    tempPoint.x = lpPoint.x
    tempPoint.y = lpPoint.y
#Else
    tempPoint.cx = lpPoint.x
    tempPoint.cy = lpPoint.y
#End If
    ret& = apiSetViewportOrgEx(iHDC, nX, nY, tempPoint)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Sub SetWindowExtEx(ByVal nX, ByVal nY, lpSize As dwPoint)
Attribute SetWindowExtEx.VB_HelpID = 2706
Attribute SetWindowExtEx.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim tempSize As SIZE
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiSetWindowExtEx(iHDC, nX, nY, tempSize)
    lpSize.cx = tempSize.cx
    lpSize.cy = tempSize.cy
    If ret& = 0 Then RaiseHdcError
End Sub

Public Sub SetWindowOrgEx(ByVal nX, ByVal nY, lpPoint As dwPoint)
Attribute SetWindowOrgEx.VB_HelpID = 2705
Attribute SetWindowOrgEx.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim tempPoint As POINTAPI
#Else
    Dim tempPoint As SIZE
#End If
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
#If Win32 Then
    tempPoint.x = lpPoint.x
    tempPoint.y = lpPoint.y
#Else
    tempPoint.cx = lpPoint.x
    tempPoint.cy = lpPoint.y
#End If
    ret& = apiSetWindowOrgEx(iHDC, nX, nY, tempPoint)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Function WindowFromDC() As Long
Attribute WindowFromDC.VB_HelpID = 2921
Attribute WindowFromDC.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiWindowFromDC(iHDC)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Function

Public Sub DrawEdge(qrc As dwRECT, ByVal edge, ByVal grfFlags)
Attribute DrawEdge.VB_HelpID = 3539
#If Win32 Then
    Dim tempRect As RECT
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    qrc.CopyToRECT agGetAddressForObject(tempRect.left)
    ret& = apiDrawEdge(iHDC, tempRect, edge, grfFlags)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub

Public Function GetBrushOrgEx() As dwPoint
Attribute GetBrushOrgEx.VB_HelpID = 2503
Attribute GetBrushOrgEx.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim tempPoint As POINTAPI
    Dim tempOrg As New dwPoint
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiGetBrushOrgEx(iHDC, tempPoint)
    If ret& = 0 Then RaiseHdcError
    tempOrg.x = tempPoint.x
    tempOrg.y = tempPoint.y
    Set GetBrushOrgEx = tempOrg
End Function

Public Sub PaintDesktop()
Attribute PaintDesktop.VB_HelpID = 3571
Attribute PaintDesktop.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiPaintDesktop(iHDC)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub

Public Sub SelectClipPath(iMode As Long)
Attribute SelectClipPath.VB_HelpID = 2681
Attribute SelectClipPath.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiSelectClipPath(iHDC, iMode)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub

Public Sub AbortPath()
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiAbortPath(iHDC)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub

Public Sub AngleArc(pPoint As dwPoint, dwRadius As Long, eStartAngle As Double, eSweepAngle As Double)
Attribute AngleArc.VB_HelpID = 2657
Attribute AngleArc.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiAngleArc(iHDC, pPoint.x, pPoint.y, dwRadius, eStartAngle, eSweepAngle)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub

Public Sub ArcTo(pPoint1 As dwPoint, pPoint2 As dwPoint, pPoint3 As dwPoint, pPoint4 As dwPoint)
Attribute ArcTo.VB_HelpID = 2672
Attribute ArcTo.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiArcTo(iHDC, pPoint1.x, pPoint1.y, pPoint2.x, pPoint2.y, pPoint3.x, pPoint3.y, pPoint4.x, pPoint4.y)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub

Public Sub Arc(pPoint1 As dwPoint, pPoint2 As dwPoint, pPoint3 As dwPoint, pPoint4 As dwPoint)
Attribute Arc.VB_HelpID = 2483
Attribute Arc.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiArc(iHDC, pPoint1.x, pPoint1.y, pPoint2.x, pPoint2.y, pPoint3.x, pPoint3.y, pPoint4.x, pPoint4.y)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Sub BeginPath()
Attribute BeginPath.VB_HelpID = 2673
Attribute BeginPath.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiBeginPath(iHDC)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub

Public Sub CancelDC()
Attribute CancelDC.VB_HelpID = 2485
Attribute CancelDC.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiCancelDC(iHDC)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub

Public Sub Chord(pPoint1 As dwPoint, pPoint2 As dwPoint, pPoint3 As dwPoint, pPoint4 As dwPoint)
Attribute Chord.VB_HelpID = 2486
Attribute Chord.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiChord(iHDC, pPoint1.x, pPoint1.y, pPoint2.x, pPoint2.y, pPoint3.x, pPoint3.y, pPoint4.x, pPoint4.y)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Sub CloseFigure()
Attribute CloseFigure.VB_HelpID = 2674
Attribute CloseFigure.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiCloseFigure(iHDC)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub

Public Sub CopyEnhMetaFile(hemfSrc As Long, lpszFile As String)
Attribute CopyEnhMetaFile.VB_HelpID = 2640
Attribute CopyEnhMetaFile.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiCopyEnhMetaFile(hemfSrc, lpszFile)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub

Public Sub CreateEnhMetaFile(hdcRef As Long, lpFileName As String, rRect As dwRECT, lpDescription As String)
Attribute CreateEnhMetaFile.VB_HelpID = 2641
Attribute CreateEnhMetaFile.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim tempRect As RECT
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    rRect.CopyToRECT agGetAddressForObject(tempRect.left)
    ret& = apiCreateEnhMetaFile(hdcRef, lpFileName, tempRect, lpDescription)
    If ret& = 0 Then RaiseHdcError
    iHDC = ret&
    DCsource = 4
    DeviceCaps.InitDevCaps iHDC
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub

Public Sub DrawEscape(nEscape As Long, cbInput As Long, lpszInData As String)
Attribute DrawEscape.VB_HelpID = 2527
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiDrawEscape(iHDC, nEscape, cbInput, lpszInData)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub

Public Sub DrawFocusRect(rRect As dwRECT)
Attribute DrawFocusRect.VB_HelpID = 2984
    Dim tempRect As RECT
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    rRect.CopyToRECT agGetAddressForObject(tempRect.left)
#If Win32 Then
    ret& = apiDrawFocusRect(iHDC, tempRect)
    If ret& = 0 Then RaiseHdcError
#Else
    apiDrawFocusRect iHDC, tempRect
#End If
End Sub

Public Sub Ellipse(pRect As dwRECT)
Attribute Ellipse.VB_HelpID = 2523
Attribute Ellipse.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiEllipse(iHDC, pRect.left, pRect.top, pRect.right, pRect.bottom)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Sub EndPath()
Attribute EndPath.VB_HelpID = 2675
Attribute EndPath.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiEndPath(iHDC)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub

Public Sub ExtFloodFill(pPoint As dwPoint, ByVal crColor, ByVal wFillType)
Attribute ExtFloodFill.VB_HelpID = 2530
Attribute ExtFloodFill.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiExtFloodFill(iHDC, pPoint.x, pPoint.y, crColor, wFillType)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Sub FillPath()
Attribute FillPath.VB_HelpID = 2676
Attribute FillPath.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiFillPath(iHDC)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub

Public Sub FillRect(rRect As dwRECT, hBrush As dwBrush)
Attribute FillRect.VB_HelpID = 2985
Attribute FillRect.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim tempRect As RECT
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    rRect.CopyToRECT agGetAddressForObject(tempRect.left)
    ret& = apiFillRect(iHDC, tempRect, hBrush.hBrush)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Sub FlattenPath()
Attribute FlattenPath.VB_HelpID = 2677
Attribute FlattenPath.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiFlattenPath(iHDC)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub

Public Sub FloodFill(pPoint As dwPoint, crColor As Long)
Attribute FloodFill.VB_HelpID = 2533
Attribute FloodFill.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiFloodFill(iHDC, pPoint.x, pPoint.y, crColor)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Sub FrameRect(rRect As dwRECT, hBrush As dwBrush)
Attribute FrameRect.VB_HelpID = 2986
Attribute FrameRect.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim tempRect As RECT
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    rRect.CopyToRECT agGetAddressForObject(tempRect.left)
    ret& = apiFrameRect(iHDC, tempRect, hBrush.hBrush)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Sub GdiComment(cbSize As Long, lpData As Byte)
Attribute GdiComment.VB_HelpID = 2655
Attribute GdiComment.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiGdiComment(iHDC, cbSize, lpData)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub

Public Function GetArcDirection() As Long
Attribute GetArcDirection.VB_HelpID = 2689
Attribute GetArcDirection.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiGetArcDirection(iHDC)
    If ret& = 0 Then RaiseHdcError
    GetArcDirection = ret&
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Function

Public Function GetBkColor() As Long
Attribute GetBkColor.VB_HelpID = 2536
Attribute GetBkColor.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiGetBkColor(iHDC)
    If ret& = 0 Then RaiseHdcError
    GetBkColor = ret&
End Function

Public Function GetBkMode() As Long
Attribute GetBkMode.VB_HelpID = 2537
Attribute GetBkMode.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiGetBkMode(iHDC)
    If ret& = 0 Then RaiseHdcError
    GetBkMode = ret&
End Function

Public Function GetCurrentPositionEx() As dwPoint
Attribute GetCurrentPositionEx.VB_HelpID = 2550
Attribute GetCurrentPositionEx.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim tempPosition As New dwPoint
    Dim tempPoint As POINTAPI
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiGetCurrentPositionEx(iHDC, tempPoint)
    tempPosition.x = tempPoint.x
    tempPosition.y = tempPoint.y
    If ret& = 0 Then RaiseHdcError
    Set GetCurrentPositionEx = tempPosition
End Function

Public Function GetMiterLimit() As Single
Attribute GetMiterLimit.VB_HelpID = 2688
Attribute GetMiterLimit.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    Dim limit As Single
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiGetMiterLimit(iHDC, limit)
    If ret& = 0 Then RaiseHdcError
    GetMiterLimit = limit
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Function

Public Function GetNearestColor(crColor As Long) As Long
Attribute GetNearestColor.VB_HelpID = 2559
Attribute GetNearestColor.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiGetNearestColor(iHDC, crColor)
    If ret& = 0 Then RaiseHdcError
    GetNearestColor = ret&
End Function

#If FlagUseArrayNotCollection Then
Public Function GetPath(lpPoints() As dwPoint, lpTypes() As Byte) As Long
Attribute GetPath.VB_HelpID = 2678
Attribute GetPath.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim tempPoints() As POINTAPI
    Dim ret&
    Dim i As Integer
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ReDim tempPoints(1)
    ReDim lpTypes(1)
    ret& = apiGetPath(iHDC, tempPoints(0), lpTypes(0), 0)
    If ret& = -1 Then RaiseHdcError
    ReDim tempPoints(ret&)
    ReDim lpTypes(ret&)
    ReDim lpPoints(ret&)
    ret& = apiGetPath(iHDC, tempPoints(0), lpTypes(0), ret&)
    If ret& = -1 Then RaiseHdcError
    For i = 0 To ret& - 1
        Set lpPoints(i) = New dwPoint
        lpPoints(i).x = tempPoints(i).x
        lpPoints(i).y = tempPoints(i).y
    Next i
    GetPath = ret&
#Else
    RaiseSysError DWERR_NOTINWIN16
#End If
End Function
#Else ' use collection version
' colPoints will be a collection of dwPoints, colTypes of Bytes
Public Function GetPath(colPoints As Collection, colTypes As Collection) As Long
#If Win32 Then
    Dim tempPoints() As POINTAPI
    Dim tempBytes() As Byte
    Dim tempCPoints As New Collection
    Dim tempCTypes As New Collection
    Dim pPoint As dwPoint
    Dim ret&
    Dim i As Integer
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ReDim tempPoints(1)
    ReDim tempBytes(1)
    ret& = apiGetPath(iHDC, tempPoints(0), tempBytes(0), 0)
    If ret& = -1 Then RaiseHdcError
    ReDim tempPoints(ret&)
    ReDim tempBytes(ret&)

    ret& = apiGetPath(iHDC, tempPoints(0), tempBytes(0), ret&)
    If ret& = -1 Then RaiseHdcError
    For i = 0 To ret& - 1
        Set pPoint = New dwPoint
        pPoint.x = tempPoints(i).x
        pPoint.y = tempPoints(i).y
        tempCPoints.Add Item:=pPoint
        tempCTypes.Add Item:=tempBytes(i)
        Set pPoint = Nothing
    Next i
    Set colPoints = tempCPoints
    Set colTypes = tempCTypes
    
    Set tempCPoints = Nothing
    Set tempCTypes = Nothing
    GetPath = ret&
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Function
#End If ' FlagUseArrayNotCollection

Public Function GetPixel(pPoint As dwPoint) As Long
Attribute GetPixel.VB_HelpID = 2564
Attribute GetPixel.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiGetPixel(iHDC, pPoint.x, pPoint.y)
    If ret& = -1 Then RaiseHdcError
    GetPixel = ret&
End Function

Public Function GetPolyFillMode() As Long
Attribute GetPolyFillMode.VB_HelpID = 2565
Attribute GetPolyFillMode.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiGetPolyFillMode(iHDC)
    If ret& = 0 Then RaiseHdcError
    GetPolyFillMode = ret&
End Function

Public Function GetROP2() As Long
Attribute GetROP2.VB_HelpID = 2534
Attribute GetROP2.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiGetROP2(iHDC)
    If ret& = 0 Then RaiseHdcError
    GetROP2 = ret&
End Function

Public Sub InvertRect(rRect As dwRECT)
Attribute InvertRect.VB_HelpID = 2987
Attribute InvertRect.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim tempRect As RECT
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    rRect.CopyToRECT agGetAddressForObject(tempRect.left)
#If Win32 Then
    ret& = apiInvertRect(iHDC, tempRect)
    If ret& = 0 Then RaiseHdcError
#Else
    apiInvertRect iHDC, tempRect
#End If
    rRect.SetRect tempRect.left, tempRect.top, tempRect.right, tempRect.bottom
End Sub

Public Sub LineTo(pPoint As dwPoint)
Attribute LineTo.VB_HelpID = 2585
Attribute LineTo.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiLineTo(iHDC, pPoint.x, pPoint.y)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Sub MoveTo(pPoint As dwPoint)
Attribute MoveTo.VB_HelpID = 2691
Attribute MoveTo.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
' You can modify this sub to return the point before the move
' by converting either the tempPoint(32-bit) or ret&(16-bit)
' to a dwPoint and returning the dwPoint.
#If Win32 Then
    Dim tempPoint As POINTAPI
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiMoveToEx(iHDC, pPoint.x, pPoint.y, tempPoint)
    If ret& = 0 Then RaiseHdcError
#Else
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiMoveTo(iHDC, pPoint.x, pPoint.y)
    ' ret holds former point, not an error code
#End If
End Sub

Public Sub Pie(pPoint1 As dwPoint, pPoint2 As dwPoint, pPoint3 As dwPoint, pPoint4 As dwPoint)
Attribute Pie.VB_HelpID = 2591
Attribute Pie.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiPie(iHDC, pPoint1.x, pPoint1.y, pPoint2.x, pPoint2.y, pPoint3.x, pPoint3.y, pPoint4.x, pPoint4.y)
    If ret& = 0 Then RaiseHdcError
End Sub

#If FlagMetaFile Then
Public Sub PlayEnhMetaFile(mf As dwMetaFile, rRect As dwRECT)
Attribute PlayEnhMetaFile.VB_HelpID = 2651
Attribute PlayEnhMetaFile.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim tempRect As RECT
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    rRect.CopyToRECT agGetAddressForObject(tempRect.left)
    ret& = apiPlayEnhMetaFile(iHDC, mf.hMetaFile, tempRect)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub
#End If ' FlagMetafile

#If FlagPlayEnhMetaFileRecord = True And FlagMetaFile = True Then
Public Sub PlayEnhMetaFileRecord(lpHandleTable As dwHandleTable, lpEnhMetaRecord As dwEnhMetaRecord, nHandles As Long)
Attribute PlayEnhMetaFileRecord.VB_HelpID = 2652
Attribute PlayEnhMetaFileRecord.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim tmpHTable As HANDLETABLE
    Dim tmpEMetaRec As ENHMETARECORD
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    lpHandleTable.CopyToHANDLETABLE agGetAddressForObject(tmpHTable.ObjectHandle(0))
    lpEnhMetaRecord.CopyToENHMETARECORD agGetAddressForObject(tmpEMetaRec.iType)
    ret& = apiPlayEnhMetaFileRecord(iHDC, tmpHTable, tmpEMetaRec, nHandles)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub
#End If 'FlagPlayEnhMetaFileRecord, FlagMetafile

#If FlagMetaFile Then
Public Sub PlayMetaFile(mf As dwMetaFile)
Attribute PlayMetaFile.VB_HelpID = 2592
Attribute PlayMetaFile.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiPlayMetaFile(iHDC, mf.hMetaFile)
    If ret& = 0 Then RaiseHdcError
End Sub
#End If ' FlagMetafile

#If FlagUseArrayNotCollection Then
Public Sub PolyBezier(lppt() As dwPoint, cPoints As Long)
Attribute PolyBezier.VB_HelpID = 2700
Attribute PolyBezier.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
End Sub
#If Win32 Then
    Dim tempPoints() As POINTAPI
    Dim ret&
    Dim i As Integer

    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ReDim tempPoints(cPoints - 1)
    For i = 0 To cPoints - 1
        tempPoints(i).x = lppt(i).x
        tempPoints(i).y = lppt(i).y
    Next i
    ret& = apiPolyBezier(iHDC, tempPoints(0), cPoints)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseSysError DWERR_NOTINWIN16
#End If
End Sub
#Else ' use Collection
' colPoints should be a collection of dwPoints
Public Sub PolyBezier(colPoints As Collection)
#If Win32 Then
    Dim tempPoints() As POINTAPI
    Dim ret&
    Dim i As Integer
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ReDim tempPoints(colPoints.count - 1)
    For i = 1 To colPoints.count
        tempPoints(i - 1).x = colPoints(i).x
        tempPoints(i - 1).y = colPoints(i).y
    Next i
    ret& = apiPolyBezier(iHDC, tempPoints(0), colPoints.count)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub
#End If ' FlagUseArrayNotCollection

#If FlagUseArrayNotCollection Then
Public Sub PolyBezierTo(lppt() As dwPoint, cPoints As Long)
Attribute PolyBezierTo.VB_HelpID = 2701
Attribute PolyBezierTo.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim tempPoints() As POINTAPI
    Dim ret&
    Dim i As Integer

    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ReDim tempPoints(cPoints - 1)
    For i = 0 To cPoints - 1
        tempPoints(i).x = lppt(i).x
        tempPoints(i).y = lppt(i).y
    Next i
    ret& = apiPolyBezierTo(iHDC, tempPoints(0), cPoints)
    If ret& = 0 Then RaiseHdcError
#End If
End Sub
#Else  ' use collection version
' colPoints should be a collection of dwPoints
Public Sub PolyBezierTo(colPoints As Collection)
#If Win32 Then
    Dim tempPoints() As POINTAPI
    Dim ret&
    Dim i As Integer
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ReDim tempPoints(colPoints.count - 1)
    For i = 1 To colPoints.count
        tempPoints(i - 1).x = colPoints(i).x
        tempPoints(i - 1).y = colPoints(i).y
    Next i
    ret& = apiPolyBezierTo(iHDC, tempPoints(0), colPoints.count)
    If ret& = 0 Then RaiseHdcError
#End If
End Sub
#End If ' FlagUseArrayNotCollection

#If FlagUseArrayNotCollection Then
Public Sub PolyDraw(lppt() As dwPoint, lpbTypes() As Byte, cPoints As Long)
Attribute PolyDraw.VB_HelpID = 2680
Attribute PolyDraw.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim tempPoints() As POINTAPI
    Dim ret&
    Dim i As Integer

    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ReDim tempPoints(cPoints - 1)
    For i = 0 To cPoints - 1
        tempPoints(i).x = lppt(i).x
        tempPoints(i).y = lppt(i).y
    Next i
    ret& = apiPolyDraw(iHDC, tempPoints(0), lpbTypes(0), cPoints)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseSysError DWERR_NOTINWIN16
#End If
End Sub
#Else ' use collection version
' colPoints should be a collection of dwPoints, colBytes a collection of Bytes
Public Sub PolyDraw(colPoints As Collection, colTypes As Collection)
#If Win32 Then
    Dim tempPoints() As POINTAPI
    Dim tempBytes() As Byte
    Dim ret&
    Dim i As Integer
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    If colPoints.count <> colTypes.count Then RaiseHdcError DWERR_COUNTMISMATCH
    ReDim tempPoints(colPoints.count - 1)
    ReDim tempBytes(colPoints.count - 1)
    For i = 1 To colPoints.count
        tempPoints(i - 1).x = colPoints(i).x
        tempPoints(i - 1).y = colPoints(i).y
        tempBytes(i - 1) = colTypes(i)
    Next i
    ret& = apiPolyDraw(iHDC, tempPoints(0), tempBytes(0), colPoints.count)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub
#End If ' FlagUseArrayNotCollection

#If FlagUseArrayNotCollection Then
Public Sub Polygon(lppt() As dwPoint, ByVal cPoints)
Attribute Polygon.VB_HelpID = 2699
Attribute Polygon.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim tempPoints() As POINTAPI
    Dim ret&
    Dim i As Integer

    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ReDim tempPoints(cPoints - 1)
    For i = 0 To cPoints - 1
        tempPoints(i).x = lppt(i).x
        tempPoints(i).y = lppt(i).y
    Next i
    ret& = apiPolygon(iHDC, tempPoints(0), cPoints)
    If ret& = 0 Then RaiseHdcError
End Sub
#Else ' use collection version
' colPoints should be a collection of dwPoints
Public Sub Polygon(colPoints As Collection)
    Dim tempPoints() As POINTAPI
    Dim ret&
    Dim i As Integer
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ReDim tempPoints(colPoints.count - 1)
    For i = 1 To colPoints.count
        tempPoints(i - 1).x = colPoints(i).x
        tempPoints(i - 1).y = colPoints(i).y
    Next i
    ret& = apiPolygon(iHDC, tempPoints(0), colPoints.count)
    If ret& = 0 Then RaiseHdcError
End Sub
#End If ' FlagUseArrayNotCollection

#If FlagUseArrayNotCollection Then
Public Sub Polyline(lppt() As dwPoint, ByVal cPoints)
Attribute Polyline.VB_HelpID = 2698
Attribute Polyline.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim tempPoints() As POINTAPI
    Dim ret&
    Dim i As Integer

    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ReDim tempPoints(cPoints - 1)
    For i = 0 To cPoints - 1
        tempPoints(i).x = lppt(i).x
        tempPoints(i).y = lppt(i).y
    Next i
    ret& = apiPolyline(iHDC, tempPoints(0), cPoints)
    If ret& = 0 Then RaiseHdcError
End Sub
#Else ' use collection version
' colPoints should be a collection of dwPoints
Public Sub Polyline(colPoints As Collection)
    Dim tempPoints() As POINTAPI
    Dim ret&
    Dim i As Integer
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ReDim tempPoints(colPoints.count - 1)
    For i = 1 To colPoints.count
        tempPoints(i - 1).x = colPoints(i).x
        tempPoints(i - 1).y = colPoints(i).y
    Next i
    ret& = apiPolyline(iHDC, tempPoints(0), colPoints.count)
    If ret& = 0 Then RaiseHdcError
End Sub
#End If ' FlagUseArrayNotCollection

#If FlagUseArrayNotCollection Then
Public Sub PolylineTo(lppt() As dwPoint, cPoints As Long)
Attribute PolylineTo.VB_HelpID = 2702
Attribute PolylineTo.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim tempPoints() As POINTAPI
    Dim ret&
    Dim i As Integer

    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ReDim tempPoints(cPoints - 1)
    For i = 0 To cPoints - 1
        tempPoints(i).x = lppt(i).x
        tempPoints(i).y = lppt(i).y
    Next i
    ret& = apiPolylineTo(iHDC, tempPoints(0), cPoints)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseSysError DWERR_NOTINWIN16
#End If
End Sub
#Else ' use collection version
' colPoints should be a collection of dwPoints
Public Sub PolylineTo(colPoints As Collection)
#If Win32 Then
    Dim tempPoints() As POINTAPI
    Dim ret&
    Dim i As Integer
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ReDim tempPoints(colPoints.count - 1)
    For i = 1 To colPoints.count
        tempPoints(i - 1).x = colPoints(i).x
        tempPoints(i - 1).y = colPoints(i).y
    Next i
    ret& = apiPolylineTo(iHDC, tempPoints(0), colPoints.count)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub
#End If ' FlagUseArrayNotCollection

#If FlagUseArrayNotCollection Then
Public Sub PolyPolyline(lppt() As dwPoint, lpPolyPoints() As Long, cPolygons As Long)
Attribute PolyPolyline.VB_HelpID = 2658
Attribute PolyPolyline.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim tempPoints() As POINTAPI
    Dim ret&
    Dim i As Integer
    Dim cPoints As Long

    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    cPoints = UBound(lppt) + 1
    ReDim tempPoints(cPoints - 1)
    For i = 0 To cPoints - 1
        tempPoints(i).x = lppt(i).x
        tempPoints(i).y = lppt(i).y
    Next i
    ret& = apiPolyPolyline(iHDC, tempPoints(0), lpPolyPoints(0), cPolygons)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseSysError DWERR_NOTINWIN16
#End If
End Sub
#Else ' use collection version
' colPoints should be a collection of dwPoints, colPolyPoints of Longs
Public Sub PolyPolyline(colPoints As Collection, colPolyPoints As Collection, cPolygons As Long)
#If Win32 Then
    Dim tempPoints() As POINTAPI
    Dim tempLongs() As Long
    Dim ret&
    Dim i As Integer
    Dim cPoints As Long
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    cPoints = colPoints.count
    ReDim tempPoints(cPoints - 1)
    ReDim tempLongs(cPoints - 1)
    For i = 1 To cPoints
        tempPoints(i - 1).x = colPoints(i).x
        tempPoints(i - 1).y = colPoints(i).y
        tempLongs(i - 1) = colPolyPoints(i)
    Next i
    ret& = apiPolyPolyline(iHDC, tempPoints(0), tempLongs(0), cPolygons)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub
#End If 'FlagUseArrayNotCollection

Public Sub Rectangle(pRect As dwRECT)
Attribute Rectangle.VB_HelpID = 2599
Attribute Rectangle.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiRectangle(iHDC, pRect.left, pRect.top, pRect.right, pRect.bottom)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Sub RoundRect(pRect As dwRECT, ByVal X3, ByVal Y3)
Attribute RoundRect.VB_HelpID = 2604
Attribute RoundRect.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiRoundRect(iHDC, pRect.left, pRect.top, pRect.right, pRect.bottom, X3, Y3)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Function SetBkColor(crColor As Long) As Long
Attribute SetBkColor.VB_HelpID = 2612
Attribute SetBkColor.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiSetBkColor(iHDC, crColor)
    If ret& = CLR_INVALID Then RaiseHdcError
    SetBkColor = ret&
End Function

Public Sub SetArcDirection(ArcDirection As Long)
Attribute SetArcDirection.VB_HelpID = 2682
Attribute SetArcDirection.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiSetArcDirection(iHDC, ArcDirection)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub

Public Function SetBkMode(ByVal nBkMode) As Long
Attribute SetBkMode.VB_HelpID = 2613
Attribute SetBkMode.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiSetBkMode(iHDC, nBkMode)
    If ret& = 0 Then RaiseHdcError
    SetBkMode = ret&
End Function

Public Sub SetBrushOrg(lppt As dwPoint)
Attribute SetBrushOrg.VB_HelpID = 2712
Attribute SetBrushOrg.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim junk As POINTAPI
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiSetBrushOrgEx(iHDC, lppt.x, lppt.y, junk)
    If ret& = 0 Then RaiseHdcError
#Else
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiSetBrushOrg(iHDC, lppt.x, lppt.y)
#End If
End Sub

Public Sub SetMiterLimit(eNewLimit As Single, peOldLimit As Single)
Attribute SetMiterLimit.VB_HelpID = 2683
Attribute SetMiterLimit.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiSetMiterLimit(iHDC, eNewLimit, peOldLimit)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub

Public Function SetPixel(pPoint As dwPoint, crColor As Long) As Long
Attribute SetPixel.VB_HelpID = 2623
Attribute SetPixel.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiSetPixel(iHDC, pPoint.x, pPoint.y, crColor)
    If ret& = -1 Then RaiseHdcError
    SetPixel = ret&
End Function

Public Sub SetPixelV(pPoint As dwPoint, crColor As Long)
Attribute SetPixelV.VB_HelpID = 2624
Attribute SetPixelV.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiSetPixelV(iHDC, pPoint.x, pPoint.y, crColor)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub

Public Function SetPolyFillMode(ByVal nPolyFillMode As Long) As Long
Attribute SetPolyFillMode.VB_HelpID = 2625
Attribute SetPolyFillMode.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiSetPolyFillMode(iHDC, nPolyFillMode)
    If ret& = 0 Then RaiseHdcError
    SetPolyFillMode = ret&
End Function

Public Function SetROP2(nDrawMode As Long) As Long
Attribute SetROP2.VB_HelpID = 2629
Attribute SetROP2.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiSetROP2(iHDC, nDrawMode)
    If ret& = 0 Then RaiseHdcError
    SetROP2 = ret&
End Function

Public Sub StrokeAndFillPath()
Attribute StrokeAndFillPath.VB_HelpID = 2684
Attribute StrokeAndFillPath.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiStrokeAndFillPath(iHDC)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub

Public Sub StrokePath()
Attribute StrokePath.VB_HelpID = 2685
Attribute StrokePath.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiStrokePath(iHDC)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub

Public Sub WidenPath()
Attribute WidenPath.VB_HelpID = 2686
Attribute WidenPath.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiWidenPath(iHDC)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub

Public Sub BitBlt(XDest As Long, YDest As Long, Width As Long, Height As Long, source As dwDeviceContext, XSrc As Long, YSrc As Long, operation As Long)
Attribute BitBlt.VB_HelpID = 2484
Attribute BitBlt.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    If source.hDC = 0 Or iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiBitBlt(iHDC, XDest, YDest, Width, Height, source.hDC, XSrc, YSrc, operation)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Sub StretchBlt(XDest As Long, YDest As Long, Width As Long, Height As Long, source As dwDeviceContext, XSrc As Long, YSrc As Long, srcWidth As Long, srcHeight As Long, operation As Long)
Attribute StretchBlt.VB_HelpID = 2626
Attribute StretchBlt.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    If source.hDC = 0 Or iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiStretchBlt(iHDC, XDest, YDest, Width, Height, source.hDC, XSrc, YSrc, srcWidth, srcHeight, operation)
    If ret& = 0 Then RaiseHdcError
End Sub

Public Sub PatBlt(XDest As Long, YDest As Long, Width As Long, Height As Long, operation As Long)
Attribute PatBlt.VB_HelpID = 2590
Attribute PatBlt.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Dim ret&
    If iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiPatBlt(iHDC, XDest, YDest, Width, Height, operation)
    If ret& = 0 Then RaiseHdcError
End Sub

#If FlagBitmap = True Then
Public Sub MaskBlt(XDest As Long, YDest As Long, Width As Long, Height As Long, source As dwDeviceContext, XSrc As Long, YSrc As Long, myBitmap As dwBitmap, Xbitmap As Long, Ybitmap As Long, operation As Long)
Attribute MaskBlt.VB_HelpID = 2586
Attribute MaskBlt.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
#If Win32 Then
    Dim ret&
    If source.hDC = 0 Or iHDC = 0 Then RaiseHdcError DWERR_UNINITIALIZED
    ret& = apiMaskBlt(iHDC, XDest, YDest, Width, Height, source.hDC, XSrc, YSrc, myBitmap.hBitmap, Xbitmap, Ybitmap, operation)
    If ret& = 0 Then RaiseHdcError
#Else
    RaiseHdcError DWERR_NOTINWIN16
#End If
End Sub
#End If 'FlagBitMap

Property Get SRCAND() As Long
    SRCAND = &H8800C6
End Property

Property Get SRCCOPY() As Long
    SRCCOPY = &HCC0020
End Property

Property Get SRCERASE() As Long
    SRCERASE = &H440328
End Property

Property Get SRCINVERT() As Long
    SRCINVERT = &H660046
End Property

Property Get SRCPAINT() As Long
    SRCPAINT = &HEE0086
End Property


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' The following is for compatibility with the
' API Foundation Library Standard.  It is not a full
' implementation, as this library was completed before
' the final version of the standard was completed.
' There are also a number of functions that are not
' completed for lack of time or because adequate
' documentation was not provided.  The standard
' may change at any time after this libray is released,
' so the functions below may not be correct.

' The "Attach" functions are ways of setting up the
' class.  Most of the functions below are the same
' as the API functions above, but are renamed for
' some reason.

Public Sub Attach(vNewValue)
    If DCsource <> 3 Then ' if not a metafile
        If apiGetMapMode(vNewValue) = 0 Then RaiseHdcError 380
        DCsource = 2    ' Direct setting
        InitialSaveDC = apiSaveDC(iHDC)    ' Save initial state
        ClearDC         ' Clear existing DC info
    End If
    iHDC = vNewValue
    DeviceCaps.InitDevCaps iHDC
End Sub

Public Sub AttachWindow(wnd As dwWindow)
    GetWindowDC wnd
End Sub

Public Function ArcDirection() As Integer
Attribute ArcDirection.VB_HelpID = 2689
Attribute ArcDirection.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    ArcDirection = GetArcDirection()
End Function

Public Function CreateCompatible() As dwDeviceContext
Attribute CreateCompatible.VB_HelpID = 2495
Attribute CreateCompatible.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    Set CreateCompatible = CreateCompatibleDC()
End Function

Public Sub Delete()
    ClearDC
End Sub

Public Sub Detach()
    ClearDC
End Sub

Public Function DeviceCapability(capabilities As Long) As Long
Attribute DeviceCapability.VB_HelpID = 2522
Attribute DeviceCapability.VB_Description = "Help available in Visual Basic Programmer's Guide to Win32 API CD ROM"
    DeviceCapability = DeviceCaps.GetCapability(capabilities)
End Function

Public Sub DrawAngleArc(pPoint As dwPoint, dwRadius As Long, eStartAngle As Double, eSweepAngle As Double)
    AngleArc pPoint, dwRadius, eStartAngle, eSweepAngle
End Sub

Public Sub DrawArc(rRect As dwRECT, StartPoint As dwPoint, EndPoint As dwPoint)
    Dim tmpPoint1 As New dwPoint
    Dim tmpPoint2 As New dwPoint
    
    tmpPoint1.x = rRect.left
    tmpPoint1.y = rRect.top
    tmpPoint2.x = rRect.right
    tmpPoint2.y = rRect.bottom
    Arc tmpPoint1, tmpPoint2, StartPoint, EndPoint
End Sub

Public Sub DrawArcTo(rRect As dwRECT, StartPoint As dwPoint, EndPoint As dwPoint)
    Dim tmpPoint1 As New dwPoint
    Dim tmpPoint2 As New dwPoint
    
    tmpPoint1.x = rRect.left
    tmpPoint1.y = rRect.top
    tmpPoint2.x = rRect.right
    tmpPoint2.y = rRect.bottom
    ArcTo tmpPoint1, tmpPoint2, StartPoint, EndPoint
End Sub

Public Sub DrawChord(rRect As dwRECT, StartPoint As dwPoint, EndPoint As dwPoint)
    Dim tmpPoint1 As New dwPoint
    Dim tmpPoint2 As New dwPoint
    
    tmpPoint1.x = rRect.left
    tmpPoint1.y = rRect.top
    tmpPoint2.x = rRect.right
    tmpPoint2.y = rRect.bottom
    Chord tmpPoint1, tmpPoint2, StartPoint, EndPoint
End Sub

Public Sub DrawEllipse(rRect As dwRECT)
    Ellipse rRect
End Sub

Public Sub DrawLine(FromPoint As dwPoint, ToPoint As dwPoint)
    MoveTo FromPoint
    LineTo ToPoint
End Sub

Public Sub DrawLineTo(ToPoint As dwPoint)
    LineTo ToPoint
End Sub

Public Sub DrawPie(rRect As dwRECT, StartPoint As dwPoint, EndPoint As dwPoint)
    Dim tmpPoint1 As New dwPoint
    Dim tmpPoint2 As New dwPoint
    
    tmpPoint1.x = rRect.left
    tmpPoint1.y = rRect.top
    tmpPoint2.x = rRect.right
    tmpPoint2.y = rRect.bottom
    Pie tmpPoint1, tmpPoint2, StartPoint, EndPoint
End Sub

Public Sub DrawPolyBezier(points As Collection)
    PolyBezier points
End Sub

Public Sub DrawPolyBezierTo(points As Collection)
    PolyBezierTo points
End Sub

Public Sub DrawPolygon(points As Collection)
    Polygon points
End Sub

Public Sub DrawPolyline(points As Collection)
    Polyline points
End Sub

Public Sub DrawPloylineTo(points As Collection)
    PolylineTo points
End Sub

Public Sub DrawRectangle(rRect As dwRECT)
    Rectangle rRect
End Sub

Public Sub DrawRoundedRectangle(rRect As dwRECT, ByVal ElipseWidth, ByVal ElipseHeight)
    RoundRect rRect, ElipseWidth, ElipseHeight
End Sub

Public Sub FillRectangle(rRect As dwRECT, hBrush As dwBrush)
    FillRect rRect, hBrush
End Sub

Public Sub FrameRectangle(rRect As dwRECT, hBrush As dwBrush)
    FrameRect rRect, hBrush
End Sub

Public Sub FrameRegion(hRgn As dwRegion, hBrush As dwBrush, ByVal nWidth, ByVal nHeight)
    FrameRgn hRgn, hBrush, nWidth, nHeight
End Sub

Public Sub InvertRectangle(rRect As dwRECT)
    InvertRect rRect
End Sub

Public Sub InvertRegion(hRgn As dwRegion)
    InvertRgn hRgn
End Sub

Public Sub OffsetViewportOrigin(ByVal nX, ByVal nY)
    Dim tmpPoint As dwPoint
    
    OffsetViewportOrgEx nX, nY, tmpPoint
End Sub

Public Sub PaintRegion(hRgn As dwRegion)
    PaintRgn hRgn
End Sub

Public Property Get PolygonFillMode() As Long
    PolygonFillMode = GetPolyFillMode()
End Property

Public Property Let PolygonFillMode(ByVal vNewValue As Long)
    Call SetPolyFillMode(vNewValue)
End Property

Public Sub Restore(ByVal nSavedDC)
    RestoreDC nSavedDC
End Sub

Public Function Save() As Long
    SaveDC
    Save = True ' SaveDC will cause a VB error if there is a problem.
End Function

' You can replace these dwPoints with dwSizes to match the
' API Foundation Library Standard without other modification.
Public Function ScaleViewportExtent(ByVal nXnum, ByVal nXdenom, ByVal nYnum, ByVal nYdenom) As dwPoint
    Dim pSize As dwPoint
    
    ScaleViewportExtEx nXnum, nXdenom, nYnum, nYdenom, pSize
    Set ScaleViewportExtent = pSize
End Function

' You can replace these dwPoints with dwSizes to match the
' API Foundation Library Standard without other modification.
Public Function ScaleWindowExtent(ByVal nXnum, ByVal nXdenom, ByVal nYnum, ByVal nYdenom) As dwPoint
    Dim pSize As dwPoint

    ScaleWindowExtEx nXnum, nXdenom, nYnum, nYdenom, pSize
    Set ScaleWindowExtent = pSize
End Function

#If FlagBitmap Then
Public Sub SelectBitmap(bm As dwBitmap)
    SelectObjectBitmap bm
End Sub
#End If ' FlagBitmap

Public Sub SelectBrush(br As dwBrush)
    SelectObjectBrush br
End Sub

Public Sub SelectPen(pn As dwPen)
    SelectObjectPen pn
End Sub

Public Property Get ViewportExtent() As dwPoint
    Set ViewportExtent = GetViewportExtEx()
End Property

Public Property Let ViewportExtent(vNewValue As dwPoint)
    Dim tmpPoint As dwPoint
    SetViewportExtEx vNewValue.x, vNewValue.y, tmpPoint
End Property

Public Property Get ViewportOrigin() As dwPoint
    Set ViewportOrigin = GetViewportOrgEx()
End Property

Public Property Let ViewportOrigin(vNewValue As dwPoint)
    Dim tmpPoint As dwPoint
    SetViewportOrgEx vNewValue.x, vNewValue.y, tmpPoint
End Property

Public Property Get WindowExtent() As dwPoint
    Set WindowExtent = GetWindowExtEx()
End Property

Public Property Let WindowExtent(vNewValue As dwPoint)
    Dim tmpPoint As dwPoint
    SetWindowExtEx vNewValue.x, vNewValue.y, tmpPoint
End Property

Public Property Get WindowOrigin() As dwPoint
    Set WindowOrigin = GetWindowOrgEx()
End Property

Public Property Let WindowOrigin(vNewValue As dwPoint)
    Dim tmpPoint As dwPoint
    SetWindowOrgEx vNewValue.x, vNewValue.y, tmpPoint
End Property

