home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / Paul's_Col2070216112007.psc / Pick.frm < prev    next >
Text File  |  2007-06-11  |  38KB  |  1,104 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
  3. Begin VB.Form frmPick 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Paul's Color picker"
  6.    ClientHeight    =   5010
  7.    ClientLeft      =   45
  8.    ClientTop       =   360
  9.    ClientWidth     =   7410
  10.    Icon            =   "Pick.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   334
  15.    ScaleMode       =   3  'Pixel
  16.    ScaleWidth      =   494
  17.    StartUpPosition =   3  'Windows Default
  18.    Begin VB.CheckBox chCursor 
  19.       Caption         =   "Colorized Cursor"
  20.       Height          =   255
  21.       Left            =   120
  22.       TabIndex        =   47
  23.       Top             =   1320
  24.       Width           =   1575
  25.    End
  26.    Begin VB.Frame frBackcolor 
  27.       BackColor       =   &H00FFFFFF&
  28.       Caption         =   "Backcolor"
  29.       Height          =   2415
  30.       Left            =   2280
  31.       TabIndex        =   30
  32.       Top             =   480
  33.       Width           =   2055
  34.       Begin VB.CommandButton cmdCancel 
  35.          Caption         =   "Cancel"
  36.          Height          =   375
  37.          Left            =   960
  38.          TabIndex        =   35
  39.          Top             =   1920
  40.          Width           =   855
  41.       End
  42.       Begin VB.ListBox lbPicks 
  43.          Height          =   645
  44.          Index           =   2
  45.          Left            =   240
  46.          TabIndex        =   34
  47.          Top             =   960
  48.          Width           =   1095
  49.       End
  50.       Begin Pauls_ColorPicker.ucPickBox ucPickBox 
  51.          Height          =   315
  52.          Left            =   240
  53.          TabIndex        =   33
  54.          Top             =   1200
  55.          Width           =   1575
  56.          _ExtentX        =   2778
  57.          _ExtentY        =   556
  58.       End
  59.       Begin VB.OptionButton optBackcolor 
  60.          BackColor       =   &H00FFFFFF&
  61.          Caption         =   "Picked color"
  62.          Height          =   375
  63.          Index           =   1
  64.          Left            =   120
  65.          TabIndex        =   32
  66.          Top             =   520
  67.          Width           =   1575
  68.       End
  69.       Begin VB.OptionButton optBackcolor 
  70.          BackColor       =   &H00FFFFFF&
  71.          Caption         =   "Standard"
  72.          Height          =   375
  73.          Index           =   0
  74.          Left            =   120
  75.          TabIndex        =   31
  76.          Top             =   240
  77.          Width           =   1575
  78.       End
  79.    End
  80.    Begin VB.CheckBox chCompare 
  81.       BackColor       =   &H00800000&
  82.       Caption         =   "Compare color picks"
  83.       ForeColor       =   &H00FFFFFF&
  84.       Height          =   375
  85.       Left            =   5040
  86.       TabIndex        =   29
  87.       Top             =   3120
  88.       Width           =   1095
  89.    End
  90.    Begin VB.ListBox lbPicks 
  91.       Height          =   645
  92.       Index           =   1
  93.       Left            =   6240
  94.       TabIndex        =   28
  95.       Top             =   2280
  96.       Visible         =   0   'False
  97.       Width           =   1095
  98.    End
  99.    Begin VB.ListBox lbPicks 
  100.       Height          =   645
  101.       Index           =   0
  102.       ItemData        =   "Pick.frx":0CCA
  103.       Left            =   5040
  104.       List            =   "Pick.frx":0CCC
  105.       TabIndex        =   23
  106.       Top             =   2280
  107.       Visible         =   0   'False
  108.       Width           =   1095
  109.    End
  110.    Begin VB.Frame frRange 
  111.       Caption         =   "Range"
  112.       BeginProperty Font 
  113.          Name            =   "MS Sans Serif"
  114.          Size            =   8.25
  115.          Charset         =   0
  116.          Weight          =   700
  117.          Underline       =   0   'False
  118.          Italic          =   0   'False
  119.          Strikethrough   =   0   'False
  120.       EndProperty
  121.       ForeColor       =   &H00C00000&
  122.       Height          =   3375
  123.       Left            =   120
  124.       TabIndex        =   13
  125.       Top             =   1560
  126.       Width           =   1935
  127.       Begin Pauls_ColorPicker.ucRange ucRange 
  128.          Height          =   510
  129.          Left            =   120
  130.          TabIndex        =   20
  131.          Top             =   2040
  132.          Width           =   1575
  133.          _ExtentX        =   2778
  134.          _ExtentY        =   900
  135.          Minimum         =   0
  136.          Maximum         =   100
  137.          Range           =   101
  138.          Lower           =   0
  139.          Upper           =   101
  140.          MainColor       =   16777215
  141.          RangeColor      =   16711680
  142.       End
  143.       Begin VB.OptionButton optIncrements 
  144.          Caption         =   "1"
  145.          Height          =   375
  146.          Index           =   4
  147.          Left            =   600
  148.          TabIndex        =   19
  149.          Top             =   1440
  150.          Width           =   615
  151.       End
  152.       Begin VB.OptionButton optIncrements 
  153.          Caption         =   "2"
  154.          Height          =   375
  155.          Index           =   3
  156.          Left            =   600
  157.          TabIndex        =   18
  158.          Top             =   1200
  159.          Width           =   615
  160.       End
  161.       Begin VB.OptionButton optIncrements 
  162.          Caption         =   "4"
  163.          Height          =   375
  164.          Index           =   2
  165.          Left            =   600
  166.          TabIndex        =   17
  167.          Top             =   960
  168.          Width           =   615
  169.       End
  170.       Begin VB.OptionButton optIncrements 
  171.          Caption         =   "8"
  172.          Height          =   375
  173.          Index           =   1
  174.          Left            =   600
  175.          TabIndex        =   16
  176.          Top             =   720
  177.          Width           =   615
  178.       End
  179.       Begin VB.OptionButton optIncrements 
  180.          Caption         =   "16"
  181.          Height          =   375
  182.          Index           =   0
  183.          Left            =   600
  184.          TabIndex        =   15
  185.          Top             =   480
  186.          Width           =   615
  187.       End
  188.       Begin VB.Label Label3 
  189.          Caption         =   "Click arrows or drag blue bar to alter the range."
  190.          Height          =   600
  191.          Left            =   120
  192.          TabIndex        =   22
  193.          Top             =   2600
  194.          Width           =   1575
  195.       End
  196.       Begin VB.Label Label2 
  197.          Caption         =   "Increments"
  198.          Height          =   255
  199.          Left            =   480
  200.          TabIndex        =   14
  201.          Top             =   240
  202.          Width           =   975
  203.       End
  204.    End
  205.    Begin MSComctlLib.Slider slVariableColor 
  206.       Height          =   255
  207.       Left            =   2400
  208.       TabIndex        =   4
  209.       Top             =   3240
  210.       Width           =   2400
  211.       _ExtentX        =   4233
  212.       _ExtentY        =   450
  213.       _Version        =   393216
  214.       LargeChange     =   16
  215.       Max             =   255
  216.       TickFrequency   =   16
  217.       TextPosition    =   1
  218.    End
  219.    Begin VB.Frame frColorPair 
  220.       Caption         =   "Color pair selection"
  221.       BeginProperty Font 
  222.          Name            =   "MS Sans Serif"
  223.          Size            =   8.25
  224.          Charset         =   0
  225.          Weight          =   700
  226.          Underline       =   0   'False
  227.          Italic          =   0   'False
  228.          Strikethrough   =   0   'False
  229.       EndProperty
  230.       ForeColor       =   &H00C00000&
  231.       Height          =   1095
  232.       Left            =   120
  233.       TabIndex        =   0
  234.       Top             =   120
  235.       Width           =   1935
  236.       Begin VB.OptionButton optSelect 
  237.          Caption         =   "Blue"
  238.          ForeColor       =   &H00C00000&
  239.          Height          =   255
  240.          Index           =   2
  241.          Left            =   240
  242.          TabIndex        =   3
  243.          Top             =   720
  244.          Width           =   610
  245.       End
  246.       Begin VB.OptionButton optSelect 
  247.          Caption         =   "Green"
  248.          ForeColor       =   &H0000C000&
  249.          Height          =   255
  250.          Index           =   1
  251.          Left            =   240
  252.          TabIndex        =   2
  253.          Top             =   480
  254.          Width           =   750
  255.       End
  256.       Begin VB.OptionButton optSelect 
  257.          Caption         =   "Red"
  258.          ForeColor       =   &H000000FF&
  259.          Height          =   255
  260.          Index           =   0
  261.          Left            =   240
  262.          TabIndex        =   1
  263.          Top             =   240
  264.          Width           =   600
  265.       End
  266.       Begin VB.Label Label1 
  267.          Caption         =   "- Red"
  268.          ForeColor       =   &H000000FF&
  269.          Height          =   255
  270.          Index           =   2
  271.          Left            =   960
  272.          TabIndex        =   7
  273.          Top             =   720
  274.          Width           =   615
  275.       End
  276.       Begin VB.Label Label1 
  277.          Caption         =   "- Blue"
  278.          ForeColor       =   &H00C00000&
  279.          Height          =   255
  280.          Index           =   1
  281.          Left            =   1000
  282.          TabIndex        =   6
  283.          Top             =   480
  284.          Width           =   615
  285.       End
  286.       Begin VB.Label Label1 
  287.          Caption         =   "- Green"
  288.          ForeColor       =   &H0000C000&
  289.          Height          =   255
  290.          Index           =   0
  291.          Left            =   960
  292.          TabIndex        =   5
  293.          Top             =   240
  294.          Width           =   615
  295.       End
  296.    End
  297.    Begin VB.PictureBox picPick 
  298.       Appearance      =   0  'Flat
  299.       AutoRedraw      =   -1  'True
  300.       BackColor       =   &H00C0C0C0&
  301.       BorderStyle     =   0  'None
  302.       ForeColor       =   &H80000008&
  303.       Height          =   2550
  304.       Left            =   2280
  305.       MouseIcon       =   "Pick.frx":0CCE
  306.       MousePointer    =   99  'Custom
  307.       ScaleHeight     =   170
  308.       ScaleMode       =   3  'Pixel
  309.       ScaleWidth      =   170
  310.       TabIndex        =   46
  311.       Top             =   150
  312.       Width           =   2550
  313.    End
  314.    Begin VB.Label Label4 
  315.       BackStyle       =   0  'Transparent
  316.       Caption         =   "Click to copy to the clipboard"
  317.       BeginProperty Font 
  318.          Name            =   "MS Serif"
  319.          Size            =   6.75
  320.          Charset         =   0
  321.          Weight          =   400
  322.          Underline       =   0   'False
  323.          Italic          =   0   'False
  324.          Strikethrough   =   0   'False
  325.       EndProperty
  326.       ForeColor       =   &H00400000&
  327.       Height          =   300
  328.       Index           =   7
  329.       Left            =   6240
  330.       TabIndex        =   45
  331.       Top             =   1950
  332.       Width           =   1050
  333.    End
  334.    Begin VB.Label Label4 
  335.       BackStyle       =   0  'Transparent
  336.       Caption         =   "Click to copy to the clipboard"
  337.       BeginProperty Font 
  338.          Name            =   "MS Serif"
  339.          Size            =   6.75
  340.          Charset         =   0
  341.          Weight          =   400
  342.          Underline       =   0   'False
  343.          Italic          =   0   'False
  344.          Strikethrough   =   0   'False
  345.       EndProperty
  346.       ForeColor       =   &H00400000&
  347.       Height          =   300
  348.       Index           =   6
  349.       Left            =   5040
  350.       TabIndex        =   44
  351.       Top             =   1950
  352.       Width           =   1050
  353.    End
  354.    Begin VB.Label Label4 
  355.       BackStyle       =   0  'Transparent
  356.       Caption         =   "RGB"
  357.       BeginProperty Font 
  358.          Name            =   "MS Serif"
  359.          Size            =   6
  360.          Charset         =   0
  361.          Weight          =   400
  362.          Underline       =   0   'False
  363.          Italic          =   0   'False
  364.          Strikethrough   =   0   'False
  365.       EndProperty
  366.       Height          =   120
  367.       Index           =   5
  368.       Left            =   6300
  369.       TabIndex        =   43
  370.       Top             =   1560
  371.       Width           =   750
  372.    End
  373.    Begin VB.Label Label4 
  374.       BackStyle       =   0  'Transparent
  375.       Caption         =   "RGB"
  376.       BeginProperty Font 
  377.          Name            =   "MS Serif"
  378.          Size            =   6
  379.          Charset         =   0
  380.          Weight          =   400
  381.          Underline       =   0   'False
  382.          Italic          =   0   'False
  383.          Strikethrough   =   0   'False
  384.       EndProperty
  385.       Height          =   120
  386.       Index           =   4
  387.       Left            =   5100
  388.       TabIndex        =   42
  389.       Top             =   1560
  390.       Width           =   975
  391.    End
  392.    Begin VB.Label Label4 
  393.       BackStyle       =   0  'Transparent
  394.       Caption         =   "Hexadecimal"
  395.       BeginProperty Font 
  396.          Name            =   "MS Serif"
  397.          Size            =   6
  398.          Charset         =   0
  399.          Weight          =   400
  400.          Underline       =   0   'False
  401.          Italic          =   0   'False
  402.          Strikethrough   =   0   'False
  403.       EndProperty
  404.       Height          =   120
  405.       Index           =   3
  406.       Left            =   6300
  407.       TabIndex        =   41
  408.       Top             =   1170
  409.       Width           =   750
  410.    End
  411.    Begin VB.Label Label4 
  412.       BackStyle       =   0  'Transparent
  413.       Caption         =   "Hexadecimal"
  414.       BeginProperty Font 
  415.          Name            =   "MS Serif"
  416.          Size            =   6
  417.          Charset         =   0
  418.          Weight          =   400
  419.          Underline       =   0   'False
  420.          Italic          =   0   'False
  421.          Strikethrough   =   0   'False
  422.       EndProperty
  423.       Height          =   120
  424.       Index           =   2
  425.       Left            =   5100
  426.       TabIndex        =   40
  427.       Top             =   1170
  428.       Width           =   975
  429.    End
  430.    Begin VB.Label Label4 
  431.       BackStyle       =   0  'Transparent
  432.       Caption         =   "Numeric"
  433.       BeginProperty Font 
  434.          Name            =   "MS Serif"
  435.          Size            =   6
  436.          Charset         =   0
  437.          Weight          =   400
  438.          Underline       =   0   'False
  439.          Italic          =   0   'False
  440.          Strikethrough   =   0   'False
  441.       EndProperty
  442.       Height          =   120
  443.       Index           =   1
  444.       Left            =   6300
  445.       TabIndex        =   39
  446.       Top             =   780
  447.       Width           =   750
  448.    End
  449.    Begin VB.Label Label4 
  450.       BackStyle       =   0  'Transparent
  451.       Caption         =   "Numeric"
  452.       BeginProperty Font 
  453.          Name            =   "MS Serif"
  454.          Size            =   6
  455.          Charset         =   0
  456.          Weight          =   400
  457.          Underline       =   0   'False
  458.          Italic          =   0   'False
  459.          Strikethrough   =   0   'False
  460.       EndProperty
  461.       Height          =   120
  462.       Index           =   0
  463.       Left            =   5100
  464.       TabIndex        =   38
  465.       Top             =   780
  466.       Width           =   975
  467.    End
  468.    Begin VB.Label cmdClear 
  469.       Alignment       =   2  'Center
  470.       Appearance      =   0  'Flat
  471.       BackColor       =   &H00800000&
  472.       BorderStyle     =   1  'Fixed Single
  473.       Caption         =   "Clear all picks"
  474.       ForeColor       =   &H00FFFFFF&
  475.       Height          =   495
  476.       Left            =   5040
  477.       TabIndex        =   37
  478.       Top             =   4200
  479.       Width           =   1095
  480.    End
  481.    Begin VB.Label cmdBackcolor 
  482.       Alignment       =   2  'Center
  483.       Appearance      =   0  'Flat
  484.       BackColor       =   &H00800000&
  485.       BorderStyle     =   1  'Fixed Single
  486.       Caption         =   "Change backcolor"
  487.       ForeColor       =   &H00FFFFFF&
  488.       Height          =   495
  489.       Left            =   5040
  490.       TabIndex        =   36
  491.       Top             =   3600
  492.       Width           =   1095
  493.    End
  494.    Begin VB.Label lblSelectedColor 
  495.       Appearance      =   0  'Flat
  496.       BorderStyle     =   1  'Fixed Single
  497.       ForeColor       =   &H80000008&
  498.       Height          =   495
  499.       Index           =   1
  500.       Left            =   6240
  501.       TabIndex        =   27
  502.       Top             =   240
  503.       Width           =   1095
  504.    End
  505.    Begin VB.Label lblLong 
  506.       Appearance      =   0  'Flat
  507.       BackColor       =   &H80000005&
  508.       BorderStyle     =   1  'Fixed Single
  509.       ForeColor       =   &H80000008&
  510.       Height          =   255
  511.       Index           =   1
  512.       Left            =   6240
  513.       TabIndex        =   26
  514.       ToolTipText     =   "Numeric (Long)"
  515.       Top             =   915
  516.       Width           =   1095
  517.    End
  518.    Begin VB.Label lblHex 
  519.       Appearance      =   0  'Flat
  520.       BackColor       =   &H80000005&
  521.       BorderStyle     =   1  'Fixed Single
  522.       ForeColor       =   &H80000008&
  523.       Height          =   255
  524.       Index           =   1
  525.       Left            =   6240
  526.       TabIndex        =   25
  527.       ToolTipText     =   "Hexadecimal"
  528.       Top             =   1305
  529.       Width           =   1095
  530.    End
  531.    Begin VB.Label lblRGB 
  532.       Appearance      =   0  'Flat
  533.       BackColor       =   &H80000005&
  534.       BorderStyle     =   1  'Fixed Single
  535.       ForeColor       =   &H80000008&
  536.       Height          =   255
  537.       Index           =   1
  538.       Left            =   6240
  539.       TabIndex        =   24
  540.       ToolTipText     =   "RGB"
  541.       Top             =   1695
  542.       Width           =   1095
  543.    End
  544.    Begin VB.Label lblVariableColor 
  545.       ForeColor       =   &H00C00000&
  546.       Height          =   975
  547.       Index           =   1
  548.       Left            =   2400
  549.       TabIndex        =   21
  550.       Top             =   3600
  551.       Width           =   2400
  552.    End
  553.    Begin VB.Label lblRGB 
  554.       Appearance      =   0  'Flat
  555.       BackColor       =   &H80000005&
  556.       BorderStyle     =   1  'Fixed Single
  557.       ForeColor       =   &H80000008&
  558.       Height          =   255
  559.       Index           =   0
  560.       Left            =   5040
  561.       TabIndex        =   12
  562.       ToolTipText     =   "RGB"
  563.       Top             =   1695
  564.       Width           =   1095
  565.    End
  566.    Begin VB.Label lblHex 
  567.       Appearance      =   0  'Flat
  568.       BackColor       =   &H80000005&
  569.       BorderStyle     =   1  'Fixed Single
  570.       ForeColor       =   &H80000008&
  571.       Height          =   255
  572.       Index           =   0
  573.       Left            =   5040
  574.       TabIndex        =   11
  575.       ToolTipText     =   "Hexadecimal"
  576.       Top             =   1305
  577.       Width           =   1095
  578.    End
  579.    Begin VB.Label lblLong 
  580.       Appearance      =   0  'Flat
  581.       BackColor       =   &H80000005&
  582.       BorderStyle     =   1  'Fixed Single
  583.       ForeColor       =   &H80000008&
  584.       Height          =   255
  585.       Index           =   0
  586.       Left            =   5040
  587.       TabIndex        =   10
  588.       ToolTipText     =   "Numeric (Long)"
  589.       Top             =   915
  590.       Width           =   1095
  591.    End
  592.    Begin VB.Label lblSelectedColor 
  593.       Appearance      =   0  'Flat
  594.       BorderStyle     =   1  'Fixed Single
  595.       ForeColor       =   &H80000008&
  596.       Height          =   495
  597.       Index           =   0
  598.       Left            =   5040
  599.       TabIndex        =   9
  600.       Top             =   240
  601.       Width           =   1095
  602.    End
  603.    Begin VB.Label lblVariableColor 
  604.       Alignment       =   2  'Center
  605.       Caption         =   "lblVariableColor"
  606.       Height          =   375
  607.       Index           =   0
  608.       Left            =   2400
  609.       TabIndex        =   8
  610.       Top             =   2880
  611.       Width           =   2400
  612.    End
  613. End
  614. Attribute VB_Name = "frmPick"
  615. Attribute VB_GlobalNameSpace = False
  616. Attribute VB_Creatable = False
  617. Attribute VB_PredeclaredId = True
  618. Attribute VB_Exposed = False
  619.  
  620. ' Paul's Color Picker
  621. '
  622. '   Compatibility:
  623. '       Windows: NT, 2000, XP
  624. '
  625. '   Software Developed by:
  626. '       Paul Turcksin
  627. '
  628. '   Legal Copyright & Trademarks:
  629. '       Copyright ⌐ 2007, by Paul Turcksin, All Rights Reserved Worldwide
  630. '       Trademark Ö 2007, by Paul Turcksin, All Rights Reserved Worldwide
  631. '
  632. '   You are free to use this code within your own applications, but you
  633. '   are expressly forbidden from selling or otherwise distributing this
  634. '   source code without prior written consent.
  635. '
  636. '   Redistributions of source code must include this list of conditions,
  637. '   and the following acknowledgment:
  638. '
  639. '   This code was developed by Paul Turcksin.
  640. '   Source code, written in Visual Basic, is freely available for non-
  641. '   commercial, non-profit use.
  642. '   Redistributions in binary form, as part of a larger project, must
  643. '   include the above acknowledgment in the end-user documentation.
  644. '   Alternatively, the above acknowledgment may appear in the software
  645. '   itself, if and where such third-party acknowledgments normally appear.
  646. '
  647. '   Comments:
  648. '       No claims or warranties are expressed or implied as to accuracy or fitness
  649. '       for use of this software. Paul Turcksin shall not be liable for any
  650. '       incidental or consequential damages suffered by any use of this  software.
  651.  
  652. '       Many thanks to my friend Paul R. Territo Ph.D (TerriTop) for his careful review, suggestions,
  653. '       and support of this program prior to public release. In addtion, I wish to
  654. '       thank the numerous open source authors who provide code and inspiration to
  655. '       make such work possible.
  656. '
  657. '   Contact Information:
  658. '       For Technical Assistance:
  659. '       Email: paul_turcksin@Hotmail.com
  660. '
  661. '
  662. '   Credits:
  663. '        ucPickBox by TerriTop
  664. '        http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=63905&lngWId=1
  665. '
  666. '        eyedropper.cur by TerriTop
  667. '
  668. '        From PSet to DIB sections - your comprehensive guide to VB graphics programming
  669. '        by Tanner "DemonSpectre" Helland
  670. '        http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=60939&lngWId=1
  671. '
  672. '        Custom Cursors Color by GioRock
  673. '        http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=68656&lngWId=1
  674. '..................................................................................................
  675. '
  676. '                                  Updates
  677. '__________________________________________________________________________________________________
  678. '
  679. ' Version 1.1
  680. '     - the slider controlling the third color only updated the Pick color labels upon release of
  681. '       the mouse button (continuous update produced exessive flicker).
  682. '       Replaced all Pick Color labels by one picturebox control and used DIB for updating
  683. '
  684. ' Version 1.2
  685. '     - Rob C suggested to show the color the mouse was over in a new field. I have implemented it
  686. '       by giving the cursor this color. Inspiration/example found in GioRock post on PSC (See credits).
  687. '       A checkbox allows to choose between an eyedropper and a colorized cursor.
  688. '..................................................................................................
  689. '
  690. '                                  Documentation
  691. '__________________________________________________________________________________________________
  692.  
  693. '  Paul's Color Picker uses an innovative approach to the color selection process.
  694. ' The starting point is the RGB  color model.
  695. '  First a color pair is selected and this color combination is presented in a 17x17 matrix
  696. ' with the colors shown with 16 units increments. Beneath the matrix is a slider allowing
  697. ' variations of the third color.
  698. ' To further refine the search the increments can be modified down to 1 unit.
  699. ' Clicking a color in the matrix shows detailed info of the color picked.
  700. ' Additional features:
  701. ' - selected colors are preserved to allow comparisons
  702. ' - the form's backcolor can be set (standard or picked color) to aid visualization and
  703. '   comparison
  704. ' - save to the clipboard in three possible formats: numeric (long), Hexadecimal or RGB
  705. '
  706.  
  707. Option Explicit
  708. '............................ DC
  709. Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
  710. Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
  711. Private CursorDC As Long
  712.  
  713. '............................ OBJECT
  714. Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
  715. Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
  716. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  717. Private oldCursorObj As Long
  718. Private oldBrush As Long
  719.  
  720. '............................ BITMAP
  721. Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
  722. Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
  723. 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) As Long
  724. Private Const PATCOPY = &HF00021        ' (DWORD) dest = pattern
  725. Private Type BITMAP '14 bytes
  726.         bmType As Long
  727.         bmWidth As Long
  728.         bmHeight As Long
  729.         bmWidthBytes As Long
  730.         bmPlanes As Integer
  731.         bmBitsPixel As Integer
  732.         bmBits As Long
  733. End Type
  734. Private Type RGBQUAD
  735.     rgbBlue As Byte
  736.     rgbGreen As Byte
  737.     rgbRed As Byte
  738.     rgbAlpha As Byte
  739. End Type
  740.  
  741. Private Type BITMAPINFOHEADER
  742.     bmSize As Long
  743.     bmWidth As Long
  744.     bmHeight As Long
  745.     bmPlanes As Integer
  746.     bmBitCount As Integer
  747.     bmCompression As Long
  748.     bmSizeImage As Long
  749.     bmXPelsPerMeter As Long
  750.     bmYPelsPerMeter As Long
  751.     bmClrUsed As Long
  752.     bmClrImportant As Long
  753. End Type
  754.  
  755. Private Type BITMAPINFO
  756.     bmHeader As BITMAPINFOHEADER
  757.     bmColors(0 To 255) As RGBQUAD
  758. End Type
  759.  
  760. Private bm As BITMAP
  761.   Private bmi As BITMAPINFO
  762.   
  763.  
  764. '............................ DIB
  765. Private Declare Function StretchDIBits Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal dWidth As Long, ByVal dHeight As Long, ByVal SrcX As Long, ByVal SrcY As Long, ByVal SrcWidth As Long, ByVal SrcHeight As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long, ByVal RasterOp As Long) As Long
  766. Private arDIB() As Byte
  767.  
  768. '............................ CURSOR
  769. ' The ICONINFO structure contains information about an icon or a cursor.
  770. Private Type ICONINFO
  771.     fIcon As Long       ' Specifies whether this structure defines an icon or a cursor.
  772.                         ' A value of TRUE specifies an icon; FALSE specifies a cursor.
  773.     xHotspot As Long    ' Specifies the x-coordinate of a cursor's hot spot.
  774.     yHotspot As Long    ' Specifies the y-coordinate of a cursor's hot spot.
  775.                         ' If these structures defines an icon, the hot spot is always
  776.                         ' in the center of the icon, and this member is ignored.
  777.     hbmMask As Long     ' Specifies the icon bitmask bitmap.
  778.     hbmColor As Long    ' Identifies the icon color bitmap.
  779. End Type
  780. ' The GetIconInfo function retrieves information about the specified icon or cursor.
  781. Private Declare Function GetIconInfo Lib "user32" (ByVal hIcon As Long, piconinfo As ICONINFO) As Long
  782. ' The CreateIconIndirect function creates an icon or cursor from an ICONINFO structure.
  783. Private Declare Function CreateIconIndirect Lib "user32" (piconinfo As ICONINFO) As Long
  784. ' The DestroyIcon function destroys an icon and frees any memory the icon occupied
  785. Private Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long
  786. ' The SetClassLong function replaces the specified 32-bit (long) value
  787. ' at the specified offset into the extra class memory or the WNDCLASS structure
  788. ' for the class to which the specified window belongs.
  789. Private Declare Function SetClassLong Lib "user32" Alias "SetClassLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  790. Private Const GCL_HCURSOR = (-12)
  791. Private pIF As ICONINFO
  792. Private oldCursor As Long
  793. Private hCursor As Long     ' handle to active cursor
  794.  
  795. '............................ BRUSH
  796. Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
  797. Private hBrush As Long
  798.  
  799. ' color pick
  800. Private iRed As Integer
  801. Private iGreen As Integer
  802. Private iBlue As Integer
  803. Private iIncrement As Integer
  804. Private iLower As Integer
  805. Private iSelected As Integer
  806. Private swActivated As Boolean
  807. Private lColorUnderMouse As Long
  808. ' Constants form width
  809. Private Const cFormWidthDefault As Single = 6315
  810. Private Const cFormWidthLarge As Single = 7500
  811.  
  812. Private Sub chCompare_Click()
  813. ' show/hide the second set of labels (color,values)
  814.    If chCompare.Value = vbChecked Then
  815.       Me.Width = cFormWidthLarge
  816.    Else
  817.       Me.Width = cFormWidthDefault
  818.    End If
  819. End Sub
  820.  
  821. Private Sub chCursor_Click()
  822. ' cursor type: eye dropper or colorized cursor
  823.    picPick.MousePointer = IIf(chCursor.Value = vbChecked, ccDefault, ccCustom)
  824. End Sub
  825.  
  826. Private Sub cmdBackcolor_Click()
  827.    frBackcolor.Visible = True
  828. End Sub
  829.  
  830. Private Sub cmdCancel_Click()
  831.    frBackcolor.Visible = False
  832. End Sub
  833.  
  834. Private Sub cmdClear_Click()
  835. ' clear pick listboxes
  836.    lbPicks(0).Clear
  837.    lbPicks(1).Clear
  838.    lbPicks(2).Clear
  839.    lbPicks(0).Visible = False
  840.    lbPicks(1).Visible = False
  841. End Sub
  842.  
  843. Private Sub Form_Load()
  844.    
  845. ' fill up the bmi (Bitmap information variable) with all of the appropriate data
  846.    With bmi.bmHeader
  847.       .bmSize = 40 'Size, in bytes, of the header (always 40)
  848.        .bmPlanes = 1 'Number of planes (always one for this instance)
  849.        .bmBitCount = 32 'Bits per pixel
  850.        .bmCompression = 0 'Compression: standard/none or RLE
  851.     End With
  852.     
  853. ' set up DIB using characteristics of picture box control
  854.    GetObject picPick.Image, Len(bm), bm
  855.    
  856. ' Build a correctly sized DIB array
  857.     ReDim arDIB(3, bm.bmWidth - 1, bm.bmHeight)
  858.     
  859. ' Now that we know the object's size, finish building the temporary header to pass to the StretchDIBits call
  860.     '(continuing to use the 'bmi' we used above)
  861.    bmi.bmHeader.bmWidth = bm.bmWidth
  862.    bmi.bmHeader.bmHeight = bm.bmHeight
  863.  
  864. ' prepare for clorized cursor
  865.    CursorDC = CreateCompatibleDC(Me.hdc)
  866.    ' init the pIF structure
  867.    With pIF
  868.       .xHotspot = 15
  869.       .yHotspot = 15
  870.       .hbmColor = CreateCompatibleBitmap(Me.hdc, 32, 32)
  871.       .hbmMask = CreateCompatibleBitmap(Me.hdc, 32, 32)
  872.    End With
  873.    
  874. ' init ucRange
  875.    With ucRange
  876.       .Minimum = 0
  877.       .Maximum = 255
  878.    End With
  879.    optIncrements(0).Value = True
  880.    
  881. ' init frame backcolor
  882.    frBackcolor.Visible = False
  883.    optBackcolor(0).Value = True
  884.    
  885.    Me.Width = cFormWidthDefault
  886.    lblVariableColor(0).Caption = ""
  887.    Me.Show
  888.    optSelect(0).Value = False
  889.    swActivated = True
  890. End Sub
  891.  
  892. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  893. ' reset to form's cursor
  894.    If hCursor <> 0 Then
  895.       DestroyIcon hCursor
  896.       hCursor = 0
  897.    End If
  898. End Sub
  899.  
  900. Private Sub Form_Unload(Cancel As Integer)
  901. ' clean up
  902.    If hCursor <> 0 Then
  903.       DestroyIcon hCursor
  904.       hCursor = 0
  905.    End If
  906.    SelectObject CursorDC, oldCursorObj
  907.    DeleteObject pIF.hbmColor
  908.    SelectObject CursorDC, oldBrush
  909.    DeleteObject hBrush
  910.    DeleteDC CursorDC
  911.    
  912.    Set frmPick = Nothing
  913. End Sub
  914.  
  915. Private Sub lblHex_Click(Index As Integer)
  916.    Clipboard.Clear
  917.    Clipboard.SetText "&H" & lblHex(Index).Caption
  918. End Sub
  919.  
  920. Private Sub lblLong_Click(Index As Integer)
  921.    Clipboard.Clear
  922.    Clipboard.SetText lblLong(Index).Caption
  923. End Sub
  924.  
  925. Private Sub lblRGB_Click(Index As Integer)
  926.    Clipboard.Clear
  927.    Clipboard.SetText "RGB(" & lblRGB(Index).Caption & ")"
  928. End Sub
  929.  
  930. Private Sub lbPicks_Click(Index As Integer)
  931. ' user clicked a color pick list box
  932.    Dim lPickColor As Long
  933.    If Index = 2 Then
  934.       ' form's backcolor
  935.       Me.BackColor = lbPicks(Index).ItemData(lbPicks(Index).ListIndex)
  936.       frBackcolor.Visible = False
  937.    Else
  938.       ' show details of color picked
  939.       subShowPick lbPicks(Index).ItemData(lbPicks(Index).ListIndex), Index
  940.    End If
  941. End Sub
  942.  
  943. Private Sub optBackcolor_Click(Index As Integer)
  944.    ucPickBox.Visible = Not CBool(Index)
  945.    lbPicks(2).Visible = Index
  946. End Sub
  947.  
  948. Private Sub optIncrements_Click(Index As Integer)
  949. ' compute new range and increments and refresh pick picturebox
  950.    With ucRange
  951.       .Range = 256 / (2 ^ Index)
  952.       iIncrement = .Range / 16
  953.    End With
  954.    
  955.    If swActivated Then
  956.       subFillPick
  957.    End If
  958. End Sub
  959.  
  960. Private Sub optSelect_Click(Index As Integer)
  961. ' selection of main color pair
  962.    If swActivated Then
  963.       iSelected = Index
  964.       subFillPick
  965.       lblVariableColor(0) = "Use slider to vary the " & Choose(iSelected + 1, "blue", "red", "green") & " component"
  966.       lblVariableColor(1) = "If the slider has the focus, you can use the Left and Right arrow keyboard keys decrement/increment its value"
  967.    End If
  968.  
  969. End Sub
  970.  
  971. Private Sub picPick_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  972.    Dim lNewColorUnderMouse As Long
  973.    
  974.    lNewColorUnderMouse = GetPixel(picPick.hdc, CLng(X), CLng(Y))
  975.    If lNewColorUnderMouse <> lColorUnderMouse Then
  976.       If hCursor <> 0 Then
  977.          DestroyIcon hCursor
  978.          hCursor = 0
  979.       End If
  980.       lColorUnderMouse = lNewColorUnderMouse
  981.       oldCursorObj = SelectObject(CursorDC, pIF.hbmColor)
  982.       hBrush = CreateSolidBrush(lColorUnderMouse)
  983.       oldBrush = SelectObject(CursorDC, hBrush)
  984.       PatBlt CursorDC, 0, 0, 32, 32, PATCOPY
  985.       SelectObject CursorDC, oldCursorObj
  986.    hCursor = CreateIconIndirect(pIF)
  987.    oldCursor = SetClassLong(picPick.hWnd, GCL_HCURSOR, hCursor)
  988.    End If
  989.  
  990. End Sub
  991.  
  992. Private Sub picPick_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  993. ' A color was clicked. Show selection: actual color and numeric, hex and RGB values.
  994. ' Add this selection also to the listboxes
  995.    Dim lClickedColor As Long
  996.    Dim iCount As Integer
  997.    
  998.    lClickedColor = GetPixel(picPick.hdc, CLng(X), CLng(Y))
  999.    subShowPick lClickedColor
  1000.    iCount = lbPicks(0).ListCount + 1
  1001.    lbPicks(0).AddItem "Pick " & Str$(iCount)
  1002.    lbPicks(0).ItemData(lbPicks(0).NewIndex) = lClickedColor
  1003.    lbPicks(1).AddItem "Pick " & Str$(iCount)
  1004.    lbPicks(1).ItemData(lbPicks(1).NewIndex) = lClickedColor
  1005.    lbPicks(2).AddItem "Pick " & Str$(iCount)
  1006.    lbPicks(2).ItemData(lbPicks(1).NewIndex) = lClickedColor
  1007.    If iCount > 1 Then
  1008.       lbPicks(0).Visible = True
  1009.       lbPicks(1).Visible = True
  1010.    End If
  1011. End Sub
  1012.  
  1013. Private Sub slVariableColor_Scroll()
  1014. ' slider
  1015.    subFillPick
  1016.  
  1017. End Sub
  1018.  
  1019. Private Sub ucPickBox_ColorChanged(NewColor As Long)
  1020. ' give form's background the color selected with the ucPickBox user control
  1021.    Me.BackColor = NewColor
  1022.    frBackcolor.Visible = False
  1023. End Sub
  1024.  
  1025. Private Sub ucRange_RangeChanged(lLower As Long, lUpper As Long)
  1026. ' triggered by range changes in the ucRange user control
  1027.    iLower = lLower
  1028.    If swActivated Then
  1029.       subFillPick
  1030.    End If
  1031. End Sub
  1032.  
  1033. '================================================================================================
  1034. '
  1035. '                                     LOCAL PROCEDURES
  1036. '________________________________________________________________________________________________
  1037.  
  1038. Private Sub subFillPick()
  1039. ' iSelected defines the choice of main color pair and color for slider
  1040.    Dim X As Integer
  1041.    Dim Y As Integer
  1042.    Dim x1 As Long
  1043.    Dim y1 As Long
  1044.    
  1045.    Select Case iSelected
  1046.       Case 0: iBlue = slVariableColor.Value
  1047.       Case 1: iRed = slVariableColor.Value
  1048.       Case 2: iGreen = slVariableColor.Value
  1049.         End Select
  1050.         
  1051. ' squares of 10x10 of a color
  1052.    For X = 0 To 16
  1053.       For Y = 0 To 16
  1054.          Select Case iSelected
  1055.             Case 0
  1056.                iRed = X * iIncrement + iLower
  1057.                iGreen = (16 - Y) * iIncrement + iLower ' (*)
  1058.             Case 1
  1059.                iGreen = X * iIncrement + iLower
  1060.                iBlue = (16 - Y) * iIncrement + iLower ' (*)
  1061.             Case 2
  1062.                iBlue = X * iIncrement + iLower
  1063.                iRed = (16 - Y) * iIncrement + iLower ' (*)
  1064.          End Select
  1065. ' check overflow on RGB values
  1066.          If iRed > 255 Then iRed = 255
  1067.          If iGreen > 255 Then iGreen = 255
  1068.          If iBlue > 255 Then iBlue = 255
  1069.          
  1070. ' fill square with the color
  1071.          For x1 = X * 10 To X * 10 + 9
  1072.             For y1 = Y * 10 To Y * 10 + 9
  1073.                arDIB(0, x1, y1) = CByte(iBlue)
  1074.                arDIB(1, x1, y1) = CByte(iGreen)
  1075.                arDIB(2, x1, y1) = CByte(iRed)
  1076.             Next y1
  1077.          Next x1
  1078.       Next Y
  1079.    Next X
  1080.    
  1081. ' now we can (finally) show the DIB
  1082.    StretchDIBits picPick.hdc, 0, 0, bm.bmWidth, bm.bmHeight, 0, 0, bm.bmWidth, bm.bmHeight, arDIB(0, 0, 0), bmi, 0, vbSrcCopy
  1083.    picPick.Refresh
  1084.  
  1085.  ' (*) this ensures correct order of lines when the final picture is filled with the DIB
  1086.  '     bottom to top
  1087.  End Sub
  1088.  
  1089.  
  1090. Private Sub subShowPick(ByVal lColor As Long, Optional Index As Integer = 0)
  1091. ' Show color and its numeric, hex and RGB values in indexed contols
  1092.    Dim lRed As Long
  1093.    Dim lGreen As Long
  1094.    Dim lBlue As Long
  1095.    
  1096.    lblSelectedColor(Index).BackColor = lColor
  1097.    lblLong(Index) = Format(lColor)
  1098.    lblHex(Index) = Hex$(lColor)
  1099.    lRed = lColor And &HFF
  1100.    lGreen = (lColor And &HFF00&) \ &H100&
  1101.    lBlue = (lColor And &HFF0000) \ &H10000
  1102.    lblRGB(Index) = Format(lRed) & "," & Format(lGreen) & "," & Format(lBlue)
  1103. End Sub
  1104.