home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / vbpg32 / samples5 / ch08 / extpen.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  13.0 KB  |  381 lines

  1. VERSION 5.00
  2. Begin VB.Form frmExtPen 
  3.    Caption         =   "Extended Pen Testing"
  4.    ClientHeight    =   4785
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1515
  7.    ClientWidth     =   5865
  8.    LinkTopic       =   "Form1"
  9.    PaletteMode     =   1  'UseZOrder
  10.    ScaleHeight     =   4785
  11.    ScaleWidth      =   5865
  12.    Begin VB.CheckBox chkCross 
  13.       Caption         =   "Cross Pattern"
  14.       Height          =   195
  15.       Left            =   3660
  16.       TabIndex        =   22
  17.       Top             =   3720
  18.       Width           =   1755
  19.    End
  20.    Begin VB.HScrollBar scrMiter 
  21.       Height          =   255
  22.       Left            =   4980
  23.       Max             =   20
  24.       Min             =   1
  25.       TabIndex        =   18
  26.       Top             =   4020
  27.       Value           =   10
  28.       Width           =   795
  29.    End
  30.    Begin VB.Frame Frame4 
  31.       Caption         =   "Join"
  32.       Height          =   1275
  33.       Left            =   3480
  34.       TabIndex        =   14
  35.       Top             =   1380
  36.       Width           =   2355
  37.       Begin VB.OptionButton chkJoin 
  38.          Caption         =   "Round"
  39.          Height          =   255
  40.          Index           =   2
  41.          Left            =   120
  42.          TabIndex        =   17
  43.          Top             =   840
  44.          Width           =   2175
  45.       End
  46.       Begin VB.OptionButton chkJoin 
  47.          Caption         =   "Miter"
  48.          Height          =   255
  49.          Index           =   1
  50.          Left            =   120
  51.          TabIndex        =   16
  52.          Top             =   540
  53.          Width           =   2175
  54.       End
  55.       Begin VB.OptionButton chkJoin 
  56.          Caption         =   "Bevel"
  57.          Height          =   255
  58.          Index           =   0
  59.          Left            =   120
  60.          TabIndex        =   15
  61.          Top             =   240
  62.          Value           =   -1  'True
  63.          Width           =   2175
  64.       End
  65.    End
  66.    Begin VB.Frame Frame3 
  67.       Caption         =   "EndCap"
  68.       Height          =   1215
  69.       Left            =   3480
  70.       TabIndex        =   10
  71.       Top             =   120
  72.       Width           =   2355
  73.       Begin VB.OptionButton chkEndcap 
  74.          Caption         =   "Flat"
  75.          Height          =   255
  76.          Index           =   2
  77.          Left            =   180
  78.          TabIndex        =   13
  79.          Top             =   840
  80.          Width           =   1635
  81.       End
  82.       Begin VB.OptionButton chkEndcap 
  83.          Caption         =   "Square"
  84.          Height          =   255
  85.          Index           =   1
  86.          Left            =   180
  87.          TabIndex        =   12
  88.          Top             =   540
  89.          Width           =   1635
  90.       End
  91.       Begin VB.OptionButton chkEndcap 
  92.          Caption         =   "Round"
  93.          Height          =   255
  94.          Index           =   0
  95.          Left            =   180
  96.          TabIndex        =   11
  97.          Top             =   240
  98.          Value           =   -1  'True
  99.          Width           =   1635
  100.       End
  101.    End
  102.    Begin VB.HScrollBar scrWidth 
  103.       Height          =   255
  104.       Left            =   4980
  105.       Max             =   10
  106.       Min             =   1
  107.       TabIndex        =   8
  108.       Top             =   4380
  109.       Value           =   1
  110.       Width           =   795
  111.    End
  112.    Begin VB.Frame Frame2 
  113.       Caption         =   "Style"
  114.       Height          =   1395
  115.       Left            =   180
  116.       TabIndex        =   4
  117.       Top             =   3240
  118.       Width           =   3135
  119.       Begin VB.OptionButton chkStyle 
  120.          Caption         =   "User ___ . . _"
  121.          Height          =   255
  122.          Index           =   2
  123.          Left            =   120
  124.          TabIndex        =   7
  125.          Top             =   960
  126.          Width           =   1695
  127.       End
  128.       Begin VB.OptionButton chkStyle 
  129.          Caption         =   "Dash"
  130.          Height          =   255
  131.          Index           =   1
  132.          Left            =   120
  133.          TabIndex        =   6
  134.          Top             =   600
  135.          Width           =   1695
  136.       End
  137.       Begin VB.OptionButton chkStyle 
  138.          Caption         =   "Solid"
  139.          Height          =   255
  140.          Index           =   0
  141.          Left            =   120
  142.          TabIndex        =   5
  143.          Top             =   240
  144.          Value           =   -1  'True
  145.          Width           =   1695
  146.       End
  147.    End
  148.    Begin VB.Frame Frame1 
  149.       Caption         =   "Type"
  150.       Height          =   975
  151.       Left            =   3480
  152.       TabIndex        =   1
  153.       Top             =   2700
  154.       Width           =   2355
  155.       Begin VB.OptionButton chkType 
  156.          Caption         =   "Geometric"
  157.          Height          =   315
  158.          Index           =   1
  159.          Left            =   180
  160.          TabIndex        =   3
  161.          Top             =   540
  162.          Width           =   1455
  163.       End
  164.       Begin VB.OptionButton chkType 
  165.          Caption         =   "Cosmetic"
  166.          Height          =   255
  167.          Index           =   0
  168.          Left            =   180
  169.          TabIndex        =   2
  170.          Top             =   240
  171.          Value           =   -1  'True
  172.          Width           =   1635
  173.       End
  174.    End
  175.    Begin VB.PictureBox Picture1 
  176.       Height          =   2895
  177.       Left            =   180
  178.       ScaleHeight     =   191
  179.       ScaleMode       =   3  'Pixel
  180.       ScaleWidth      =   203
  181.       TabIndex        =   0
  182.       Top             =   180
  183.       Width           =   3075
  184.    End
  185.    Begin VB.Label lblWidth 
  186.       Caption         =   "1"
  187.       Height          =   255
  188.       Left            =   4620
  189.       TabIndex        =   21
  190.       Top             =   4380
  191.       Width           =   315
  192.    End
  193.    Begin VB.Label lblMiter 
  194.       Caption         =   "10"
  195.       Height          =   255
  196.       Left            =   4620
  197.       TabIndex        =   20
  198.       Top             =   4020
  199.       Width           =   315
  200.    End
  201.    Begin VB.Label Label2 
  202.       Alignment       =   1  'Right Justify
  203.       Caption         =   "Miter limit:"
  204.       Height          =   255
  205.       Left            =   3720
  206.       TabIndex        =   19
  207.       Top             =   4020
  208.       Width           =   795
  209.    End
  210.    Begin VB.Label Label1 
  211.       Alignment       =   1  'Right Justify
  212.       Caption         =   "Width:"
  213.       Height          =   255
  214.       Left            =   3660
  215.       TabIndex        =   9
  216.       Top             =   4380
  217.       Width           =   855
  218.    End
  219. Attribute VB_Name = "frmExtPen"
  220. Attribute VB_GlobalNameSpace = False
  221. Attribute VB_Creatable = False
  222. Attribute VB_PredeclaredId = True
  223. Attribute VB_Exposed = False
  224. Option Explicit
  225. ' Copyright 
  226.  1997 by Desaware Inc. All Rights Reserved
  227. Dim ExtendedPen&
  228. Dim CustomStyle(8) As Long
  229. Private Const CustomStyleLength = 8
  230. Dim BrushInfo As LOGBRUSH
  231. Private Declare Function BeginPath Lib "gdi32" (ByVal hdc As Long) As Long
  232. Private Declare Function EndPath Lib "gdi32" (ByVal hdc As Long) As Long
  233. Private Declare Function StrokePath Lib "gdi32" (ByVal hdc As Long) As Long
  234. Private Declare Function ExtCreatePen Lib "gdi32" (ByVal dwPenStyle As Long, ByVal dwWidth As Long, lplb As LOGBRUSH, ByVal dwStyleCount As Long, lpStyle As Any) As Long
  235. Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
  236. Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
  237. 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
  238. Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
  239. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  240. Private Declare Function SetMiterLimit Lib "gdi32" (ByVal hdc As Long, ByVal eNewLimit As Single, peOldLimit As Single) As Long
  241. Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
  242. Private Type POINTAPI
  243.         x As Long
  244.         y As Long
  245. End Type
  246. Private Type LOGBRUSH
  247.         lbStyle As Long
  248.         lbColor As Long
  249.         lbHatch As Long
  250. End Type
  251. Private Const PS_SOLID = 0
  252. Private Const PS_DASH = 1                    '  -------
  253. Private Const PS_DOT = 2                     '  .......
  254. Private Const PS_DASHDOT = 3                 '  _._._._
  255. Private Const PS_DASHDOTDOT = 4              '  _.._.._
  256. Private Const PS_NULL = 5
  257. Private Const PS_INSIDEFRAME = 6
  258. Private Const PS_USERSTYLE = 7
  259. Private Const PS_ALTERNATE = 8
  260. Private Const PS_STYLE_MASK = &HF
  261. Private Const PS_ENDCAP_ROUND = &H0
  262. Private Const PS_ENDCAP_SQUARE = &H100
  263. Private Const PS_ENDCAP_FLAT = &H200
  264. Private Const PS_ENDCAP_MASK = &HF00
  265. Private Const PS_JOIN_ROUND = &H0
  266. Private Const PS_JOIN_BEVEL = &H1000
  267. Private Const PS_JOIN_MITER = &H2000
  268. Private Const PS_JOIN_MASK = &HF000
  269. Private Const PS_COSMETIC = &H0
  270. Private Const PS_GEOMETRIC = &H10000
  271. Private Const PS_TYPE_MASK = &HF0000
  272. Private Const BS_SOLID = 0
  273. Private Const BS_NULL = 1
  274. Private Const BS_HOLLOW = BS_NULL
  275. Private Const BS_HATCHED = 2
  276. Private Const BS_PATTERN = 3
  277. Private Const BS_INDEXED = 4
  278. Private Const BS_DIBPATTERN = 5
  279. Private Const BS_DIBPATTERNPT = 6
  280. Private Const BS_PATTERN8X8 = 7
  281. Private Const BS_DIBPATTERN8X8 = 8
  282. '  Hatch Styles
  283. Private Const HS_HORIZONTAL = 0              '  -----
  284. Private Const HS_VERTICAL = 1                '  |||||
  285. Private Const HS_FDIAGONAL = 2               '  \\\\\
  286. Private Const HS_BDIAGONAL = 3               '  /////
  287. Private Const HS_CROSS = 4                   '  +++++
  288. Private Const HS_DIAGCROSS = 5               '  xxxxx
  289. Private Sub chkCross_Click()
  290.     Picture1.Refresh
  291. End Sub
  292. Private Sub chkEndcap_Click(Index As Integer)
  293.     Picture1.Refresh
  294. End Sub
  295. Private Sub chkJoin_Click(Index As Integer)
  296.    Picture1.Refresh
  297. End Sub
  298. Private Sub chkStyle_Click(Index As Integer)
  299.     Picture1.Refresh
  300. End Sub
  301. Private Sub chkType_Click(Index As Integer)
  302.     Picture1.Refresh
  303. End Sub
  304. Private Sub Form_Load()
  305.     CustomStyle(0) = 3
  306.     CustomStyle(1) = 1
  307.     CustomStyle(2) = 1
  308.     CustomStyle(3) = 2
  309.     CustomStyle(4) = 1
  310.     CustomStyle(5) = 2
  311.     CustomStyle(6) = 1
  312.     CustomStyle(7) = 2
  313.     BrushInfo.lbColor = RGB(0, 255, 0)
  314.     BrushInfo.lbHatch = HS_CROSS
  315. End Sub
  316. Private Sub DoPenUpdate()
  317.     Dim di&
  318.     Dim pentype&, penstyle&, endcap&, join&
  319.     Dim usewidth&
  320.     ' Delete the pen if it exists
  321.     If ExtendedPen Then di = DeleteObject(ExtendedPen)
  322.     If chkType(0).Value Then pentype = PS_COSMETIC Else pentype = PS_GEOMETRIC
  323.     If chkStyle(0).Value Then penstyle = PS_SOLID
  324.     If chkStyle(1).Value Then penstyle = PS_DASH
  325.     If chkStyle(2).Value Then penstyle = PS_USERSTYLE
  326.     If chkEndcap(0).Value Then endcap = PS_ENDCAP_ROUND
  327.     If chkEndcap(1).Value Then endcap = PS_ENDCAP_SQUARE
  328.     If chkEndcap(2).Value Then endcap = PS_ENDCAP_FLAT
  329.     If chkJoin(0).Value Then join = PS_JOIN_BEVEL
  330.     If chkJoin(1).Value Then join = PS_JOIN_MITER
  331.     If chkJoin(2).Value Then join = PS_JOIN_ROUND
  332.     ' Set the pen style
  333.     If chkCross.Value = 1 Then BrushInfo.lbStyle = BS_HATCHED Else BrushInfo.lbStyle = BS_SOLID
  334.     If pentype = PS_COSMETIC Then usewidth = 1 Else usewidth = scrWidth.Value
  335.     If penstyle = PS_USERSTYLE Then
  336.         ExtendedPen = ExtCreatePen(pentype Or penstyle Or endcap Or join, usewidth, BrushInfo, CustomStyleLength, CustomStyle(0))
  337.     Else
  338.         ExtendedPen = ExtCreatePen(pentype Or penstyle Or endcap Or join, usewidth, BrushInfo, 0, ByVal 0&)
  339.     End If
  340. End Sub
  341. Private Sub Form_Unload(Cancel As Integer)
  342.     Dim di&
  343.     If ExtendedPen Then di = DeleteObject(ExtendedPen)
  344. End Sub
  345. Private Sub Picture1_Paint()
  346.     Dim di&
  347.     Dim pt As POINTAPI
  348.     Dim oldpen&
  349.     Dim oldmiter As Single
  350.     Dim newmiter As Single
  351.     DoPenUpdate
  352.     newmiter = scrMiter
  353.     di = SetMiterLimit(Picture1.hdc, newmiter, oldmiter)
  354.     oldpen = SelectObject(Picture1.hdc, ExtendedPen&)
  355.     di = MoveToEx(Picture1.hdc, 10, 150, pt)
  356.     di = LineTo(Picture1.hdc, 10, 20)
  357.     di = LineTo(Picture1.hdc, 40, 150)
  358.     di = LineTo(Picture1.hdc, 50, 20)
  359.     di = LineTo(Picture1.hdc, 70, 20)
  360.     di = LineTo(Picture1.hdc, 70, 150)
  361.     di = BeginPath(Picture1.hdc)
  362.     di = MoveToEx(Picture1.hdc, 100, 150, pt)
  363.     di = LineTo(Picture1.hdc, 100, 20)
  364.     di = LineTo(Picture1.hdc, 130, 150)
  365.     di = LineTo(Picture1.hdc, 140, 20)
  366.     di = LineTo(Picture1.hdc, 160, 20)
  367.     di = LineTo(Picture1.hdc, 160, 150)
  368.     di = EndPath(Picture1.hdc)
  369.     di = StrokePath(Picture1.hdc)
  370.     di = SelectObject(Picture1.hdc, oldpen)
  371.     di = SetMiterLimit(Picture1.hdc, oldmiter, newmiter)
  372. End Sub
  373. Private Sub scrMiter_Change()
  374.     lblMiter.Caption = Str$(scrMiter.Value)
  375.     Picture1.Refresh
  376. End Sub
  377. Private Sub scrWidth_Change()
  378.     lblWidth.Caption = Str$(scrWidth.Value)
  379.     Picture1.Refresh
  380. End Sub
  381.