home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Advanced_S656403262002.psc / Source / VB / ScreenRipper / CaptureRectangle.frm (.txt) next >
Encoding:
Visual Basic Form  |  2002-03-21  |  8.4 KB  |  294 lines

  1. VERSION 5.00
  2. Begin VB.Form frmCaptureRectangle 
  3.    Appearance      =   0  'Flat
  4.    BorderStyle     =   0  'None
  5.    ClientHeight    =   5475
  6.    ClientLeft      =   0
  7.    ClientTop       =   105
  8.    ClientWidth     =   6825
  9.    ControlBox      =   0   'False
  10.    LinkTopic       =   "Form1"
  11.    MousePointer    =   2  'Cross
  12.    ScaleHeight     =   365
  13.    ScaleMode       =   3  'Pixel
  14.    ScaleWidth      =   455
  15.    ShowInTaskbar   =   0   'False
  16.    StartUpPosition =   2  'CenterScreen
  17.    Begin VB.PictureBox picRectangle 
  18.       Appearance      =   0  'Flat
  19.       AutoRedraw      =   -1  'True
  20.       BackColor       =   &H80000005&
  21.       BorderStyle     =   0  'None
  22.       ForeColor       =   &H80000008&
  23.       Height          =   855
  24.       Left            =   2475
  25.       ScaleHeight     =   57
  26.       ScaleMode       =   3  'Pixel
  27.       ScaleWidth      =   97
  28.       TabIndex        =   1
  29.       Top             =   3900
  30.       Visible         =   0   'False
  31.       Width           =   1455
  32.    End
  33.    Begin VB.PictureBox Picture1 
  34.       AutoRedraw      =   -1  'True
  35.       Height          =   3165
  36.       Left            =   0
  37.       MousePointer    =   2  'Cross
  38.       ScaleHeight     =   207
  39.       ScaleMode       =   3  'Pixel
  40.       ScaleWidth      =   448
  41.       TabIndex        =   0
  42.       Top             =   -15
  43.       Width           =   6780
  44.       Begin VB.Line Line4 
  45.          BorderStyle     =   3  'Dot
  46.          Visible         =   0   'False
  47.          X1              =   248
  48.          X2              =   248
  49.          Y1              =   56
  50.          Y2              =   112
  51.       End
  52.       Begin VB.Line Line3 
  53.          BorderStyle     =   3  'Dot
  54.          Visible         =   0   'False
  55.          X1              =   168
  56.          X2              =   240
  57.          Y1              =   120
  58.          Y2              =   120
  59.       End
  60.       Begin VB.Line Line2 
  61.          BorderStyle     =   3  'Dot
  62.          Visible         =   0   'False
  63.          X1              =   152
  64.          X2              =   152
  65.          Y1              =   56
  66.          Y2              =   112
  67.       End
  68.       Begin VB.Line Line1 
  69.          BorderStyle     =   3  'Dot
  70.          Visible         =   0   'False
  71.          X1              =   160
  72.          X2              =   240
  73.          Y1              =   48
  74.          Y2              =   48
  75.       End
  76.    End
  77. Attribute VB_Name = "frmCaptureRectangle"
  78. Attribute VB_GlobalNameSpace = False
  79. Attribute VB_Creatable = False
  80. Attribute VB_PredeclaredId = True
  81. Attribute VB_Exposed = False
  82. Option Explicit
  83. Private mbDown As Boolean
  84. Private nOldX As Integer
  85. Private nOldY As Integer
  86. Private Sub Form_DblClick()
  87.     Unload Me
  88. End Sub
  89. Private Sub Form_Load()
  90.     '--- Set up the Snap Form to the size of the
  91.     '--- Whole Screen capture we did when we choose
  92.     '--- to Get the Rectangular area Capture.
  93.     '--- The "-2" offset prevents the screen from shifting
  94.     '--- slightly when switchting to display screen capture image.
  95.     With Me
  96.         .Left = -2
  97.         .Top = -2
  98.         .Width = Screen.Width + 2
  99.         .Height = Screen.Height + 2
  100.     End With
  101.     With Picture1
  102.         .Left = -2
  103.         .Top = -2
  104.         .Height = Me.Height
  105.         .Width = Me.Width
  106.     End With
  107. End Sub
  108. Public Sub ShowPicture(picBitmap As Variant)
  109.     '--- Load the Screen that was Captured into Picture Box
  110.     Load Me
  111.     DoEvents
  112.     Picture1.Picture = picBitmap
  113.     Me.Show
  114.     mbDown = False
  115. End Sub
  116. Private Sub Form_Unload(Cancel As Integer)
  117.     frmScreenCapture.Show
  118. End Sub
  119. Private Sub Picture1_DblClick()
  120.     Unload Me
  121. End Sub
  122. Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  123. '--- This where we set the Begainning of the Box
  124. '--- that will be Drawn around the Capture Area
  125.     mbDown = (Button = 1)
  126.     With Line1
  127.         .X1 = X
  128.         .X2 = X
  129.         .Y1 = Y
  130.         .Y2 = Y
  131.     End With
  132.         
  133.     With Line2
  134.         .X1 = X
  135.         .X2 = X
  136.         .Y1 = Y
  137.         .Y2 = Y
  138.     End With
  139.         
  140.     With Line3
  141.         .X1 = X
  142.         .X2 = X
  143.         .Y1 = Y
  144.         .Y2 = Y
  145.     End With
  146.         
  147.     With Line4
  148.         .X1 = X
  149.         .X2 = X
  150.         .Y1 = Y
  151.         .Y2 = Y
  152.     End With
  153.         
  154.     Line1.Visible = True
  155.     Line2.Visible = True
  156.     Line3.Visible = True
  157.     Line4.Visible = True
  158.     nOldX = X
  159.     nOldY = Y
  160. End Sub
  161. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  162. '--- Where we Draw the Box around the Choosen Area as you hold down the Left Mouse
  163. '--- button and Drag in any direction to create a rectangle
  164.     If mbDown Then
  165.         With Line1
  166.             .X1 = nOldX
  167.             .X2 = X
  168.             .Y1 = nOldY
  169.             .Y2 = nOldY
  170.         End With
  171.         
  172.         With Line2
  173.             .X1 = nOldX
  174.             .X2 = nOldX
  175.             .Y1 = nOldY
  176.             .Y2 = Y
  177.         End With
  178.         
  179.         With Line3
  180.             .X1 = X
  181.             .X2 = X
  182.             .Y1 = nOldY
  183.             .Y2 = Y
  184.         End With
  185.         
  186.         With Line4
  187.             .X1 = nOldX
  188.             .X2 = X
  189.             .Y1 = Y
  190.             .Y2 = Y
  191.         End With
  192.     End If
  193. End Sub
  194. Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  195.     On Error Resume Next
  196.     Dim XUpperLeft As Long
  197.     Dim YUpperLeft As Long
  198.     Dim XLowerRight As Long
  199.     Dim YLowerRight As Long
  200.     '--- Determine the upper left hand corner & lower right hand corner
  201.     '--- XY coordinates.  By doing this, it doesn't matter which
  202.     '--- direction the user "dragged" the rectangle:
  203.     XUpperLeft = Line1.X1
  204.     If Line1.X2 < XUpperLeft Then
  205.         XUpperLeft = Line1.X2
  206.     End If
  207.     With Line2
  208.         If .X1 < XUpperLeft Then
  209.             XUpperLeft = .X1
  210.         End If
  211.         If .X2 < XUpperLeft Then
  212.             XUpperLeft = .X2
  213.         End If
  214.     End With
  215.     YUpperLeft = Line1.Y1
  216.     If Line1.Y2 < YUpperLeft Then
  217.         YUpperLeft = Line1.Y2
  218.     End If
  219.     With Line2
  220.         If .Y1 < YUpperLeft Then
  221.             YUpperLeft = .Y1
  222.         End If
  223.         If .Y2 < YUpperLeft Then
  224.             YUpperLeft = .Y2
  225.         End If
  226.     End With
  227.     XLowerRight = Line1.X1
  228.     If Line1.X2 > XLowerRight Then
  229.         XLowerRight = Line1.X2
  230.     End If
  231.     With Line2
  232.         If .X1 > XLowerRight Then
  233.             XLowerRight = .X1
  234.         End If
  235.         If .X2 > XLowerRight Then
  236.             XLowerRight = .X2
  237.         End If
  238.     End With
  239.     YLowerRight = Line1.Y1
  240.     If Line1.Y2 > YLowerRight Then
  241.         YLowerRight = Line1.Y2
  242.     End If
  243.     With Line2
  244.         If .Y1 > YLowerRight Then
  245.             YLowerRight = .Y1
  246.         End If
  247.         If .Y2 > YLowerRight Then
  248.             YLowerRight = .Y2
  249.         End If
  250.     End With
  251.     '--- Selected a single pixel (clicked, no drag)
  252.     If XUpperLeft = XLowerRight Then XLowerRight = XLowerRight + 1
  253.     If YUpperLeft = YLowerRight Then YLowerRight = YLowerRight + 1
  254.     '--- Set the picRectangle to the size
  255.     '--- we will paint the Image to
  256.     With picRectangle
  257.         .Picture = LoadPicture()
  258.         .Cls
  259.         DoEvents
  260.         .Width = Abs(Line1.X2 - Line1.X1)
  261.         .Height = Abs(Line2.Y2 - Line2.Y1)
  262.         '--- Paint the Captured part of the screen to
  263.         '--- form3 Picture1
  264.         .PaintPicture Picture1, 0, 0, _
  265.             XLowerRight - XUpperLeft, _
  266.             YLowerRight - YUpperLeft, _
  267.             XUpperLeft, YUpperLeft, _
  268.             XLowerRight - XUpperLeft, _
  269.             YLowerRight - YUpperLeft ', opcode
  270.             
  271.         '--- IMPORTANT: DO NOT REMOVE THIS DoEvents! Windows needs to "catchup"
  272.         '--- before can use the "painted" picture.
  273.         DoEvents
  274.         mbDown = False
  275.     End With
  276.     '--- Put picture image back in calling form and show it
  277.     With frmScreenCapture
  278.         '--- Load selected rectangle image into picture box:
  279.         With .Picture2
  280.             '--- Just to be safe, clear picture before
  281.             '--- loading new image:
  282.             .Picture = LoadPicture()
  283.             .Cls
  284.             .Picture = picRectangle.Image
  285.         End With
  286.         '--- Show frmScreenCapture with the Captured Image
  287.         '--- in frmScreenCapture.Picture2
  288.         .Show
  289.         
  290.         '--- unload frmCaptureRectangle
  291.         Unload Me
  292.     End With
  293. End Sub
  294.