home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "QUIKDRAW1"
- Option Explicit
- ' QuikDraw program example
- ' This version of QuickDraw uses the Desaware
- ' API Class Library.
-
-
- #If Win32 Then
- ' Not all functions or data types are in the Class
- ' Library.
- Type METAFILEPICT
- mm As Long
- xExt As Long
- yExt As Long
- hMF As Long
- End Type
-
- Type METARECORD
- rdSize As Long
- rdFunction As Integer
- rdParm(1) As Integer
- End Type
-
- Declare Function CloseClipboard& Lib "user32" ()
- Declare Function EmptyClipboard& Lib "user32" ()
- Declare Function GetObjectType& Lib "gdi32" (ByVal hgdiobj As Long)
- Declare Function OpenClipboard& Lib "user32" (ByVal hwnd As Long)
- Declare Function SetClipboardData& Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long)
-
- Declare Function lopen Lib "kernel32" Alias "_lopen" (ByVal lpPathName As String, ByVal iReadWrite As Long) As Long
- Declare Function lclose Lib "kernel32" Alias "_lclose" (ByVal hFile As Long) As Long
- Declare Function lcreat Lib "kernel32" Alias "_lcreat" (ByVal lpPathName As String, ByVal iAttribute As Long) As Long
- Declare Function llseek Lib "kernel32" Alias "_llseek" (ByVal hFile As Long, ByVal lOffset As Long, ByVal iOrigin As Long) As Long
- Declare Function lread Lib "kernel32" Alias "_lread" (ByVal hFile As Long, lpbuffer As Any, ByVal wBytes As Long) As Long
- Declare Function lwrite Lib "kernel32" Alias "_lwrite" (ByVal hFile As Long, lpbuffer As Any, ByVal wBytes As Long) As Long
-
- Declare Function hread Lib "kernel32" Alias "_hread" (ByVal hFile As Long, lpbuffer As Any, ByVal lBytes As Long) As Long
- Declare Function hwrite Lib "kernel32" Alias "_hwrite" (ByVal hFile As Long, lpbuffer As Any, ByVal lBytes As Long) As Long
-
- #Else
-
- Type METAFILEPICT '8 Bytes
- mm As Integer
- xExt As Integer
- yExt As Integer
- hMF As Integer
- End Type
-
- Declare Function CloseClipboard% Lib "user" ()
- Declare Function EmptyClipboard% Lib "user" ()
- Declare Function OpenClipboard% Lib "user" (ByVal hwnd%)
- Declare Function SetClipboardData% Lib "user" (ByVal wFormat%, ByVal hMem%)
-
- Declare Function lopen% Lib "kernel" Alias "_lopen" (ByVal lpPathName$, ByVal iReadWrite%)
- Declare Function lclose% Lib "kernel" Alias "_lclose" (ByVal hFile%)
- Declare Function lcreat% Lib "kernel" Alias "_lcreat" (ByVal lpPathName$, ByVal iAttribute%)
- Declare Function llseek& Lib "kernel" Alias "_llseek" (ByVal hFile%, ByVal lOffset&, ByVal iOrigin%)
- Declare Function lread% Lib "kernel" Alias "_lread" (ByVal hFile%, lpbuffer As Any, ByVal wBytes%)
- Declare Function lwrite% Lib "kernel" Alias "_lwrite" (ByVal hFile%, lpbuffer As Any, ByVal wBytes%)
- Declare Function hread& Lib "kernel" Alias "_hread" (ByVal hf%, hpvBuffer As Any, ByVal cbBuffer&)
- Declare Function hwrite& Lib "kernel" Alias "_hwrite" (ByVal hf%, hpvBuffer As Any, ByVal cbBuffer&)
-
- #End If
-
- Type RECTS
- left As Integer
- top As Integer
- right As Integer
- bottom As Integer
- End Type
-
- Type METAFILEHEADER ' 22 bytes
- key As Long
- hMF As Integer
- bbox As RECTS
- inch As Integer
- Reserved As Long
- checksum As Integer
- End Type
-
- ' Application global variables
-
- ' Metafile to hold objects
- Public MetaFile As dwMetaFile
-
- ' Private Pen and Brush to use
- Public Pen As New dwPen
- Public Brush As New dwBrush
-
- Public MaxPoints% ' Maximum points to use this drawing mode
- Public PointsUsed% ' Number of points used.
- ' collection of dwPoints
- Public PointCollection As New Collection
-
- ' Current drawing mode - most recent Draw menu index
- Public LastDrawIndex%
-
- ' This flag is set to -1 after the Execute button is pressed.
- ' This is an indication that the next click in Picture1 should
- ' start a new object.
- Public LastWasExecute%
-
-
- ' Public constants imported from APICONST.TXT
- Public Const R2_BLACK = 1
- Public Const R2_NOTMERGEPEN = 2
- Public Const R2_MASKNOTPEN = 3
- Public Const R2_NOTCOPYPEN = 4
- Public Const R2_MASKPENNOT = 5
- Public Const R2_NOT = 6
- Public Const R2_XORPEN = 7
- Public Const R2_NOTMASKPEN = 8
- Public Const R2_MASKPEN = 9
- Public Const R2_NOTXORPEN = 10
- Public Const R2_NOP = 11
- Public Const R2_MERGENOTPEN = 12
- Public Const R2_COPYPEN = 13
- Public Const R2_MERGEPENNOT = 14
- Public Const R2_MERGEPEN = 15
- Public Const R2_WHITE = 16
- Public Const ALTERNATE = 1
- Public Const WINDING = 2
- Public Const TRANSPARENT = 1
- Public Const OPAQUE = 2
- Public Const MM_TEXT = 1
- Public Const MM_LOMETRIC = 2
- Public Const MM_HIMETRIC = 3
- Public Const MM_LOENGLISH = 4
- Public Const MM_HIENGLISH = 5
- Public Const MM_TWIPS = 6
- Public Const MM_ISOTROPIC = 7
- Public Const MM_ANISOTROPIC = 8
- Public Const ABSOLUTE = 1
- Public Const RELATIVE = 2
- Public Const WHITE_BRUSH = 0
- Public Const LTGRAY_BRUSH = 1
- Public Const GRAY_BRUSH = 2
- Public Const DKGRAY_BRUSH = 3
- Public Const BLACK_BRUSH = 4
- Public Const NULL_BRUSH = 5
- Public Const HOLLOW_BRUSH = NULL_BRUSH ' change references to this
- Public Const WHITE_PEN = 6
- Public Const BLACK_PEN = 7
- Public Const NULL_PEN = 8
- Public Const OEM_FIXED_FONT = 10
- Public Const ANSI_FIXED_FONT = 11
- Public Const ANSI_VAR_FONT = 12
- Public Const SYSTEM_FONT = 13
- Public Const DEVICE_DEFAULT_FONT = 14
- Public Const DEFAULT_PALETTE = 15
- Public Const SYSTEM_FIXED_FONT = 16
- Public Const PS_SOLID = 0
- Public Const PS_DASH = 1
- Public Const PS_DOT = 2
- Public Const PS_DASHDOT = 3
- Public Const PS_DASHDOTDOT = 4
- Public Const PS_NULL = 5
- Public Const PS_INSIDEFRAME = 6
- Public Const HS_HORIZONTAL = 0
- Public Const HS_VERTICAL = 1
- Public Const HS_FDIAGONAL = 2
- Public Const HS_BDIAGONAL = 3
- Public Const HS_CROSS = 4
- Public Const HS_DIAGCROSS = 5
-
- Public Const GMEM_MOVEABLE = &H2
- Public Const CF_METAFILEPICT = 3
- Public Const GMEM_ZEROINIT = &H40
-
- Function LoadTheMetafile(filename$) As dwMetaFile
- #If Win32 Then
- Dim fhnd&
- Dim di&, dl&
- Dim mfglbhnd&
-
- #Else
- Dim fhnd%
- Dim di%, dl&
- Dim mfglbhnd%
- #End If
- Dim mf As New dwMetaFile
- Dim gmem As New dwGlobalMemory
- Dim sys As New dwSystem
- Dim mfile As METAFILEHEADER
- Dim mfinfosize&
- Dim currentfileloc&
- Dim gptr&
-
- ' Open the file to read
- fhnd = lopen(filename$, 0)
- If fhnd < 0 Then Exit Function
-
- ' First read the placeable header file header
- di = lread(fhnd, mfile, Len(mfile))
- If mfile.key <> &H9AC6CDD7 Then
- ' It's not a placeable metafile - so just seek to the start
- di = llseek(fhnd, 0, 0)
- End If
-
- ' Now we need a buffer that will contain the metafile data
- currentfileloc& = llseek(fhnd, 0, 1)
- mfinfosize& = llseek(fhnd, 0, 2) - currentfileloc&
-
-
- ' Now allocate a buffer to hold the data
- ' We use the Global memory pool because this buffer
- ' could easily be above 64k bytes.
- Set gmem = sys.GlobalAlloc(GMEM_MOVEABLE, mfinfosize)
- gptr& = gmem.GlobalLock()
- dl = llseek(fhnd, currentfileloc, 0)
-
- dl = hread(fhnd, ByVal gptr, mfinfosize)
-
- ' Win32 does not support the SetMetaFileBitsBetter function
- #If Win32 Then
- ' If we were using a byte array, we could use
- ' the original definition of SetMetaFileBitsEx, but
- ' we want to preserve 16 bit compatibility
- Set mf = gmem.SetMetafileBits()
- gmem.GlobalUnlock
- #Else
- gmem.GlobalUnlock
- Set mf = gmem.SetMetafileBits()
- #End If
-
- di = lclose(fhnd)
-
- ' Don't delete the global handle - it holds the metafile data
- Set LoadTheMetafile = mf
- End Function
-
- '
- '
- ' Even though xExt and yExt are longs, they are limited to integer
- ' values to stay compatible with the METAFILEHEADER structure
- '
- Function SaveTheMetafile(filename$, mfhnd As dwMetaFile, xExt&, yExt&)
- #If Win32 Then
- Dim fhnd&
- Dim di&, dl&
- #Else
- Dim fhnd%
- Dim di%, dl&
- #End If
- Dim sys As New dwSystem
- Dim DC As dwDeviceContext
- Dim newmf As New dwMetaFile
- Dim gmem As New dwGlobalMemory
- Dim mfile As METAFILEHEADER
- Dim mfinfosize&
- Dim currentfileloc&
- Dim gptr&
-
- Dim oldsize As New dwPoint
-
- ' Open the file to write
- fhnd = lcreat(filename$, 0)
- fhnd = lopen(filename$, 2)
- If fhnd < 0 Then Exit Function
- If mfhnd Is Nothing Then Exit Function
-
-
- ' First write a placeable header file header
- mfile.key = &H9AC6CDD7 ' The key - required
- mfile.hMF = 0 ' Must be 0
- mfile.bbox.left = 0
- mfile.bbox.top = 0
- ' These should be calculated using GetDeviceCaps
- mfile.bbox.right = xExt + 1 ' Size in metafile units of bounding area
- mfile.bbox.bottom = yExt + 1
- mfile.inch = 1000 ' Number of metafile units per inch
-
- mfile.Reserved = 0
- ' Build the checksum
- mfile.checksum = &H9AC6 Xor &HCDD7
- mfile.checksum = mfile.checksum Xor mfile.bbox.right
- mfile.checksum = mfile.checksum Xor mfile.bbox.bottom
- mfile.checksum = mfile.checksum Xor mfile.inch
-
-
- ' Write the buffer
- di = lwrite(fhnd, mfile, Len(mfile))
-
- ' Now we retrieve a handle that will contain the
- ' metafile - We make a copy, but first we set the
- ' extents so that it can be properly displayed
- Set DC = sys.CreateMetafile(vbNullString)
- DC.SetWindowExtEx xExt, yExt, oldsize
- di = DC.SetMapMode(MM_ANISOTROPIC)
- DC.PlayMetaFile mfhnd
- Set newmf = DC.CloseMetafile()
-
- #If Win32 Then
- ' Find out how bit the buffer needs to be
- mfinfosize = newmf.GetMetafileBitsSize()
- If mfinfosize = 0 Then
- di = lclose(fhnd)
- Exit Function
- End If
- Set gmem = sys.GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, mfinfosize)
- gptr = gmem.GlobalLock()
- newmf.GetMetafileBitsByAddr mfinfosize, ByVal gptr
- #Else
- Set gmem = newmf.GetMetafileBitsByAddr()
- gptr = gmem.GlobalLock()
- mfinfosize = gmem.GlobalSize()
- #End If
-
-
- dl = hwrite(fhnd, ByVal gptr, mfinfosize)
-
- gmem.GlobalUnlock
- gmem.GlobalFree
- di = lclose(fhnd)
-
- End Function
-
-