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 / ch09 / roptest.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  14.3 KB  |  431 lines

  1. VERSION 4.00
  2. Begin VB.Form frmROPTest 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H00C0C0C0&
  5.    Caption         =   "Raster Op Test"
  6.    ClientHeight    =   6660
  7.    ClientLeft      =   1095
  8.    ClientTop       =   1470
  9.    ClientWidth     =   5490
  10.    BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  11.       Name            =   "MS Sans Serif"
  12.       Size            =   8.25
  13.       Charset         =   0
  14.       Weight          =   700
  15.       Underline       =   0   'False
  16.       Italic          =   0   'False
  17.       Strikethrough   =   0   'False
  18.    EndProperty
  19.    ForeColor       =   &H80000008&
  20.    Height          =   7065
  21.    Left            =   1035
  22.    LinkTopic       =   "Form1"
  23.    ScaleHeight     =   6660
  24.    ScaleWidth      =   5490
  25.    Top             =   1125
  26.    Width           =   5610
  27.    Begin VB.TextBox txtUserDef 
  28.       Appearance      =   0  'Flat
  29.       Height          =   315
  30.       Left            =   2940
  31.       TabIndex        =   21
  32.       Top             =   5640
  33.       Width           =   2055
  34.    End
  35.    Begin VB.OptionButton Option1 
  36.       Appearance      =   0  'Flat
  37.       BackColor       =   &H00C0C0C0&
  38.       Caption         =   "WHITENESS"
  39.       ForeColor       =   &H80000008&
  40.       Height          =   315
  41.       Index           =   14
  42.       Left            =   1980
  43.       TabIndex        =   20
  44.       Top             =   5220
  45.       Width           =   1815
  46.    End
  47.    Begin VB.OptionButton Option1 
  48.       Appearance      =   0  'Flat
  49.       BackColor       =   &H00C0C0C0&
  50.       Caption         =   "BLACKNESS"
  51.       ForeColor       =   &H80000008&
  52.       Height          =   315
  53.       Index           =   13
  54.       Left            =   1980
  55.       TabIndex        =   19
  56.       Top             =   4860
  57.       Width           =   1815
  58.    End
  59.    Begin VB.OptionButton Option1 
  60.       Appearance      =   0  'Flat
  61.       BackColor       =   &H00C0C0C0&
  62.       Caption         =   "DSTINVERT"
  63.       ForeColor       =   &H80000008&
  64.       Height          =   315
  65.       Index           =   12
  66.       Left            =   1980
  67.       TabIndex        =   18
  68.       Top             =   4500
  69.       Width           =   1815
  70.    End
  71.    Begin VB.OptionButton Option1 
  72.       Appearance      =   0  'Flat
  73.       BackColor       =   &H00C0C0C0&
  74.       Caption         =   "PATINVERT"
  75.       ForeColor       =   &H80000008&
  76.       Height          =   315
  77.       Index           =   11
  78.       Left            =   1980
  79.       TabIndex        =   17
  80.       Top             =   4140
  81.       Width           =   1815
  82.    End
  83.    Begin VB.OptionButton Option1 
  84.       Appearance      =   0  'Flat
  85.       BackColor       =   &H00C0C0C0&
  86.       Caption         =   "PATPAINT"
  87.       ForeColor       =   &H80000008&
  88.       Height          =   315
  89.       Index           =   10
  90.       Left            =   1980
  91.       TabIndex        =   16
  92.       Top             =   3780
  93.       Width           =   1815
  94.    End
  95.    Begin VB.OptionButton Option1 
  96.       Appearance      =   0  'Flat
  97.       BackColor       =   &H00C0C0C0&
  98.       Caption         =   "PATCOPY"
  99.       ForeColor       =   &H80000008&
  100.       Height          =   315
  101.       Index           =   9
  102.       Left            =   1980
  103.       TabIndex        =   15
  104.       Top             =   3420
  105.       Width           =   1815
  106.    End
  107.    Begin VB.OptionButton Option1 
  108.       Appearance      =   0  'Flat
  109.       BackColor       =   &H00C0C0C0&
  110.       Caption         =   "MERGEPAINT"
  111.       ForeColor       =   &H80000008&
  112.       Height          =   315
  113.       Index           =   8
  114.       Left            =   1980
  115.       TabIndex        =   14
  116.       Top             =   3060
  117.       Width           =   1815
  118.    End
  119.    Begin VB.OptionButton Option1 
  120.       Appearance      =   0  'Flat
  121.       BackColor       =   &H00C0C0C0&
  122.       Caption         =   "MERGECOPY"
  123.       ForeColor       =   &H80000008&
  124.       Height          =   315
  125.       Index           =   7
  126.       Left            =   1980
  127.       TabIndex        =   13
  128.       Top             =   2700
  129.       Width           =   1815
  130.    End
  131.    Begin VB.OptionButton Option1 
  132.       Appearance      =   0  'Flat
  133.       BackColor       =   &H00C0C0C0&
  134.       Caption         =   "NOTSRCERASE"
  135.       ForeColor       =   &H80000008&
  136.       Height          =   315
  137.       Index           =   6
  138.       Left            =   1980
  139.       TabIndex        =   12
  140.       Top             =   2340
  141.       Width           =   1815
  142.    End
  143.    Begin VB.OptionButton Option1 
  144.       Appearance      =   0  'Flat
  145.       BackColor       =   &H00C0C0C0&
  146.       Caption         =   "NOTSRCCOPY"
  147.       ForeColor       =   &H80000008&
  148.       Height          =   315
  149.       Index           =   5
  150.       Left            =   1980
  151.       TabIndex        =   11
  152.       Top             =   1980
  153.       Width           =   1815
  154.    End
  155.    Begin VB.OptionButton Option1 
  156.       Appearance      =   0  'Flat
  157.       BackColor       =   &H00C0C0C0&
  158.       Caption         =   "SRCERASE"
  159.       ForeColor       =   &H80000008&
  160.       Height          =   315
  161.       Index           =   4
  162.       Left            =   1980
  163.       TabIndex        =   10
  164.       Top             =   1620
  165.       Width           =   1815
  166.    End
  167.    Begin VB.OptionButton Option1 
  168.       Appearance      =   0  'Flat
  169.       BackColor       =   &H00C0C0C0&
  170.       Caption         =   "SRCINVERT"
  171.       ForeColor       =   &H80000008&
  172.       Height          =   315
  173.       Index           =   3
  174.       Left            =   1980
  175.       TabIndex        =   9
  176.       Top             =   1260
  177.       Width           =   1815
  178.    End
  179.    Begin VB.OptionButton Option1 
  180.       Appearance      =   0  'Flat
  181.       BackColor       =   &H00C0C0C0&
  182.       Caption         =   "SRCAND"
  183.       ForeColor       =   &H80000008&
  184.       Height          =   315
  185.       Index           =   2
  186.       Left            =   1980
  187.       TabIndex        =   8
  188.       Top             =   900
  189.       Width           =   1815
  190.    End
  191.    Begin VB.OptionButton Option1 
  192.       Appearance      =   0  'Flat
  193.       BackColor       =   &H00C0C0C0&
  194.       Caption         =   "SRCPAINT"
  195.       ForeColor       =   &H80000008&
  196.       Height          =   315
  197.       Index           =   1
  198.       Left            =   1980
  199.       TabIndex        =   7
  200.       Top             =   540
  201.       Width           =   1815
  202.    End
  203.    Begin VB.OptionButton Option1 
  204.       Appearance      =   0  'Flat
  205.       BackColor       =   &H00C0C0C0&
  206.       Caption         =   "SRCCOPY"
  207.       ForeColor       =   &H80000008&
  208.       Height          =   315
  209.       Index           =   0
  210.       Left            =   1980
  211.       TabIndex        =   6
  212.       Top             =   180
  213.       Value           =   -1  'True
  214.       Width           =   1815
  215.    End
  216.    Begin VB.CommandButton cmdPatBlt 
  217.       Appearance      =   0  'Flat
  218.       BackColor       =   &H80000005&
  219.       Caption         =   "PatBlt"
  220.       Height          =   435
  221.       Left            =   2640
  222.       TabIndex        =   5
  223.       Top             =   6060
  224.       Width           =   1095
  225.    End
  226.    Begin VB.PictureBox picBrush 
  227.       Appearance      =   0  'Flat
  228.       BackColor       =   &H80000005&
  229.       ForeColor       =   &H80000008&
  230.       Height          =   495
  231.       Left            =   1500
  232.       ScaleHeight     =   465
  233.       ScaleWidth      =   945
  234.       TabIndex        =   3
  235.       Top             =   6060
  236.       Width           =   975
  237.    End
  238.    Begin VB.CommandButton cmdBitBlt 
  239.       Appearance      =   0  'Flat
  240.       BackColor       =   &H80000005&
  241.       Caption         =   "BitBlt"
  242.       Height          =   435
  243.       Left            =   3960
  244.       TabIndex        =   2
  245.       Top             =   6060
  246.       Width           =   1215
  247.    End
  248.    Begin VB.PictureBox picDest 
  249.       Appearance      =   0  'Flat
  250.       BackColor       =   &H80000005&
  251.       ForeColor       =   &H80000008&
  252.       Height          =   5355
  253.       Left            =   4140
  254.       ScaleHeight     =   355
  255.       ScaleMode       =   3  'Pixel
  256.       ScaleWidth      =   59
  257.       TabIndex        =   1
  258.       Top             =   180
  259.       Width           =   915
  260.    End
  261.    Begin VB.PictureBox picSource 
  262.       Appearance      =   0  'Flat
  263.       BackColor       =   &H80000005&
  264.       ForeColor       =   &H80000008&
  265.       Height          =   5355
  266.       Left            =   600
  267.       ScaleHeight     =   355
  268.       ScaleMode       =   3  'Pixel
  269.       ScaleWidth      =   59
  270.       TabIndex        =   0
  271.       Top             =   180
  272.       Width           =   915
  273.    End
  274.    Begin VB.Label labRes 
  275.       Appearance      =   0  'Flat
  276.       BackColor       =   &H80000005&
  277.       BackStyle       =   0  'Transparent
  278.       ForeColor       =   &H80000008&
  279.       Height          =   255
  280.       Left            =   180
  281.       TabIndex        =   23
  282.       Top             =   5640
  283.       Width           =   375
  284.    End
  285.    Begin VB.Label Label2 
  286.       Alignment       =   1  'Right Justify
  287.       Appearance      =   0  'Flat
  288.       BackColor       =   &H80000005&
  289.       BackStyle       =   0  'Transparent
  290.       Caption         =   "User Defined:"
  291.       ForeColor       =   &H80000008&
  292.       Height          =   255
  293.       Left            =   960
  294.       TabIndex        =   22
  295.       Top             =   5640
  296.       Width           =   1815
  297.    End
  298.    Begin VB.Label Label1 
  299.       Appearance      =   0  'Flat
  300.       BackColor       =   &H80000005&
  301.       BackStyle       =   0  'Transparent
  302.       Caption         =   "Current Brush:"
  303.       ForeColor       =   &H80000008&
  304.       Height          =   315
  305.       Left            =   120
  306.       TabIndex        =   4
  307.       Top             =   6120
  308.       Width           =   1275
  309.    End
  310. Attribute VB_Name = "frmROPTest"
  311. Attribute VB_Creatable = False
  312. Attribute VB_Exposed = False
  313. Option Explicit
  314. ' Copyright 
  315.  1997 by Desaware Inc. All Rights Reserved
  316. ' Globals
  317. Dim CellHeight&     ' Height in pixels of one color cell
  318. Dim CurrentMouseY&  ' Current Y location
  319. Dim CurrentBrush&   ' Current brush to use
  320. Dim CurrentOption%
  321. ' API calls
  322. Private Declare Function DeleteObject& Lib "gdi32" (ByVal hObject As Long)
  323. Private Declare Function CreateSolidBrush& Lib "gdi32" (ByVal crColor As Long)
  324. Private Declare Function PatBlt& Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal dwRop As Long)
  325. Private Declare Function BitBlt& Lib "gdi32" (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)
  326. Private Declare Function SelectObject& Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long)
  327. ' The most common raster operations
  328. Dim RasterOps&(15)
  329. Const SRCCOPY = &HCC0020    ' (DWORD) dest = source
  330. Const SRCPAINT = &HEE0086   ' (DWORD) dest = source OR dest
  331. Const SRCAND = &H8800C6     ' (DWORD) dest = source AND dest
  332. Const SRCINVERT = &H660046  ' (DWORD) dest = source XOR dest
  333. Const SRCERASE = &H440328   ' (DWORD) dest = source AND (NOT dest )
  334. Const NOTSRCCOPY = &H330008 ' (DWORD) dest = (NOT source)
  335. Const NOTSRCERASE = &H1100A6 ' (DWORD) dest = (NOT src) AND (NOT dest)
  336. Const MERGECOPY = &HC000CA  ' (DWORD) dest = (source AND pattern)
  337. Const MERGEPAINT = &HBB0226 ' (DWORD) dest = (NOT source) OR dest
  338. Const PATCOPY = &HF00021    ' (DWORD) dest = pattern
  339. Const PATPAINT = &HFB0A09   ' (DWORD) dest = (Not source) or pattern or dest
  340. Const PATINVERT = &H5A0049  ' (DWORD) dest = pattern XOR dest
  341. Const DSTINVERT = &H550009  ' (DWORD) dest = (NOT dest)
  342. Const BLACKNESS = &H42&     ' (DWORD) dest = BLACK
  343. Const WHITENESS = &HFF0062  ' (DWORD) dest = WHITE
  344. Private Sub cmdBitBlt_Click()
  345.     Dim di%
  346.     Dim raster&
  347.     Dim oldbrush&
  348.     If Len(txtUserDef.Text) <> 0 Then
  349.         raster& = "&H" & txtUserDef.Text
  350.     Else
  351.         raster& = RasterOps(CurrentOption%)
  352.     End If
  353.         
  354.     Debug.Print raster&
  355.     oldbrush = SelectObject(picDest.hdc, CurrentBrush&)
  356.     di = BitBlt(picDest.hdc, 0, 0, picDest.ScaleWidth, picDest.ScaleHeight, picSource.hdc, 0, 0, raster&)
  357.     oldbrush = SelectObject(picDest.hdc, oldbrush&)
  358.     labRes.Caption = di
  359. End Sub
  360. Private Sub cmdPatBlt_Click()
  361.     Dim di&
  362.     Dim raster&
  363.     Dim oldbrush&
  364.     If Len(txtUserDef.Text) <> 0 Then
  365.         raster& = "&H" & txtUserDef.Text
  366.     Else
  367.         raster& = RasterOps(CurrentOption%)
  368.     End If
  369.         
  370.     Debug.Print raster&
  371.     oldbrush& = SelectObject(picDest.hdc, CurrentBrush&)
  372.     di = PatBlt&(picDest.hdc, 0, 0, picDest.ScaleWidth, picDest.ScaleHeight, raster&)
  373.     oldbrush& = SelectObject(picDest.hdc, oldbrush&)
  374.     labRes.Caption = di
  375. End Sub
  376. Private Sub Form_Load()
  377.     ' Default to a white brush
  378.     CurrentBrush& = CreateSolidBrush(QBColor(15))
  379.     RasterOps(0) = SRCCOPY
  380.     RasterOps(1) = SRCPAINT
  381.     RasterOps(2) = SRCAND
  382.     RasterOps(3) = SRCINVERT
  383.     RasterOps(4) = SRCERASE
  384.     RasterOps(5) = NOTSRCCOPY
  385.     RasterOps(6) = NOTSRCERASE
  386.     RasterOps(7) = MERGECOPY
  387.     RasterOps(8) = MERGEPAINT
  388.     RasterOps(9) = PATCOPY
  389.     RasterOps(10) = PATPAINT
  390.     RasterOps(11) = PATINVERT
  391.     RasterOps(12) = DSTINVERT
  392.     RasterOps(13) = BLACKNESS
  393.     RasterOps(14) = WHITENESS
  394. End Sub
  395. Private Sub Form_Unload(Cancel As Integer)
  396.     Dim di%
  397.     If CurrentBrush& Then di = DeleteObject(CurrentBrush)
  398. End Sub
  399. Private Sub Option1_Click(Index As Integer)
  400.     CurrentOption% = Index
  401. End Sub
  402. Private Sub picSource_Click()
  403.     Dim usecolor%, di&
  404.     If CurrentBrush& Then di = DeleteObject(CurrentBrush&)
  405.     usecolor% = CInt(CurrentMouseY \ CellHeight)
  406.     If usecolor% < 0 Then usecolor% = 0
  407.     If usecolor% > 15 Then usecolor% = 15
  408.     CurrentBrush& = CreateSolidBrush(QBColor(usecolor%))
  409.     picBrush.BackColor = QBColor(usecolor%)
  410. End Sub
  411. Private Sub picSource_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  412.     CurrentMouseY = y
  413. End Sub
  414. Private Sub picSource_Paint()
  415.     Dim x%
  416.     ' Determine the height of each block of color
  417.     CellHeight& = picSource.ScaleHeight \ 16
  418.     For x% = 0 To 15
  419.         picSource.Line (0, CellHeight * x)-(picSource.ScaleWidth, CellHeight * (x + 1)), QBColor(x%), BF
  420.     Next x%
  421. End Sub
  422. Private Sub txtUserDef_Change()
  423.     Dim txtEmpty%
  424.     Dim x%
  425.     txtEmpty% = Len(txtUserDef.Text) = 0
  426.     ' Set option button enabled status
  427.     For x% = 0 To 14
  428.         Option1(x%).Enabled = txtEmpty%
  429.     Next x%
  430. End Sub
  431.