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 / samples4 / ch08 / extpen.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  13.0 KB  |  382 lines

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