home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / ch_code / ch13 / apidraw / apidraw.frm (.txt) next >
Encoding:
Visual Basic Form  |  1996-04-30  |  4.5 KB  |  125 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Begin VB.Form APIDrawingForm 
  4.    AutoRedraw      =   -1  'True
  5.    BackColor       =   &H00FFFFFF&
  6.    Caption         =   "Drawing with API Functions"
  7.    ClientHeight    =   5400
  8.    ClientLeft      =   60
  9.    ClientTop       =   345
  10.    ClientWidth     =   7710
  11.    DrawWidth       =   2
  12.    FillColor       =   &H80000017&
  13.    ForeColor       =   &H000000FF&
  14.    LinkTopic       =   "Form1"
  15.    ScaleHeight     =   360
  16.    ScaleMode       =   3  'Pixel
  17.    ScaleWidth      =   514
  18.    StartUpPosition =   3  'Windows Default
  19.    Begin VB.CommandButton Command2 
  20.       Caption         =   "Fill Color"
  21.       BeginProperty Font 
  22.          Name            =   "Verdana"
  23.          Size            =   9.75
  24.          Charset         =   0
  25.          Weight          =   400
  26.          Underline       =   0   'False
  27.          Italic          =   0   'False
  28.          Strikethrough   =   0   'False
  29.       EndProperty
  30.       Height          =   495
  31.       Left            =   120
  32.       TabIndex        =   1
  33.       Top             =   4800
  34.       Width           =   1935
  35.    End
  36.    Begin MSComDlg.CommonDialog CommonDialog1 
  37.       Left            =   2160
  38.       Top             =   4800
  39.       _ExtentX        =   847
  40.       _ExtentY        =   847
  41.       _Version        =   393216
  42.    End
  43.    Begin VB.CommandButton Command1 
  44.       Caption         =   "Draw Now!"
  45.       BeginProperty Font 
  46.          Name            =   "Verdana"
  47.          Size            =   9.75
  48.          Charset         =   0
  49.          Weight          =   400
  50.          Underline       =   0   'False
  51.          Italic          =   0   'False
  52.          Strikethrough   =   0   'False
  53.       EndProperty
  54.       Height          =   495
  55.       Left            =   5640
  56.       TabIndex        =   0
  57.       Top             =   4800
  58.       Width           =   1935
  59.    End
  60. Attribute VB_Name = "APIDrawingForm"
  61. Attribute VB_GlobalNameSpace = False
  62. Attribute VB_Creatable = False
  63. Attribute VB_PredeclaredId = True
  64. Attribute VB_Exposed = False
  65. '  ******************************
  66. '  ******************************
  67. '  ** MASTERING VB6            **
  68. '  ** by Evangelos Petroutos   **
  69. '  ** SYBEX, 1998              **
  70. '  ******************************
  71. '  ******************************
  72. Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
  73. Private Declare Function Ellipse Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
  74. Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
  75. Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
  76. Private Declare Function ExtFloodFill Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long, ByVal wFillType As Long) As Long
  77. Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
  78. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  79. Private Const FLOODFILLBORDER = 0
  80. Private Const FLOODFILLSURFACE = 1
  81. Private Type POINTAPI
  82.     x As Long
  83.     y As Long
  84. End Type
  85. Private Sub Command1_Click()
  86. Dim point As POINTAPI
  87.     Me.Cls
  88.     Me.ForeColor = RGB(255, 0, 0)
  89.     ' draw first ellipse's bounding rectangle
  90.     MoveToEx Me.hdc, 10, 10, point
  91.     LineTo Me.hdc, 500, 10
  92.     LineTo Me.hdc, 500, 300
  93.     LineTo Me.hdc, 10, 300
  94.     LineTo Me.hdc, 10, 10
  95.     ' draw first ellipse
  96.     Ellipse Me.hdc, 10, 10, 500, 300
  97.     Me.ForeColor = RGB(0, 0, 255)
  98.     ' draw second ellipse's bounding rectangle
  99.     MoveToEx Me.hdc, 10, 10, point
  100.     LineTo Me.hdc, 300, 10
  101.     LineTo Me.hdc, 300, 300
  102.     LineTo Me.hdc, 10, 300
  103.     LineTo Me.hdc, 10, 10
  104.     ' draw second ellipse
  105.     ' because the rectangle is square, a circle is drawn
  106.     Ellipse Me.hdc, 10, 10, 300, 300
  107. End Sub
  108. Private Sub Command2_Click()
  109. On Error GoTo ClrError
  110.     CommonDialog1.CancelError = True
  111.     CommonDialog1.ShowColor
  112.     Exit Sub
  113. ClrError:
  114. End Sub
  115. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  116.     ' create solid brush object
  117.     brush = CreateSolidBrush(CommonDialog1.Color)
  118.     ' select it into the current device context
  119.     SelectObject Me.hdc, brush
  120.     ' fill area with selected brush
  121.     ExtFloodFill Me.hdc, x, y, Me.point(x, y), FLOODFILLSURFACE
  122.     ' brush object no longer needed, delete it
  123.     DeleteObject brush
  124. End Sub
  125.