home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / leadtools / ocx32.lt / view.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-06-30  |  22.0 KB  |  563 lines

  1. VERSION 5.00
  2. Object = "{00100003-B1BA-11CE-ABC6-F5B2E79D9E3F}#1.0#0"; "LTOCX10N.OCX"
  3. Begin VB.Form ViewFrm 
  4.    Appearance      =   0  'Flat
  5.    BackColor       =   &H00FFFFFF&
  6.    Caption         =   "Viewing Window"
  7.    ClientHeight    =   3600
  8.    ClientLeft      =   4125
  9.    ClientTop       =   1605
  10.    ClientWidth     =   5460
  11.    BeginProperty Font 
  12.       Name            =   "MS Sans Serif"
  13.       Size            =   8.25
  14.       Charset         =   0
  15.       Weight          =   700
  16.       Underline       =   0   'False
  17.       Italic          =   0   'False
  18.       Strikethrough   =   0   'False
  19.    EndProperty
  20.    ForeColor       =   &H80000008&
  21.    Icon            =   "view.frx":0000
  22.    LinkTopic       =   "Viewer"
  23.    MDIChild        =   -1  'True
  24.    PaletteMode     =   1  'UseZOrder
  25.    ScaleHeight     =   3600
  26.    ScaleWidth      =   5460
  27.    Visible         =   0   'False
  28.    Begin LEADLib.LEAD Lead1 
  29.       Height          =   1575
  30.       Left            =   240
  31.       TabIndex        =   0
  32.       Top             =   240
  33.       Width           =   2055
  34.       _Version        =   65536
  35.       _ExtentX        =   3625
  36.       _ExtentY        =   2778
  37.       _StockProps     =   229
  38.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  39.          Name            =   "MS Sans Serif"
  40.          Size            =   8.25
  41.          Charset         =   0
  42.          Weight          =   700
  43.          Underline       =   0   'False
  44.          Italic          =   0   'False
  45.          Strikethrough   =   0   'False
  46.       EndProperty
  47.       ScaleHeight     =   105
  48.       ScaleWidth      =   137
  49.       DataField       =   ""
  50.       BitmapDataPath  =   ""
  51.       AnnDataPath     =   ""
  52.       PanWinTitle     =   "PanWindow"
  53.       CLeadCtrl       =   0
  54.    End
  55.    Begin LEADLib.LEAD Lead2 
  56.       Height          =   1815
  57.       Left            =   2760
  58.       TabIndex        =   1
  59.       Top             =   1560
  60.       Width           =   2175
  61.       _Version        =   65536
  62.       _ExtentX        =   3836
  63.       _ExtentY        =   3201
  64.       _StockProps     =   229
  65.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  66.          Name            =   "MS Sans Serif"
  67.          Size            =   8.25
  68.          Charset         =   0
  69.          Weight          =   700
  70.          Underline       =   0   'False
  71.          Italic          =   0   'False
  72.          Strikethrough   =   0   'False
  73.       EndProperty
  74.       ScaleHeight     =   121
  75.       ScaleWidth      =   145
  76.       DataField       =   ""
  77.       BitmapDataPath  =   ""
  78.       AnnDataPath     =   ""
  79.       PanWinTitle     =   "PanWindow"
  80.       CLeadCtrl       =   0
  81.    End
  82. Attribute VB_Name = "ViewFrm"
  83. Attribute VB_GlobalNameSpace = False
  84. Attribute VB_Creatable = False
  85. Attribute VB_PredeclaredId = True
  86. Attribute VB_Exposed = False
  87. 'Windows functions
  88. #If Win32 Then
  89. Private Type POINTAPI
  90.         x As Long
  91.         y As Long
  92. End Type
  93. Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
  94. Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
  95. Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
  96. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  97. Private Declare Function GetROP2 Lib "gdi32" (ByVal hdc As Long) As Long
  98. Private Declare Function SetROP2 Lib "gdi32" (ByVal hdc As Long, ByVal nDrawMode As Long) As Long
  99. 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
  100. Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
  101. Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
  102. 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
  103. #Else
  104. Private Declare Function GetDC Lib "User" (ByVal hWnd As Integer) As Integer
  105. Private Declare Function ReleaseDC Lib "User" (ByVal hWnd As Integer, ByVal hdc As Integer) As Integer
  106. Private Declare Function CreatePen Lib "GDI" (ByVal nPenStyle As Integer, ByVal nWidth As Integer, ByVal crColor As Long) As Integer
  107. Private Declare Function GetStockObject Lib "GDI" (ByVal nIndex As Integer) As Integer
  108. Private Declare Function SelectObject Lib "GDI" (ByVal hdc As Integer, ByVal hObject As Integer) As Integer
  109. Private Declare Function DeleteObject Lib "GDI" (ByVal hObject As Integer) As Integer
  110. Private Declare Function GetROP2 Lib "GDI" (ByVal hdc As Integer) As Integer
  111. Private Declare Function SetROP2 Lib "GDI" (ByVal hdc As Integer, ByVal nDrawMode As Integer) As Integer
  112. Private Declare Function Ellipse Lib "GDI" (ByVal hdc As Integer, ByVal X1 As Integer, ByVal Y1 As Integer, ByVal X2 As Integer, ByVal Y2 As Integer) As Integer
  113. Private Declare Function LineTo Lib "GDI" (ByVal hdc As Integer, ByVal x As Integer, ByVal y As Integer) As Integer
  114. Private Declare Function MoveTo Lib "GDI" (ByVal hdc As Integer, ByVal x As Integer, ByVal y As Integer) As Long
  115. Private Declare Function Rectangle Lib "GDI" (ByVal hdc As Integer, ByVal X1 As Integer, ByVal Y1 As Integer, ByVal X2 As Integer, ByVal Y2 As Integer) As Integer
  116. #End If
  117. 'Windows constants
  118. Const PS_SOLID = 0
  119. Const WHITE_BRUSH = 0
  120. Const HOLLOW_BRUSH = 5
  121. Const WHITE_PEN = 6
  122. Const R2_NOT = 6
  123. Dim StartX As Integer       'Starting point for click and drag, in screen pixels
  124. Dim StartY As Integer       'Starting point for click and drag, in screen pixels
  125. Dim EndX As Integer         'Ending point for click and drag, in screen pixels
  126. Dim EndY As Integer         'Ending point for click and drag, in screen pixels
  127. Dim BStartX As Integer      'Starting point for click and drag, in bitmap pixels
  128. Dim BStartY As Integer      'Starting point for click and drag, in bitmap pixels
  129. Dim BEndX As Integer        'Ending point for click and drag, in bitmap pixels
  130. Dim BEndY As Integer        'Ending point for click and drag, in bitmap pixels
  131. Dim Drawing As Integer      'True if the mouse button is down during any drawing action
  132. Dim FirstDraw As Integer    'True for the first MouseMove event when we are drawing
  133. Public FileName As String  'The file that we load to the Lead1 control on this form
  134. Public ViewFactor As Integer   'Width of the drawing line, in bitmap pixels
  135. Public DrawObject As Integer   'Refer to the DECL module for constants
  136. Public DrawColor As Integer    'Refer to the DECL module for constants
  137. Public Sub UndoZoom()
  138.     Lead1.AutoScroll = True
  139.     Lead1.top = 0
  140.     Lead1.left = 0
  141.     Lead1.Width = ScaleWidth
  142.     Lead1.Height = ScaleHeight
  143.     Lead1.SetSrcRect 0, 0, Lead1.BitmapWidth, Lead1.BitmapHeight
  144.     Lead1.SetSrcClipRect 0, 0, Lead1.BitmapWidth, Lead1.BitmapHeight
  145.     Lead1.SetDstRect 0, 0, Lead1.BitmapWidth, Lead1.BitmapHeight
  146.     Lead1.SetDstClipRect 0, 0, Lead1.BitmapWidth, Lead1.BitmapHeight
  147.     Lead1.BackErase = True
  148. End Sub
  149. Private Sub Form_Load()
  150.   Lead1.UnlockSupport L_SUPPORT_EXPRESS, L_KEY_EXPRESS
  151.   Lead1.UnlockSupport L_SUPPORT_GIFLZW, L_KEY_GIFLZW
  152.   Lead1.UnlockSupport L_SUPPORT_TIFLZW, L_KEY_TIFLZW
  153.   Lead1.UnlockSupport L_SUPPORT_MEDICAL, L_KEY_MEDICAL
  154.   gNumChildren = gNumChildren + 1
  155.   DrawColor = COLOR_BLACK
  156.   DrawObject = OBJECT_ELLIPSE
  157.   DiffWidth = Width - ScaleWidth
  158.   DiffHeight = Height - ScaleHeight
  159.   Lead1.left = 0
  160.   Lead1.top = 0
  161.   Lead1.AutoScroll = True
  162.   Lead1.AutoRepaint = True
  163.   Lead1.BackErase = True
  164.   If gNumChildren = 1 Then
  165.     Main.SaveFile(2).Enabled = True
  166.     Main.MenuObject.Enabled = True
  167.     Main.MenuColor.Enabled = True
  168.     Main.MenuThickness.Enabled = True
  169.     Main.MenuDraw.Enabled = True
  170.     Main.MenuWindow.Enabled = True
  171.   End If
  172. End Sub
  173. Private Sub Form_Resize()
  174.     Lead1.Width = Width - DiffWidth
  175.     If Height >= DiffHeight Then
  176.         Lead1.Height = Height - DiffHeight
  177.     Else
  178.         Lead1.Height = 0
  179.     End If
  180. End Sub
  181. Private Sub Form_Unload(Cancel As Integer)
  182.   gNumChildren = gNumChildren - 1
  183.   If gNumChildren = 0 Then
  184.     Main.SaveFile(2).Enabled = False
  185.     Main.MenuObject.Enabled = False
  186.     Main.MenuColor.Enabled = False
  187.     Main.MenuThickness.Enabled = False
  188.     Main.MenuDraw.Enabled = False
  189.     Main.MenuWindow.Enabled = False
  190.   End If
  191.   Lead1.Bitmap = 0
  192.   Lead2.Bitmap = 0
  193. End Sub
  194. Private Sub Lead1_Change()
  195.     If Lead1.Bitmap <> 0 And DrawMenu = "Disabled" Then
  196.         SaveMode = Lead1.ScaleMode
  197.         Lead1.ScaleMode = 3 'Pixels
  198.         Caption = FileName + "  (" + CStr(Lead1.BitmapWidth) + " x " + CStr(Lead1.BitmapHeight) + " - " + CStr(Lead1.BitmapBits) + " BPP)"
  199.         Lead1.ScaleMode = SaveMode
  200.     End If
  201. End Sub
  202. Private Sub Lead1_GotFocus()
  203.     'Handle the situation when drawing is disabled.
  204.     If DrawMenu = "Disabled" And Lead1.Bitmap <> 0 Then
  205.         
  206.         SaveMode = Lead1.ScaleMode
  207.         Lead1.ScaleMode = 3 'Pixels
  208.         Caption = FileName + "  (" + CStr(Lead1.BitmapWidth) + " x " + CStr(Lead1.BitmapHeight) + " - " + CStr(Lead1.BitmapBits) + " BPP)"
  209.         Lead1.ScaleMode = SaveMode
  210.         
  211.         If Lead1.DstWidth <> Lead1.SrcWidth Or Lead1.DstHeight <> Lead1.SrcHeight Then
  212.             UndoZoom
  213.         End If
  214.     End If
  215. End Sub
  216. Private Sub Lead1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  217.     'Set the variables to use when specifying positions on the bitmap
  218.     If DrawMenu <> "Disabled" Then
  219.       
  220.         'Use pixels because GDI functions require that scale mode
  221.         Lead1.ScaleMode = 3
  222.         Lead2.ScaleMode = 3
  223.         
  224.         'Initialize the zoomf factors
  225.         If Lead1.Bitmap <> 0 Then
  226.             ZoomFactorX = Lead1.DstWidth / Lead1.SrcWidth
  227.             ZoomFactorY = Lead1.DstHeight / Lead1.SrcHeight
  228.         End If
  229.         
  230.         'Determine the mouse coordinates on the screen.
  231.         'These coordinates are converted to pixels for use with the GDI functions.
  232.         StartX = x / Screen.TwipsPerPixelX
  233.         StartY = y / Screen.TwipsPerPixelY
  234.                 
  235.         'Determine the mouse coordinates on the bitmap.
  236.         'These coordinates account for the zoom factor and offset.
  237.         BStartX = (StartX / ZoomFactorX) - (Lead1.DstLeft / ZoomFactorX) + Lead1.SrcLeft
  238.         BStartY = (StartY / ZoomFactorY) - (Lead1.DstTop / ZoomFactorY) + Lead1.SrcTop
  239.         
  240.         FirstDraw = True
  241.         Drawing = True
  242.         Lead1.AutoRepaint = False
  243.     End If
  244.       
  245.     'The rest of this procedure is for pasting
  246.     If DrawMenu <> "Paste" Then Exit Sub
  247.     'Get the image from the clipboard
  248.     If Lead2.Paste(PASTE_ISREADY) = 0 Then
  249.         MsgBox ("Invalid data on the clipboard")
  250.         Exit Sub
  251.     Else
  252.         Lead2.Paste 0
  253.     End If
  254.     'Set the mouse to an hourglass while pasting
  255.     Lead1.MousePointer = 11
  256.     'If Lead1 has a palette, see if the Lead2 palette matches it.
  257.     If Lead1.BitmapBits < 16 Then
  258.         If Lead2.BitmapBits > 8 Then
  259.             'Lead2 has no palette.
  260.             fMustDoColorRes = True
  261.         Else
  262.             'Check to see if the palettes match.
  263.             NoColors = 2 ^ Lead1.BitmapBits
  264.             fMustDoColorRes = False
  265.             For i = 0 To NoColors - 1
  266.                 If Lead1.BitmapPalette(i) <> Lead2.BitmapPalette(i) Then
  267.                     fMustDoColorRes = True
  268.                     Exit For
  269.                 End If
  270.             Next i
  271.         End If
  272.         'If it is not the same palette, let the user decide whether to continue.
  273.         If fMustDoColorRes = True Then
  274.             nRet = MsgBox("Palette mismatch. Convert to 24-bit?", vbYesNo)
  275.             If nRet = vbYes Then
  276.                 Lead1.ColorRes 24, CRP_BYTEORDERBGR, 0, 0
  277.                 Lead2.ColorRes 24, CRP_BYTEORDERBGR, 0, 0
  278.             Else
  279.                 Exit Sub
  280.             End If
  281.         End If
  282.     ElseIf Lead2.BitmapBits <> Lead1.BitmapBits Then
  283.         'Convert Lead2 to the same bits per pixel as Lead1 (16 or 24)
  284.         Lead2.ColorRes Lead1.BitmapBits, CRP_BYTEORDERBGR, 0, 0
  285.     End If
  286.     'Combine Lead2 with Lead1 at the current mouse position.
  287.     MyOp = CB_OP_ADD + CB_DST_0 'Operation flags for a simple paste.
  288.     Lead1.Combine BStartX, BStartY, Lead2.SrcWidth, Lead2.SrcHeight, Lead2.Bitmap, 0, 0, MyOp
  289.     'Repaint the changed portion of the bitmap
  290.     Lead1.SetSrcClipRect BStartX, BStartY, Lead2.SrcWidth, Lead2.SrcHeight
  291.     Lead1.BackErase = False
  292.     Lead1.ForceRepaint
  293.     Lead1.SetSrcClipRect Lead1.SrcLeft, Lead1.SrcTop, Lead1.SrcWidth, Lead1.SrcHeight
  294.     'Set the mouse pointer back to the default
  295.     Lead1.MousePointer = 0
  296.     Drawing = True
  297. End Sub
  298. Private Sub Lead1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  299.   Dim XPixels As Integer
  300.   Dim YPixels As Integer
  301.   Dim DisplayMode As Integer
  302. #If Win32 Then
  303.   Dim LeadDC As Long
  304.   Dim hOldPen As Long
  305.   Dim hOldBrush As Long
  306.   Dim OldPoint As POINTAPI
  307. #Else
  308.   Dim LeadDC As Integer
  309.   Dim hOldPen As Integer
  310.   Dim hOldBrush As Integer
  311. #End If
  312.   If DrawMenu = "Object" Then
  313.     Lead1.MousePointer = 2
  314.     XPixels = x / Screen.TwipsPerPixelX
  315.     YPixels = y / Screen.TwipsPerPixelY
  316.     Caption = "Mouse X = " + CStr(XPixels) + ", Mouse Y = " + CStr(YPixels)
  317.     If Button = 1 Then
  318.       LeadDC = Lead1.GetClientDC
  319.       hOldPen = SelectObject(LeadDC, GetStockObject(WHITE_PEN))
  320.       hOldBrush = SelectObject(LeadDC, GetStockObject(HOLLOW_BRUSH))
  321.       DisplayMode = GetROP2(LeadDC)
  322.       ret = SetROP2(LeadDC, R2_NOT)
  323.       Select Case DrawObject
  324.         Case OBJECT_ELLIPSE:
  325.           If FirstDraw <> True Then
  326.             ReturnVal = Ellipse(LeadDC, StartX, StartY, EndX, EndY)
  327.           End If
  328.           EndX = XPixels
  329.           EndY = YPixels
  330.           ReturnVal = Ellipse(LeadDC, StartX, StartY, EndX, EndY)
  331.         Case OBJECT_LINE:
  332.           If FirstDraw <> True Then
  333. #If Win32 Then
  334.             ReturnVal = MoveToEx(LeadDC, StartX, StartY, OldPoint)
  335. #Else
  336.             ReturnVal = MoveTo(LeadDC, StartX, StartY)
  337. #End If
  338.             ReturnVal = LineTo(LeadDC, EndX, EndY)
  339.           End If
  340.           EndX = XPixels
  341.           EndY = YPixels
  342. #If Win32 Then
  343.           ReturnVal = MoveToEx(LeadDC, StartX, StartY, OldPoint)
  344. #Else
  345.           ReturnVal = MoveTo(LeadDC, StartX, StartY)
  346. #End If
  347.           ReturnVal = LineTo(LeadDC, EndX, EndY)
  348.         Case OBJECT_RECTANGLE:
  349.           If FirstDraw <> True Then
  350.             ReturnVal = Rectangle(LeadDC, StartX, StartY, EndX, EndY)
  351.           End If
  352.           EndX = XPixels
  353.           EndY = YPixels
  354.           ReturnVal = Rectangle(LeadDC, StartX, StartY, EndX, EndY)
  355.       End Select
  356.       FirstDraw = False
  357.       ret = SetROP2(LeadDC, DisplayMode)
  358.       Lead1.ReleaseClientDC
  359.     End If
  360.   ElseIf DrawMenu = "Copy" Or DrawMenu = "ZoomIn" Then
  361.     Lead1.MousePointer = 2
  362.     XPixels = x / Screen.TwipsPerPixelX
  363.     YPixels = y / Screen.TwipsPerPixelY
  364.     Caption = "Mouse X = " + CStr(XPixels) + ", Mouse Y = " + CStr(YPixels)
  365.     If Button = 1 Then
  366.         If XPixels >= StartX Then
  367.             rbX = StartX
  368.         Else
  369.             rbX = XPixels
  370.         End If
  371.         If YPixels >= StartY Then
  372.             rbY = StartY
  373.         Else
  374.             rbY = YPixels
  375.         End If
  376.         rbWidth = Abs(StartX - XPixels)
  377.         rbHeight = Abs(StartY - YPixels)
  378.         Lead1.SetRubberBandRect rbX, rbY, rbWidth, rbHeight
  379.         Lead1.RubberBandVisible = True
  380.     End If
  381.   ElseIf DrawMenu = "Paste" Then
  382.     Lead1.MousePointer = 10
  383.     XPixels = x / Screen.TwipsPerPixelX
  384.     YPixels = y / Screen.TwipsPerPixelY
  385.     Caption = "Mouse X = " + CStr(XPixels) + ", Mouse Y = " + CStr(YPixels)
  386.   Else
  387.     Lead1.MousePointer = DEFAULT
  388.   End If
  389. End Sub
  390. Private Sub Lead1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  391.   Dim ColorRGB As Long
  392. #If Win32 Then
  393.   Dim hPen As Long
  394.   Dim hBrush As Long
  395.   Dim hOldBitmapPen As Long
  396.   Dim hOldBitmapBrush As Long
  397.   Dim hOldClientPen As Long
  398.   Dim hOldClientBrush As Long
  399.   Dim hOldclientpalette As Long
  400.   Dim hLeadPalette As Long
  401.   Dim OldPoint As POINTAPI
  402. #Else
  403.   Dim hPen As Integer
  404.   Dim hBrush As Integer
  405.   Dim hOldBitmapPen As Integer
  406.   Dim hOldBitmapBrush As Integer
  407.   Dim hOldClientPen As Integer
  408.   Dim hOldClientBrush As Integer
  409.   Dim hOldclientpalette As Integer
  410.   Dim hLeadPalette As Integer
  411. #End If
  412. If Drawing = True Then
  413.     EndX = x / Screen.TwipsPerPixelX
  414.     EndY = y / Screen.TwipsPerPixelY
  415.     'These coordinates account for the zoom factor and offset.
  416.     BEndX = (EndX / ZoomFactorX) - (Lead1.DstLeft / ZoomFactorX) + Lead1.SrcLeft
  417.     BEndY = (EndY / ZoomFactorY) - (Lead1.DstTop / ZoomFactorY) + Lead1.SrcTop
  418.   Lead1.AutoRepaint = True
  419.   If DrawMenu = "Object" Then
  420.     Select Case DrawColor
  421.       Case COLOR_BLACK
  422.         ColorRGB = RGB(0, 0, 0)
  423.       Case COLOR_BLUE
  424.         ColorRGB = RGB(0, 0, 255)
  425.       Case COLOR_GREEN
  426.         ColorRGB = RGB(0, 255, 0)
  427.       Case COLOR_RED
  428.         ColorRGB = RGB(255, 0, 0)
  429.       Case COLOR_WHITE
  430.         ColorRGB = RGB(255, 255, 255)
  431.     End Select
  432.     LeadBitmapDC = Lead1.GetBitmapDC
  433.     hPen = CreatePen(PS_SOLID, ViewFactor, ColorRGB)
  434.     hOldBitmapPen = SelectObject(LeadBitmapDC, hPen)
  435.     hOldBitmapBrush = SelectObject(LeadBitmapDC, GetStockObject(HOLLOW_BRUSH))
  436.     Select Case DrawObject
  437.       Case OBJECT_ELLIPSE:
  438.         ReturnVal = Ellipse(LeadBitmapDC, BStartX, BStartY, BEndX, BEndY)
  439.       Case OBJECT_LINE:
  440. #If Win32 Then
  441.         ReturnVal = MoveToEx(LeadBitmapDC, BStartX, BStartY, OldPoint)
  442. #Else
  443.         ReturnVal = MoveTo(LeadBitmapDC, BStartX, BStartY)
  444. #End If
  445.         ReturnVal = LineTo(LeadBitmapDC, BEndX, BEndY)
  446.       Case OBJECT_RECTANGLE:
  447.         ReturnVal = Rectangle(LeadBitmapDC, BStartX, BStartY, BEndX, BEndY)
  448.     End Select
  449.     SelectObject LeadBitmapDC, hOldBitmapPen
  450.     SelectObject LeadBitmapDC, hOldBitmapBrush
  451.     StartDraw = False
  452.     Lead1.ReleaseBitmapDC
  453.     hOldPen = DeleteObject(hPen)
  454.     Lead1.BackErase = False ' this forces a repaint
  455.   ElseIf DrawMenu = "Copy" Then
  456.     Lead1.MousePointer = 11
  457.     'Get rid of the rectangle.
  458.     Lead1.RubberBandVisible = False
  459.     'Get the width and height of the selected area in bitmap pixels.
  460.     CropWidth = Abs(BEndX - BStartX)
  461.     CropHeight = Abs(BEndY - BStartY)
  462.     'We need at least one pixel.
  463.     If CropWidth < 1 Or CropHeight < 1 Then
  464.         Exit Sub
  465.     End If
  466.     'Create the Lead2 bitmap and load its palette if necessary.
  467.     Lead2.CreateBitmap CropWidth, CropHeight, Lead1.BitmapBits
  468.     If Lead1.BitmapBits < 16 Then
  469.         NoColors = 2 ^ Lead1.BitmapBits
  470.         For i = 0 To NoColors - 1
  471.             Lead2.BitmapPalette(i) = Lead1.BitmapPalette(i)
  472.         Next
  473.     End If
  474.     Lead2.Fill RGB(0, 0, 0)
  475.     'Find the top left corner of the selected rectangle.
  476.     If BStartX < BEndX Then
  477.         xSrc = BStartX
  478.     Else
  479.         xSrc = BEndX
  480.     End If
  481.     If BStartY < BEndY Then
  482.         ySrc = BStartY
  483.     Else
  484.         ySrc = BEndY
  485.     End If
  486.     'Use the Combine method to copy the selected rectangle to Lead2.
  487.     MyOp = CB_OP_ADD + CB_DST_0 'Operation flags for a simple paste.
  488.     Lead2.Combine 0, 0, CropWidth, CropHeight, Lead1.Bitmap, xSrc, ySrc, MyOp
  489.     ' Copy the second bitmap to the clipboard
  490.     Lead2.Copy COPY_DIB
  491.     'Change next option to paste
  492.     DrawMenu = "Paste"
  493.     Main.EnableSelect(2).CHECKED = False
  494.     Main.EnableSelect(3).CHECKED = True
  495.     Lead1.MousePointer = 0
  496.   ElseIf DrawMenu = "ZoomIn" Then
  497.     'Simplify by making sure all measurements are in the same mode.
  498.     SaveMode = ScaleMode
  499.     ScaleMode = Lead1.ScaleMode
  500.     'Get the origin of the rubberband rectangle.
  501.     'Allow for different mouse drag directions
  502.     If BStartX < BEndX Then
  503.         CropLeft = BStartX
  504.     Else
  505.        CropLeft = BEndX
  506.     End If
  507.     If BStartY < BEndY Then
  508.         CropTop = BStartY
  509.     Else
  510.        CropTop = BEndY
  511.     End If
  512.     'Get the height and width of the cropped area
  513.     CropWidth = Abs(BEndX - BStartX)
  514.     CropHeight = Abs(BEndY - BStartY)
  515.     If CropWidth < 1 Or CropHeight < 1 Then
  516.         Lead1.RubberBandVisible = False
  517.         Lead1.BackErase = False ' this forces a repaint
  518.         StartDraw = False
  519.         Exit Sub
  520.     End If
  521.     'Size and redisplay the control, using the new source rectangle.
  522.     'Set the variables used for preserving the aspect ratio.
  523.     HeightFactor = CropHeight
  524.     WidthFactor = CropWidth
  525.     HeightAllowed = ScaleHeight
  526.     WidthAllowed = ScaleWidth
  527.     ' Hide the Lead control while we change its size and position.
  528.     Lead1.Visible = False
  529.     'Center the LEAD control on the form, preserving the aspect ratio.
  530.     'Check to see if using the maximum width will make the image too tall.
  531.     'Set the dimensions based on the result.
  532.     If ((WidthAllowed * HeightFactor) / WidthFactor) <= HeightAllowed Then
  533.       Lead1.left = 0
  534.       Lead1.Width = WidthAllowed
  535.       Lead1.Height = (Lead1.ScaleWidth * HeightFactor) / WidthFactor
  536.       Lead1.top = (ScaleHeight - Lead1.ScaleHeight) / 2
  537.     Else
  538.       Lead1.top = 0
  539.       Lead1.Height = HeightAllowed
  540.       Lead1.Width = (Lead1.ScaleHeight * WidthFactor) / HeightFactor
  541.       Lead1.left = (ScaleWidth - Lead1.ScaleWidth) / 2
  542.     End If
  543.     'Turn off scroll bars to make sure we use the full client area.
  544.     Lead1.AutoScroll = False
  545.     'Zoom in on the source rectangle
  546.     Lead1.SetSrcRect CropLeft, CropTop, CropWidth, CropHeight
  547.     Lead1.SetSrcClipRect CropLeft, CropTop, CropWidth, CropHeight
  548.     'Set the image display size to match the LEAD control
  549.     Lead1.SetDstRect 0, 0, Lead1.ScaleWidth, Lead1.ScaleHeight
  550.     Lead1.SetDstClipRect 0, 0, Lead1.ScaleWidth, Lead1.ScaleHeight
  551.     'Set defaults
  552.     Lead1.RubberBandVisible = False
  553.     Lead1.MousePointer = 0 'Default
  554.     ' Display the Lead control
  555.     Lead1.Visible = True
  556.     Lead1.ForceRepaint
  557.     'Return the form's scalemode to the saved value
  558.     ScaleMode = SaveMode
  559.     Lead1.ScaleMode = SavedMode
  560.   End If
  561. End If
  562. End Sub
  563.