home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH4 / SRC / COLORBAL.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-01-03  |  22.7 KB  |  728 lines

  1. VERSION 4.00
  2. Begin VB.Form ColorBalForm 
  3.    Caption         =   "Color Balance"
  4.    ClientHeight    =   5235
  5.    ClientLeft      =   1380
  6.    ClientTop       =   915
  7.    ClientWidth     =   4695
  8.    Height          =   5925
  9.    Left            =   1320
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   349
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   313
  14.    Top             =   285
  15.    Width           =   4815
  16.    Begin VB.PictureBox BalPict 
  17.       BorderStyle     =   0  'None
  18.       Height          =   975
  19.       Left            =   0
  20.       ScaleHeight     =   975
  21.       ScaleWidth      =   4695
  22.       TabIndex        =   4
  23.       Top             =   4200
  24.       Width           =   4695
  25.       Begin VB.HScrollBar ScrollBlue 
  26.          Enabled         =   0   'False
  27.          Height          =   255
  28.          LargeChange     =   10
  29.          Left            =   860
  30.          Max             =   100
  31.          Min             =   -100
  32.          TabIndex        =   9
  33.          Top             =   720
  34.          Width           =   3855
  35.       End
  36.       Begin VB.HScrollBar ScrollGreen 
  37.          Enabled         =   0   'False
  38.          Height          =   255
  39.          LargeChange     =   10
  40.          Left            =   860
  41.          Max             =   100
  42.          Min             =   -100
  43.          TabIndex        =   7
  44.          Top             =   360
  45.          Width           =   3855
  46.       End
  47.       Begin VB.HScrollBar ScrollRed 
  48.          Enabled         =   0   'False
  49.          Height          =   255
  50.          LargeChange     =   10
  51.          Left            =   860
  52.          Max             =   100
  53.          Min             =   -100
  54.          TabIndex        =   5
  55.          Top             =   0
  56.          Width           =   3855
  57.       End
  58.       Begin VB.Label ValueBlue 
  59.          BorderStyle     =   1  'Fixed Single
  60.          Caption         =   "0"
  61.          Height          =   255
  62.          Left            =   480
  63.          TabIndex        =   13
  64.          Top             =   720
  65.          Width           =   375
  66.       End
  67.       Begin VB.Label ValueRed 
  68.          BorderStyle     =   1  'Fixed Single
  69.          Caption         =   "0"
  70.          Height          =   255
  71.          Left            =   480
  72.          TabIndex        =   12
  73.          Top             =   0
  74.          Width           =   375
  75.       End
  76.       Begin VB.Label ValueGreen 
  77.          BorderStyle     =   1  'Fixed Single
  78.          Caption         =   "0"
  79.          Height          =   255
  80.          Left            =   480
  81.          TabIndex        =   11
  82.          Top             =   360
  83.          Width           =   375
  84.       End
  85.       Begin VB.Label Label1 
  86.          Caption         =   "Blue"
  87.          Height          =   255
  88.          Index           =   2
  89.          Left            =   0
  90.          TabIndex        =   10
  91.          Top             =   720
  92.          Width           =   495
  93.       End
  94.       Begin VB.Label Label1 
  95.          Caption         =   "Green"
  96.          Height          =   255
  97.          Index           =   1
  98.          Left            =   0
  99.          TabIndex        =   8
  100.          Top             =   360
  101.          Width           =   495
  102.       End
  103.       Begin VB.Label Label1 
  104.          Caption         =   "Red"
  105.          Height          =   255
  106.          Index           =   0
  107.          Left            =   0
  108.          TabIndex        =   6
  109.          Top             =   0
  110.          Width           =   495
  111.       End
  112.    End
  113.    Begin VB.PictureBox FromSwin 
  114.       Height          =   3855
  115.       Left            =   0
  116.       ScaleHeight     =   253
  117.       ScaleMode       =   3  'Pixel
  118.       ScaleWidth      =   293
  119.       TabIndex        =   2
  120.       Top             =   0
  121.       Width           =   4455
  122.       Begin VB.PictureBox FromPict 
  123.          AutoRedraw      =   -1  'True
  124.          AutoSize        =   -1  'True
  125.          Height          =   1905
  126.          Left            =   0
  127.          ScaleHeight     =   123
  128.          ScaleMode       =   3  'Pixel
  129.          ScaleWidth      =   88
  130.          TabIndex        =   3
  131.          Top             =   0
  132.          Width           =   1380
  133.       End
  134.    End
  135.    Begin VB.HScrollBar FromHBar 
  136.       Enabled         =   0   'False
  137.       Height          =   255
  138.       Left            =   0
  139.       TabIndex        =   1
  140.       Top             =   3840
  141.       Width           =   4485
  142.    End
  143.    Begin VB.VScrollBar FromVBar 
  144.       Enabled         =   0   'False
  145.       Height          =   3855
  146.       Left            =   4440
  147.       TabIndex        =   0
  148.       Top             =   0
  149.       Width           =   255
  150.    End
  151.    Begin MSComDlg.CommonDialog FileDialog 
  152.       Left            =   4200
  153.       Top             =   3600
  154.       _Version        =   65536
  155.       _ExtentX        =   847
  156.       _ExtentY        =   847
  157.       _StockProps     =   0
  158.       CancelError     =   -1  'True
  159.    End
  160.    Begin VB.Menu mnuFile 
  161.       Caption         =   "&File"
  162.       Begin VB.Menu mnuFileLoad 
  163.          Caption         =   "&Load..."
  164.          Shortcut        =   ^L
  165.       End
  166.       Begin VB.Menu mnuFileSep2 
  167.          Caption         =   "-"
  168.       End
  169.       Begin VB.Menu mnuFileExit 
  170.          Caption         =   "E&xit"
  171.       End
  172.    End
  173. Attribute VB_Name = "ColorBalForm"
  174. Attribute VB_Creatable = False
  175. Attribute VB_Exposed = False
  176. Option Explicit
  177. Dim SysPalSize As Integer
  178. Dim NumStaticColors As Integer
  179. Dim StaticColor1 As Integer
  180. Dim StaticColor2 As Integer
  181. Dim bytes() As Byte
  182. Dim wid As Long
  183. Dim hgt As Long
  184. Dim LogPal As Integer
  185. Dim origpal(0 To 255) As PALETTEENTRY
  186. Dim newpal(0 To 255) As PALETTEENTRY
  187. Dim SettingValues As Boolean
  188. ' ***********************************************
  189. ' Load the control's palette so the non-static
  190. ' colors are grays. Map the logical palette to
  191. ' match the system palette. Convert the image to
  192. ' use the non-static grays.
  193. ' Set the following module global variables.
  194. '   LogPal      Image logical palette handle.
  195. '   origpal()  Image logical palette entries.
  196. '   wid         Width of image.
  197. '   hgt         Height of image.
  198. '   bytes(1 To wid, 1 To hgt)
  199. '               Image pixel values.
  200. ' ***********************************************
  201. Sub MatchGrayPalette(pic As Control)
  202. Dim sys(0 To 255) As PALETTEENTRY
  203. Dim i As Integer
  204. Dim bm As BITMAP
  205. Dim hbm As Integer
  206. Dim status As Long
  207. Dim X As Integer
  208. Dim Y As Integer
  209. Dim gray As Single
  210. Dim dgray As Single
  211. Dim c As Integer
  212. Dim clr As Integer
  213.     ' Make sure pic has the foreground palette.
  214.     pic.ZOrder
  215.     i = RealizePalette(pic.hdc)
  216.     DoEvents
  217.     ' Get the system palette entries.
  218.     i = GetSystemPaletteEntries(pic.hdc, 0, SysPalSize, sys(0))
  219.         
  220.     ' Get the image pixels.
  221.     hbm = pic.Image
  222.     status = GetObject(hbm, BITMAP_SIZE, bm)
  223.     wid = bm.bmWidthBytes
  224.     hgt = bm.bmHeight
  225.     ReDim bytes(1 To wid, 1 To hgt)
  226.     status = GetBitmapBits(hbm, wid * hgt, bytes(1, 1))
  227.     ' Make the logical palette as big as possible.
  228.     LogPal = pic.Picture.hPal
  229.     If ResizePalette(LogPal, SysPalSize) = 0 Then
  230.         Beep
  231.         MsgBox "Error resizing logical palette.", _
  232.             vbExclamation
  233.         Exit Sub
  234.     End If
  235.     ' Blank the non-static colors.
  236.     For i = 0 To StaticColor1
  237.         origpal(i) = sys(i)
  238.     Next i
  239.     For i = StaticColor1 + 1 To StaticColor2 - 1
  240.         With origpal(i)
  241.             .peRed = 0
  242.             .peGreen = 0
  243.             .peBlue = 0
  244.             .peFlags = PC_NOCOLLAPSE
  245.         End With
  246.     Next i
  247.     For i = StaticColor2 To 255
  248.         origpal(i) = sys(i)
  249.     Next i
  250.     i = SetPaletteEntries(LogPal, 0, SysPalSize, origpal(0))
  251.     ' Insert the non-static grays.
  252.     gray = 0
  253.     dgray = 255 / (StaticColor2 - StaticColor1 - 2)
  254.     For i = StaticColor1 + 1 To StaticColor2 - 1
  255.         c = gray
  256.         gray = gray + dgray
  257.         With origpal(i)
  258.             .peRed = c
  259.             .peGreen = c
  260.             .peBlue = c
  261.         End With
  262.     Next i
  263.     i = SetPaletteEntries(LogPal, StaticColor1 + 1, StaticColor2 - StaticColor1 - 1, origpal(StaticColor1 + 1))
  264.     ' Recreate the image using the new colors.
  265.     For Y = 1 To hgt
  266.         For X = 1 To wid
  267.             clr = bytes(X, Y)
  268.             With sys(clr)
  269.                 c = (CInt(.peRed) + .peGreen + .peBlue) / 3
  270.             End With
  271.             bytes(X, Y) = NearestNonstaticGray(c)
  272.         Next X
  273.     Next Y
  274.     status = SetBitmapBits(hbm, wid * hgt, bytes(1, 1))
  275.     ' Realize the gray palette.
  276.     i = RealizePalette(pic.hdc)
  277.     pic.Refresh
  278. End Sub
  279. ' ************************************************
  280. ' Return the index of the nonstatic color closest
  281. ' to the given color value.
  282. ' ************************************************
  283. Function NearestNonstaticColor(ByVal r As Integer, ByVal g As Integer, ByVal b As Integer) As Integer
  284. Dim best_i As Integer
  285. Dim best_dist As Long
  286. Dim dist As Long
  287. Dim dr As Long
  288. Dim dg As Long
  289. Dim db As Long
  290. Dim i As Integer
  291.     best_dist = 1000000
  292.     For i = StaticColor1 + 1 To StaticColor2 - 1
  293.         With origpal(i)
  294.             dr = r - .peRed
  295.             dg = g - .peGreen
  296.             db = b - .peBlue
  297.             dist = dr * dr + dg * dg + db * db
  298.         End With
  299.         If best_dist > dist Then
  300.             best_i = i
  301.             best_dist = dist
  302.         End If
  303.     Next i
  304.     NearestNonstaticColor = best_i
  305. End Function
  306. ' ************************************************
  307. ' Return the index of the nonstatic gray closest
  308. ' to the given value (assuming the non-static
  309. ' colors are a gray scale created by
  310. ' MatchGrayPalette).
  311. ' ************************************************
  312. Function NearestNonstaticGray(c As Integer) As Integer
  313. Dim dgray As Single
  314.     If c < 0 Then
  315.         c = 0
  316.     ElseIf c > 255 Then
  317.         c = 255
  318.     End If
  319.     dgray = 255 / (StaticColor2 - StaticColor1 - 2)
  320.     NearestNonstaticGray = c / dgray + StaticColor1 + 1
  321. End Function
  322. ' ***********************************************
  323. ' Load the control's palette so it matches the
  324. ' the system palette. Remap any of the image's
  325. ' pixels that use static colors to non-static
  326. ' colors.
  327. ' Set the following module global variables.
  328. '   LogPal      Image logical palette handle.
  329. '   origpal()  Image logical palette entries.
  330. '   wid         Width of image.
  331. '   hgt         Height of image.
  332. '   bytes(1 To wid, 1 To hgt)
  333. '               Image pixel values.
  334. ' ***********************************************
  335. Sub MatchColorPalette(pic As Control)
  336. Dim sys(0 To 255) As PALETTEENTRY
  337. Dim i As Integer
  338. Dim bm As BITMAP
  339. Dim hbm As Integer
  340. Dim status As Long
  341. Dim X As Integer
  342. Dim Y As Integer
  343. Dim clr As Integer
  344.     ' Make sure pic has the foreground palette.
  345.     pic.ZOrder
  346.     i = RealizePalette(pic.hdc)
  347.     DoEvents
  348.     ' Get the system palette entries.
  349.     i = GetSystemPaletteEntries(pic.hdc, 0, SysPalSize, sys(0))
  350.             
  351.     ' Make the logical palette as big as possible.
  352.     LogPal = pic.Picture.hPal
  353.     If ResizePalette(LogPal, SysPalSize) = 0 Then
  354.         Beep
  355.         MsgBox "Error resizing logical palette.", _
  356.             vbExclamation
  357.         Exit Sub
  358.     End If
  359.     ' Blank the non-static colors.
  360.     For i = 0 To StaticColor1
  361.         origpal(i) = sys(i)
  362.     Next i
  363.     For i = StaticColor1 + 1 To StaticColor2 - 1
  364.         With origpal(i)
  365.             .peRed = 0
  366.             .peGreen = 0
  367.             .peBlue = 0
  368.             .peFlags = PC_NOCOLLAPSE
  369.         End With
  370.     Next i
  371.     For i = StaticColor2 To 255
  372.         origpal(i) = sys(i)
  373.     Next i
  374.     i = SetPaletteEntries(LogPal, 0, SysPalSize, origpal(0))
  375.     ' Insert the non-static colors.
  376.     For i = StaticColor1 + 1 To StaticColor2 - 1
  377.         origpal(i) = sys(i)
  378.         origpal(i).peFlags = PC_NOCOLLAPSE
  379.     Next i
  380.     i = SetPaletteEntries(LogPal, StaticColor1 + 1, StaticColor2 - StaticColor1 - 1, origpal(StaticColor1 + 1))
  381.     ' Realize the new palette.
  382.     i = RealizePalette(pic.hdc)
  383.     ' Get the image pixels.
  384.     hbm = pic.Image
  385.     status = GetObject(hbm, BITMAP_SIZE, bm)
  386.     wid = bm.bmWidthBytes
  387.     hgt = bm.bmHeight
  388.     ReDim bytes(1 To wid, 1 To hgt)
  389.     status = GetBitmapBits(hbm, wid * hgt, bytes(1, 1))
  390.     ' Remap any pixels using static colors.
  391.     For Y = 1 To hgt
  392.         For X = 1 To wid
  393.             clr = bytes(X, Y)
  394.             If clr <= StaticColor1 Or clr >= StaticColor2 Then
  395.                 With sys(clr)
  396.                     bytes(X, Y) = _
  397.                         NearestNonstaticColor( _
  398.                         .peRed, .peGreen, .peBlue)
  399.                 End With
  400.             End If
  401.         Next X
  402.     Next Y
  403.     ' Update the image's pixel values.
  404.     status = SetBitmapBits(hbm, wid * hgt, bytes(1, 1))
  405.     pic.Refresh
  406. End Sub
  407. ' ***********************************************
  408. ' Load the indicated file and prepare to work
  409. ' with its palette.
  410. ' ***********************************************
  411. Sub LoadFromPict(fname As String)
  412. Dim status As Long
  413. Dim i As Integer
  414.     On Error GoTo LoadFileError
  415.     FromPict.Picture = LoadPicture(fname)
  416.     On Error GoTo 0
  417.         
  418.     FromHBar.Enabled = False
  419.     FromVBar.Enabled = False
  420.     ScrollRed.Enabled = False
  421.     ScrollGreen.Enabled = False
  422.     ScrollBlue.Enabled = False
  423.     DoEvents
  424.     MatchColorPalette FromPict
  425.     For i = 0 To SysPalSize - 1
  426.         newpal(i) = origpal(i)
  427.     Next i
  428.     FromPict.Move 0, 0
  429.     ResetScrollBars
  430.     ScrollRed.Enabled = True
  431.     ScrollGreen.Enabled = True
  432.     ScrollBlue.Enabled = True
  433.     SettingValues = True
  434.     ScrollRed.Value = 0
  435.     ScrollGreen.Value = 0
  436.     ScrollBlue.Value = 0
  437.     SettingValues = False
  438.         
  439.     Caption = "Color Balance [" & fname & "]"
  440.     Exit Sub
  441. LoadFileError:
  442.     Beep
  443.     MsgBox "Error loading file " & fname & "." & _
  444.         vbCrLf & Error$
  445.     Exit Sub
  446. End Sub
  447. ' ***********************************************
  448. ' Set the Max and LargeChange properties for the
  449. ' image scroll bars.
  450. ' ***********************************************
  451. Sub ResetScrollBars()
  452.     ' FromHBar.
  453.     FromHBar.Value = 0
  454.     If FromSwin.ScaleWidth >= FromPict.Width Then
  455.         FromHBar.Enabled = False
  456.     Else
  457.         FromHBar.Max = FromPict.Width - FromSwin.ScaleWidth
  458.         FromHBar.LargeChange = FromSwin.ScaleWidth
  459.         FromHBar.Enabled = True
  460.     End If
  461.     ' FromVBar.
  462.     FromVBar.Value = 0
  463.     If FromSwin.ScaleHeight >= FromPict.Height Then
  464.         FromVBar.Enabled = False
  465.     Else
  466.         FromVBar.Max = FromPict.Height - FromSwin.ScaleHeight
  467.         FromVBar.LargeChange = FromSwin.ScaleHeight
  468.         FromVBar.Enabled = True
  469.     End If
  470. End Sub
  471. ' ************************************************
  472. ' Adjust the colors using the current values of
  473. ' ScrollRed, ScrollGreen, and ScrollBlue.
  474. ' If -100 <= v <= 0, then subtract v percent of
  475. ' the corresponding color value.
  476. ' If 0 <= v <= 100, then add v percent of the
  477. ' difference between the corresponding color value
  478. ' and 255.
  479. ' Thus:
  480. '   When v = -100, the color goes to 0.
  481. '   When v =    0, the color is unchanged.
  482. '   When v =  100, the color goes to 255.
  483. ' ************************************************
  484. Sub UpdateColors()
  485. Dim i As Integer
  486. Dim vr As Single
  487. Dim vg As Single
  488. Dim vb As Single
  489. Dim fr As Single
  490. Dim fg As Single
  491. Dim fb As Single
  492. Dim r As Integer
  493. Dim g As Integer
  494. Dim b As Integer
  495.     ' Get the scroll bar values.
  496.     vr = ScrollRed.Value / 100#
  497.     If vr < 0 Then
  498.         fr = 1 + vr
  499.     Else
  500.         fr = vr
  501.     End If
  502.     vg = ScrollGreen.Value / 100#
  503.     If vg < 0 Then
  504.         fg = 1 + vg
  505.     Else
  506.         fg = vg
  507.     End If
  508.     vb = ScrollBlue.Value / 100#
  509.     If vb < 0 Then
  510.         fb = 1 + vb
  511.     Else
  512.         fb = vb
  513.     End If
  514.     ' Set the new palette entries.
  515.     For i = StaticColor1 + 1 To StaticColor2 - 1
  516.         With origpal(i)
  517.             r = .peRed
  518.             If vr < 0 Then
  519.                 r = r * fr
  520.             Else
  521.                 r = r + (255 - r) * fr
  522.             End If
  523.         
  524.             g = .peGreen
  525.             If vg < 0 Then
  526.                 g = g * fg
  527.             Else
  528.                 g = g + (255 - g) * fg
  529.             End If
  530.             
  531.             b = .peBlue
  532.             If vb < 0 Then
  533.                 b = b * fb
  534.             Else
  535.                 b = b + (255 - b) * fb
  536.             End If
  537.         End With
  538.         With newpal(i)
  539.             .peRed = r
  540.             .peGreen = g
  541.             .peBlue = b
  542.             .peFlags = PC_NOCOLLAPSE
  543.         End With
  544.     Next i
  545.     i = SetPaletteEntries(LogPal, StaticColor1 + 1, StaticColor2 - StaticColor1 - 1, newpal(StaticColor1 + 1))
  546.     i = RealizePalette(FromPict.hdc)
  547. End Sub
  548. ' ***********************************************
  549. ' Give the form and all the picture boxes an
  550. ' hourglass cursor.
  551. ' ***********************************************
  552. Sub WaitStart()
  553.     MousePointer = vbHourglass
  554.     FromPict.MousePointer = vbHourglass
  555.     DoEvents
  556. End Sub
  557. ' ***********************************************
  558. ' Restore the mouse pointers for the form and all
  559. ' the picture boxes.
  560. ' ***********************************************
  561. Sub WaitEnd()
  562.     MousePointer = vbDefault
  563.     FromPict.MousePointer = vbDefault
  564. End Sub
  565. Private Sub Form_Load()
  566.     ' Make sure the screen supports palettes.
  567.     If Not GetDeviceCaps(hdc, RASTERCAPS) And RC_PALETTE Then
  568.         Beep
  569.         MsgBox "This monitor does not support palettes.", _
  570.             vbCritical
  571.         End
  572.     End If
  573.     ' Get system palette size and # static colors.
  574.     SysPalSize = GetDeviceCaps(hdc, SIZEPALETTE)
  575.     NumStaticColors = GetDeviceCaps(hdc, NUMRESERVED)
  576.     StaticColor1 = NumStaticColors \ 2 - 1
  577.     StaticColor2 = SysPalSize - NumStaticColors \ 2
  578.     ' Remove the borders from FromPict.
  579.     FromPict.BorderStyle = vbTransparent
  580.     ' Make sure FromPict has control.
  581.     FromPict.ZOrder
  582. End Sub
  583. ' ***********************************************
  584. ' Make the picture as large as possible.
  585. ' ***********************************************
  586. Private Sub Form_Resize()
  587. Const GAP = 4
  588. Dim hgt As Single
  589. Dim wid As Single
  590. Dim lft As Single
  591.     If WindowState = vbMinimized Then Exit Sub
  592.         
  593.     hgt = ScaleHeight - FromHBar.Height - 1 - _
  594.         BalPict.Height - 2 * GAP
  595.     wid = ScaleWidth - FromVBar.Width - 1
  596.     ' Place FromSwin and its scroll bars.
  597.     FromSwin.Move 0, 0, wid, hgt
  598.     FromVBar.Move _
  599.         FromSwin.Left + FromSwin.Width + 1, _
  600.         0, FromVBar.Width, hgt
  601.     FromHBar.Move _
  602.         FromSwin.Left, FromSwin.Height + 1, _
  603.         wid
  604.         
  605.     BalPict.Move 0, _
  606.         FromHBar.Top + FromHBar.Height + GAP, _
  607.         ScaleWidth
  608.     ScrollRed.Width = BalPict.ScaleWidth - ScrollRed.Left
  609.     ScrollGreen.Width = ScrollRed.Width
  610.     ScrollBlue.Width = ScrollRed.Width
  611.     ResetScrollBars
  612. End Sub
  613. Private Sub Form_Unload(Cancel As Integer)
  614.     End
  615. End Sub
  616. ' ***********************************************
  617. ' Move FromPict within FromSwin.
  618. ' ***********************************************
  619. Private Sub FromHBar_Change()
  620.     FromPict.Left = -FromHBar.Value
  621. End Sub
  622. ' ***********************************************
  623. ' Move FromPict within FromSwin.
  624. ' ***********************************************
  625. Private Sub FromHBar_Scroll()
  626.     FromPict.Left = -FromHBar.Value
  627. End Sub
  628. ' ************************************************
  629. ' Present a message indicating the pixel's palette
  630. ' index and color value.
  631. ' ************************************************
  632. Private Sub FromPict_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  633.     If X > wid Or Y > hgt Then Exit Sub
  634.     With newpal(bytes(X, Y))
  635.         MsgBox "Palette index:" & Str$(bytes(X, Y)) & _
  636.             vbCrLf & "Red:  " & Str$(.peRed) & _
  637.             vbCrLf & "Green:" & Str$(.peGreen) & _
  638.             vbCrLf & "Blue: " & Str$(.peBlue)
  639.     End With
  640. End Sub
  641. ' ***********************************************
  642. ' Load a new image file.
  643. ' ***********************************************
  644. Private Sub mnuFileLoad_Click()
  645. Dim fname As String
  646.     ' Allow the user to pick a file.
  647.     On Error Resume Next
  648.     FileDialog.filename = "*.BMP;*.ICO;*.RLE;*.WMF;*.DIB"
  649.     FileDialog.Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly
  650.     FileDialog.ShowOpen
  651.     If Err.Number = cdlCancel Then
  652.         Exit Sub
  653.     ElseIf Err.Number <> 0 Then
  654.         Beep
  655.         MsgBox "Error selecting file.", , vbExclamation
  656.         Exit Sub
  657.     End If
  658.     On Error GoTo 0
  659.     fname = Trim$(FileDialog.filename)
  660.     FileDialog.InitDir = Left$(fname, Len(fname) _
  661.         - Len(FileDialog.FileTitle) - 1)
  662.     ' Load the picture.
  663.     WaitStart
  664.     LoadFromPict fname
  665.     WaitEnd
  666. End Sub
  667. ' ***********************************************
  668. ' End the application. (See also the QueryUnload
  669. ' event.)
  670. ' ***********************************************
  671. Private Sub mnuFileExit_Click()
  672.     Unload Me
  673. End Sub
  674. ' ***********************************************
  675. ' Move FromPict within FromSwin.
  676. ' ***********************************************
  677. Private Sub FromVBar_Change()
  678.     FromPict.Top = -FromVBar.Value
  679. End Sub
  680. ' ***********************************************
  681. ' Move FromPict within FromSwin.
  682. ' ***********************************************
  683. Private Sub FromVBar_Scroll()
  684.     FromPict.Top = -FromVBar.Value
  685. End Sub
  686. ' ************************************************
  687. ' Update the color balance.
  688. ' ************************************************
  689. Private Sub ScrollBlue_Change()
  690.     ValueBlue.Caption = Format$(ScrollBlue.Value)
  691.     If SettingValues Then Exit Sub
  692.     UpdateColors
  693. End Sub
  694. ' ************************************************
  695. ' Update the color balance.
  696. ' ************************************************
  697. Private Sub ScrollBlue_Scroll()
  698.     ScrollBlue_Change
  699. End Sub
  700. ' ************************************************
  701. ' Update the color balance.
  702. ' ************************************************
  703. Private Sub ScrollGreen_Change()
  704.     ValueGreen.Caption = Format$(ScrollGreen.Value)
  705.     If SettingValues Then Exit Sub
  706.     UpdateColors
  707. End Sub
  708. ' ************************************************
  709. ' Update the color balance.
  710. ' ************************************************
  711. Private Sub ScrollGreen_Scroll()
  712.     ScrollGreen_Change
  713. End Sub
  714. ' ************************************************
  715. ' Update the color balance.
  716. ' ************************************************
  717. Private Sub ScrollRed_Change()
  718.     ValueRed.Caption = Format$(ScrollRed.Value)
  719.     If SettingValues Then Exit Sub
  720.     UpdateColors
  721. End Sub
  722. ' ************************************************
  723. ' Update the color balance.
  724. ' ************************************************
  725. Private Sub ScrollRed_Scroll()
  726.     ScrollRed_Change
  727. End Sub
  728.