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 / ScreenCapture.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2002-03-26  |  30.1 KB  |  859 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "Comdlg32.ocx"
  4. Begin VB.Form frmScreenCapture 
  5.    AutoRedraw      =   -1  'True
  6.    Caption         =   "Advanced Print Screen Utility"
  7.    ClientHeight    =   5160
  8.    ClientLeft      =   120
  9.    ClientTop       =   120
  10.    ClientWidth     =   7980
  11.    Icon            =   "ScreenCapture.frx":0000
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   5160
  14.    ScaleWidth      =   7980
  15.    StartUpPosition =   2  'CenterScreen
  16.    Begin VB.PictureBox picRectangle 
  17.       Appearance      =   0  'Flat
  18.       AutoRedraw      =   -1  'True
  19.       AutoSize        =   -1  'True
  20.       BackColor       =   &H80000005&
  21.       BorderStyle     =   0  'None
  22.       ForeColor       =   &H80000008&
  23.       Height          =   855
  24.       Left            =   5955
  25.       ScaleHeight     =   57
  26.       ScaleMode       =   3  'Pixel
  27.       ScaleWidth      =   97
  28.       TabIndex        =   5
  29.       Top             =   600
  30.       Visible         =   0   'False
  31.       Width           =   1455
  32.    End
  33.    Begin VB.HScrollBar HScroll1 
  34.       Height          =   255
  35.       Left            =   120
  36.       TabIndex        =   3
  37.       Top             =   4800
  38.       Visible         =   0   'False
  39.       Width           =   7500
  40.    End
  41.    Begin VB.VScrollBar VScroll1 
  42.       Height          =   4335
  43.       Left            =   7650
  44.       TabIndex        =   2
  45.       Top             =   420
  46.       Visible         =   0   'False
  47.       Width           =   255
  48.    End
  49.    Begin MSComctlLib.ImageList ImageList1 
  50.       Left            =   4320
  51.       Top             =   780
  52.       _ExtentX        =   1005
  53.       _ExtentY        =   1005
  54.       BackColor       =   -2147483643
  55.       ImageWidth      =   16
  56.       ImageHeight     =   16
  57.       MaskColor       =   12632256
  58.       _Version        =   393216
  59.       BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
  60.          NumListImages   =   11
  61.          BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  62.             Picture         =   "ScreenCapture.frx":0442
  63.             Key             =   ""
  64.             Object.Tag             =   "Exit"
  65.          EndProperty
  66.          BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  67.             Picture         =   "ScreenCapture.frx":089E
  68.             Key             =   ""
  69.             Object.Tag             =   "Open"
  70.          EndProperty
  71.          BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  72.             Picture         =   "ScreenCapture.frx":0CF2
  73.             Key             =   ""
  74.             Object.Tag             =   "Save"
  75.          EndProperty
  76.          BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  77.             Picture         =   "ScreenCapture.frx":1146
  78.             Key             =   ""
  79.             Object.Tag             =   "Capture Rectangle"
  80.          EndProperty
  81.          BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  82.             Picture         =   "ScreenCapture.frx":15D0
  83.             Key             =   ""
  84.             Object.Tag             =   "Capture Full Screen"
  85.          EndProperty
  86.          BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  87.             Picture         =   "ScreenCapture.frx":1A24
  88.             Key             =   ""
  89.             Object.Tag             =   "About"
  90.          EndProperty
  91.          BeginProperty ListImage7 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  92.             Picture         =   "ScreenCapture.frx":1E78
  93.             Key             =   ""
  94.             Object.Tag             =   "Print image"
  95.          EndProperty
  96.          BeginProperty ListImage8 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  97.             Picture         =   "ScreenCapture.frx":238A
  98.             Key             =   ""
  99.          EndProperty
  100.          BeginProperty ListImage9 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  101.             Picture         =   "ScreenCapture.frx":271C
  102.             Key             =   ""
  103.             Object.Tag             =   "CopyToClipboard"
  104.          EndProperty
  105.          BeginProperty ListImage10 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  106.             Picture         =   "ScreenCapture.frx":2AEE
  107.             Key             =   ""
  108.          EndProperty
  109.          BeginProperty ListImage11 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  110.             Picture         =   "ScreenCapture.frx":2EF8
  111.             Key             =   ""
  112.             Object.Tag             =   "Crop"
  113.          EndProperty
  114.       EndProperty
  115.    End
  116.    Begin VB.PictureBox Picture1 
  117.       AutoRedraw      =   -1  'True
  118.       BackColor       =   &H00808080&
  119.       ForeColor       =   &H00808080&
  120.       Height          =   4335
  121.       Left            =   105
  122.       ScaleHeight     =   285
  123.       ScaleMode       =   3  'Pixel
  124.       ScaleWidth      =   497
  125.       TabIndex        =   1
  126.       Top             =   450
  127.       Width           =   7515
  128.       Begin MSComDlg.CommonDialog CD1 
  129.          Left            =   5130
  130.          Top             =   315
  131.          _ExtentX        =   847
  132.          _ExtentY        =   847
  133.          _Version        =   393216
  134.       End
  135.       Begin VB.PictureBox Picture2 
  136.          Appearance      =   0  'Flat
  137.          AutoRedraw      =   -1  'True
  138.          AutoSize        =   -1  'True
  139.          BackColor       =   &H80000005&
  140.          BorderStyle     =   0  'None
  141.          ForeColor       =   &H80000008&
  142.          Height          =   1995
  143.          Left            =   0
  144.          ScaleHeight     =   133
  145.          ScaleMode       =   3  'Pixel
  146.          ScaleWidth      =   151
  147.          TabIndex        =   4
  148.          Top             =   0
  149.          Width           =   2265
  150.          Begin VB.Line Line1 
  151.             BorderStyle     =   3  'Dot
  152.             Visible         =   0   'False
  153.             X1              =   37
  154.             X2              =   117
  155.             Y1              =   30
  156.             Y2              =   30
  157.          End
  158.          Begin VB.Line Line2 
  159.             BorderStyle     =   3  'Dot
  160.             Visible         =   0   'False
  161.             X1              =   29
  162.             X2              =   29
  163.             Y1              =   38
  164.             Y2              =   94
  165.          End
  166.          Begin VB.Line Line3 
  167.             BorderStyle     =   3  'Dot
  168.             Visible         =   0   'False
  169.             X1              =   45
  170.             X2              =   117
  171.             Y1              =   102
  172.             Y2              =   102
  173.          End
  174.          Begin VB.Line Line4 
  175.             BorderStyle     =   3  'Dot
  176.             Visible         =   0   'False
  177.             X1              =   125
  178.             X2              =   125
  179.             Y1              =   38
  180.             Y2              =   94
  181.          End
  182.       End
  183.    End
  184.    Begin MSComctlLib.Toolbar Toolbar1 
  185.       Align           =   1  'Align Top
  186.       Height          =   420
  187.       Left            =   0
  188.       TabIndex        =   0
  189.       Top             =   0
  190.       Width           =   7980
  191.       _ExtentX        =   14076
  192.       _ExtentY        =   741
  193.       ButtonWidth     =   609
  194.       ButtonHeight    =   582
  195.       Appearance      =   1
  196.       ImageList       =   "ImageList1"
  197.       _Version        =   393216
  198.       BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628} 
  199.          NumButtons      =   13
  200.          BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  201.             Style           =   4
  202.          EndProperty
  203.          BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  204.             Key             =   "Exit"
  205.             Object.ToolTipText     =   "Exit Program"
  206.             ImageIndex      =   1
  207.          EndProperty
  208.          BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  209.             Key             =   "Open"
  210.             Object.ToolTipText     =   "Open a new Image."
  211.             ImageIndex      =   2
  212.          EndProperty
  213.          BeginProperty Button4 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  214.             Key             =   "SaveIt"
  215.             Object.ToolTipText     =   "Save Image As"
  216.             ImageIndex      =   3
  217.          EndProperty
  218.          BeginProperty Button5 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  219.             Style           =   4
  220.          EndProperty
  221.          BeginProperty Button6 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  222.             Key             =   "Capture1"
  223.             Object.ToolTipText     =   "Capture Rectangular Area"
  224.             ImageIndex      =   4
  225.          EndProperty
  226.          BeginProperty Button7 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  227.             Key             =   "Capture2"
  228.             Object.ToolTipText     =   "Capture Full Screen"
  229.             ImageIndex      =   5
  230.          EndProperty
  231.          BeginProperty Button8 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  232.             Style           =   4
  233.          EndProperty
  234.          BeginProperty Button9 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  235.             Key             =   "Print"
  236.             Object.ToolTipText     =   "Print Image"
  237.             ImageIndex      =   8
  238.          EndProperty
  239.          BeginProperty Button10 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  240.             Key             =   "Copy"
  241.             Object.ToolTipText     =   "Copy Image to Clipboard"
  242.             ImageIndex      =   9
  243.          EndProperty
  244.          BeginProperty Button11 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  245.             Key             =   "Crop"
  246.             Object.ToolTipText     =   "Select area to crop"
  247.             ImageIndex      =   11
  248.          EndProperty
  249.          BeginProperty Button12 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  250.             Style           =   4
  251.          EndProperty
  252.          BeginProperty Button13 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  253.             Key             =   "About"
  254.             Object.ToolTipText     =   "About Screen Ripper"
  255.             ImageIndex      =   6
  256.          EndProperty
  257.       EndProperty
  258.    End
  259.    Begin VB.Menu mnuFile 
  260.       Caption         =   "&File"
  261.       Begin VB.Menu mnuOpen 
  262.          Caption         =   "&Open"
  263.       End
  264.       Begin VB.Menu mnuSave 
  265.          Caption         =   "Save &As"
  266.       End
  267.       Begin VB.Menu mnBB 
  268.          Caption         =   "-"
  269.       End
  270.       Begin VB.Menu mnuPrint 
  271.          Caption         =   "&Print"
  272.       End
  273.       Begin VB.Menu mnuAA 
  274.          Caption         =   "-"
  275.       End
  276.       Begin VB.Menu mnuExit 
  277.          Caption         =   "E&xit"
  278.       End
  279.    End
  280.    Begin VB.Menu mnuEdit 
  281.       Caption         =   "&Edit"
  282.       Begin VB.Menu mnuCrop 
  283.          Caption         =   "Select Crop &Area"
  284.       End
  285.       Begin VB.Menu mnuCopy 
  286.          Caption         =   "&Copy Image to Clipboard"
  287.       End
  288.    End
  289.    Begin VB.Menu mnuB 
  290.       Caption         =   "&Capture"
  291.       Begin VB.Menu mnuRectangle 
  292.          Caption         =   "Capture &Rectangular Area"
  293.       End
  294.       Begin VB.Menu mnuFullScreen 
  295.          Caption         =   "Capture Full &Screen"
  296.       End
  297.    End
  298.    Begin VB.Menu mnuC 
  299.       Caption         =   "&About"
  300.       Begin VB.Menu mnuAbout 
  301.          Caption         =   "About"
  302.       End
  303.    End
  304. Attribute VB_Name = "frmScreenCapture"
  305. Attribute VB_GlobalNameSpace = False
  306. Attribute VB_Creatable = False
  307. Attribute VB_PredeclaredId = True
  308. Attribute VB_Exposed = False
  309. Option Explicit
  310. '--- Original concept and design by Bob "Real Redneck" Davis (adavis354@comcast.net).
  311. '--- Enhancements by Gary Choma (gchoma@hotmail.com).
  312. '--- Special thanks to www.planet-source-code.com!
  313. '--- If you can make this program better, your welcome to do so...
  314. '--- ...and please then share it!
  315. Private mbCrop As Boolean
  316. Private mbDown As Boolean
  317. Private nOldX As Integer
  318. Private nOldY As Integer
  319. '--- Printscreen API declaration:
  320. Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
  321. Private Function CaptureDesktop() As Boolean
  322. '--- This where the Screen gets Captured
  323. '--- Captures screenshot image and puts it in Picture2.Picture
  324.     Dim mvContents As Variant
  325.     Dim mnClpFmt As Integer
  326.     Dim i As Long
  327.     Dim nErrorCount As Long
  328.     Dim nXpos As Long
  329.     On Error Resume Next
  330.     '--- Hide the FrmMain so that it will not
  331.     '--- be included in the Screen Capture
  332.     '--- NOTE: It seems sometimes that when Windows gets bogged down,
  333.     '--- it "captures" a ghost of frmScreenCapture because it didn't fully
  334.     '--- hide it.  Here are some attempts to avoid that:
  335.     '--- To make sure this form is not included in screencapture, let's
  336.     '--- hide it AND move it off to the left of the screen, then move it
  337.     '--- back and show it.
  338.     nXpos = Me.Left
  339.     Me.Move (Me.Left + Screen.Width), Me.Height
  340.     DoEvents
  341.     '--- Need to issue a .Hide so that focus goes to what's underneath this form.
  342.     Me.Hide
  343.     DoEvents
  344.     Me.Refresh
  345.     DoEvents
  346.     '--- Initialize variables
  347.     mnClpFmt = 0
  348.     Set mvContents = Nothing
  349.     With Clipboard
  350.         
  351.         '--- from the VB Help file:
  352.         If .GetFormat(vbCFText) Then mnClpFmt = mnClpFmt + 1
  353.         If .GetFormat(vbCFBitmap) Then mnClpFmt = mnClpFmt + 2
  354.         If .GetFormat(vbCFDIB) Then mnClpFmt = mnClpFmt + 4
  355.         If .GetFormat(vbCFRTF) Then mnClpFmt = mnClpFmt + 8
  356.         
  357.         '--- Cache current contents of clipboard:
  358.         Select Case mnClpFmt
  359.             Case 1
  360.                 'Msg = "The Clipboard contains only text."
  361.                 mvContents = .GetText(vbCFText)
  362.             Case 2, 4, 6
  363.                 'Msg = "The Clipboard contains only a bitmap."
  364.                 Set mvContents = .GetData
  365.             Case 3, 5, 7
  366.                 'Msg = "The Clipboard contains text and a bitmap."
  367.                 mvContents = .GetData(mnClpFmt)
  368.             Case 8, 9
  369.                 'Msg = "The Clipboard contains only rich text."
  370.                 mvContents = .GetText(vbCFRTF)
  371.             Case Else
  372.                 'Msg = "There is nothing on the Clipboard."
  373.         End Select
  374.         DoEvents
  375.         On Error GoTo ErrorHandler
  376.         '--- Activate Printscreen, which puts screen capture in Clipboard
  377.         Call keybd_event(vbKeySnapshot, 1, 0, 0)
  378.         '--- IMPORTANT: DoEvents are needed to give Windows a chance to
  379.         '--- "keep up / finish up".  It appears that whenever interacting
  380.         '--- programmatically with the Windows Clipboard, judicious use
  381.         '--- of DoEvents are needed surrounding those calls to allow Windows
  382.         '--- to finish processing the relatively time-intensive Clipboar work.
  383.         '--- Otherwise, the program doesn't work...no screen captures show up
  384.         '--- in the Picturebox controls!
  385.         DoEvents
  386.         Picture2.Cls '--- Actually, this seems to help with the processing timing
  387.                      '--- which the DoEvents doesn't seem to be always effective enough?
  388.         Picture2.Picture = .GetData()
  389.     End With
  390.     DoEvents
  391.     CaptureDesktop = True
  392.     '--- created from VB help file example.
  393.     On Error Resume Next
  394.     If Not IsEmpty(mvContents) Then
  395.         '--- Restore cached contents of the Windows clipboard
  396.         Select Case mnClpFmt
  397.             Case 1
  398.                 'Msg = "The Clipboard contains only text."
  399.                 Clipboard.Clear
  400.                 DoEvents
  401.                 Clipboard.SetText mvContents, vbCFText
  402.             Case 2, 4, 6
  403.                 'Msg = "The Clipboard contains only a bitmap."
  404.                 Clipboard.Clear
  405.                 DoEvents
  406.                 Clipboard.SetData mvContents
  407.             Case 3, 5, 7
  408.                 'Msg = "The Clipboard contains text and a bitmap."
  409.                 '--- Not sure if this is correct because I'm not sure how
  410.                 '--- to set both text and a bitmap into the clipboard
  411.                 Clipboard.Clear
  412.                 DoEvents
  413.                 Clipboard.SetData mvContents
  414.             Case 8, 9
  415.                 'Msg = "The Clipboard contains only rich text."
  416.                 '--- i.e. Copied text within MSWord
  417.                 Clipboard.Clear
  418.                 DoEvents
  419.                 Clipboard.SetText mvContents, vbCFRTF
  420.             Case Else
  421.                 'Msg = "There is nothing on the Clipboard."
  422.         End Select
  423.     End If
  424.     Me.Left = nXpos
  425.     Exit Function
  426. ErrorHandler:
  427.     If Err.Number = 521 Then
  428.         Err.Clear
  429.         If nErrorCount < 5 Then
  430.             nErrorCount = nErrorCount + 1
  431.             Resume
  432.         Else
  433.             If MsgBox("Couldn't open Windows Clipboard.  Try again?", vbExclamation + vbYesNo) = vbYes Then
  434.                 Resume
  435.             End If
  436.         End If
  437.     Else
  438.         MsgBox "Error number: " & Err.Number & ". " & Err.Description
  439.     End If
  440.     CaptureDesktop = False
  441.     Me.Left = nXpos
  442.     Me.Show
  443. End Function
  444. Private Sub Form_Activate()
  445.     AdjustScrollbars
  446. End Sub
  447. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  448.     Unload Me
  449. End Sub
  450. Private Sub Form_Resize()
  451.     '--- nTitleBarHeight may vary between versions/settings of Windows.
  452.     '--- for example, in WinXP, the titlebar is much thicker than in Win95.
  453.     Const nTitleBarHeight As Integer = 400
  454.     On Error Resume Next
  455.     '--- Limit how small user can resize the form:
  456.     With Me
  457.         If .Width < 3000 Then
  458.             .Width = 4000
  459.         End If
  460.         If .Height < 2000 Then
  461.             .Height = 2000
  462.         End If
  463.     End With
  464.     With Picture1
  465.         .Width = Me.Width - VScroll1.Width - 180 - Picture1.Left
  466.         .Height = Me.Height - Picture1.Top - Toolbar1.Height - HScroll1.Height - nTitleBarHeight - 30
  467.     End With
  468.     With VScroll1
  469.         .Left = Me.Width - VScroll1.Width - 150
  470.         .Height = Picture1.Height
  471.         .Top = Picture1.Top
  472.         .Value = 0
  473.     End With
  474.     With HScroll1
  475.         .Top = Me.Height - HScroll1.Height - nTitleBarHeight - 420
  476.         .Width = Picture1.Width
  477.         .Value = 0
  478.         .Left = Picture1.Left
  479.     End With
  480.     '--- Picture2 is contained within Picture1
  481.     With Picture2
  482.         .Left = 0
  483.         .Top = 0
  484.     End With
  485.     AdjustScrollbars
  486. End Sub
  487. Private Sub mnuAbout_Click()
  488. '--- The about Screen Capture Utility
  489.     Dim ms As String
  490.     ms = "Make sure screen to capture from is directly below this form" & vbCrLf
  491.     MsgBox ms, , Me.Caption
  492. End Sub
  493. Private Sub mnuCrop_Click()
  494.     Crop
  495. End Sub
  496. Private Sub mnuRectangle_Click()
  497. '--- This is where we start the Capture of
  498. '--- a choosen Rectangular Area
  499.     '--- We capture the Whole Screen even if
  500.     '--- we only want a part of it:
  501.     If CaptureDesktop Then
  502.         '--- Show the Form where all the Work will take place
  503.         DoEvents
  504.         frmCaptureRectangle.ShowPicture Picture2.Picture
  505.     End If
  506. End Sub
  507. Private Sub mnuCopy_Click()
  508.     If Picture2.Picture <> 0 Then
  509.         Clipboard.Clear
  510.         DoEvents
  511.         Clipboard.SetData Picture2.Picture
  512.         DoEvents
  513.         MsgBox "Image saved to Windows clipboard.  Use Paste or CTL+V in another application, such as Word, to paste image from clipboard.", vbInformation, "Copy Image to Clipboard"
  514.     Else
  515.         MsgBox "Please capture or load an image before copying to clipboard.", vbInformation, "Nothing To Copy"
  516.     End If
  517. End Sub
  518. Private Sub mnuExit_Click()
  519.     Unload Me
  520. End Sub
  521. Private Sub mnuOpen_Click()
  522. '--- This is where we choose a Image that is
  523. '--- already on the Disk so that is can be save
  524. '--- by the User
  525.     '--- Set the Filters
  526.     With CD1
  527.         .Filter = "GIF Files (*.gif)|*.gif|JPEG Files" & _
  528.                  "(*.jpg)|*.jpg|Bitmap Files (*.bmp)|*.bmp"
  529.         '--- Specify default filter
  530.         .FilterIndex = 2
  531.         '--- set starting Path
  532.         .InitDir = "c:\aaaaaa" 'Path1
  533.         
  534.         .Flags = cdlOFNExplorer
  535.         
  536.         '--- Show the Open Dialog
  537.         .ShowOpen
  538.         '--- If Canceled is Pressed
  539.         If .FileName = "" Then Exit Sub
  540.         '--- Load the Choosen Image to the Picture Box
  541.         Picture2.Picture = LoadPicture(.FileName)
  542.     End With
  543. End Sub
  544. Private Sub mnuPrint_Click()
  545.     If Picture2.Picture <> 0 Then
  546.         frmPrintScreen.PrintBitmap Picture2.Picture
  547.     Else
  548.         MsgBox "Please capture or load an image before printing.", vbInformation, "Nothing To Print"
  549.     End If
  550. End Sub
  551. Private Sub mnuSave_Click()
  552. '--- This where we save the Captured part of the Screen
  553. '--- to disk. I would have set it save as JPG also
  554. '--- but PSC want let You upload the DLL needed
  555. '--- for now save only as a BMP
  556.     If Picture2.Picture = 0 Then
  557.         MsgBox "Please capture or load an image before saving.", vbInformation, "Nothing To Save"
  558.     Else
  559.         '--- Set the Filters
  560.         With CD1
  561.             .Filter = "Bitmap Files (*.bmp)|*.bmp"
  562.             '--- Specify default filter
  563.             .FilterIndex = 2
  564.             '--- Hide the "Open as read only" checkbox when saving.
  565.             .Flags = cdlOFNHideReadOnly
  566.             '--- Show the Open Dialog
  567.             .ShowSave
  568.             '--- If Canceled is Pressed
  569.             If .FileName = "" Then Exit Sub
  570.             '--- Save the Image
  571.             SavePicture Picture2.Image, .FileName
  572.         End With
  573.     End If
  574. End Sub
  575. Private Sub mnuFullScreen_Click()
  576. '--- This is where we capture the FULL screen
  577. '--- when the User chooses to capture the FULL Screen
  578.     '--- Capture the Screen
  579.     CaptureDesktop
  580.         
  581.     Me.Show
  582.     AdjustScrollbars
  583. End Sub
  584. Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
  585. '--- Where we do the action for the Clicked Icons
  586.     On Error Resume Next
  587.     Select Case Button.Key
  588.         Case "Exit"
  589.             mnuExit_Click
  590.         Case "Open"
  591.             mnuOpen_Click
  592.         Case "SaveIt"
  593.             mnuSave_Click
  594.         Case "Capture1"
  595.             mnuRectangle_Click
  596.         Case "Capture2"
  597.             mnuFullScreen_Click
  598.         Case "Copy"
  599.             mnuCopy_Click
  600.         Case "Print"
  601.             mnuPrint_Click
  602.         Case "Crop"
  603.             mnuCrop_Click
  604.         Case "About"
  605.             mnuAbout_Click
  606.     End Select
  607. End Sub
  608. Private Sub VScroll1_Change()
  609. '--- Make the changes to the Scrollbars as needed
  610. '--- NOTE: the "+ 60" offset is so that you can see right to
  611. '--- the very edge of the screencapture image.
  612.     If (Picture2.Height * Screen.TwipsPerPixelY) > Picture1.Height Then
  613.         Picture2.Top = 0 - ((VScroll1.Value / Screen.TwipsPerPixelX) + 4)
  614.     End If
  615. End Sub
  616. Private Sub HScroll1_Change()
  617. '--- Make the Changes to the Scrollbars as needed
  618. '--- NOTE: the "+ 60" offset is so that you can see right to
  619. '--- the very edge of the screencapture image.
  620.     If (Picture2.Width * Screen.TwipsPerPixelX) > Picture1.Width Then
  621.         Picture2.Left = 0 - ((HScroll1.Value / Screen.TwipsPerPixelX) + 4)
  622.     End If
  623. End Sub
  624. Private Sub AdjustScrollbars()
  625. '--- Adjust scrollbars' proportions according to size of Picture2
  626.     Dim oActiveControl As Control
  627.     'Exit Sub
  628.     On Error Resume Next
  629.     '--- Cache active control to fix scrollbar bug of blinking scrollbar button having focus
  630.     '--- then not resizing after scrollbar resizes:
  631.     '--- NOTE: Picture2.ScaleMode = pixels, but frmScreenCapture.ScaleMode = TWIPS, so becareful!!
  632.     With VScroll1
  633.         .Value = 0
  634.         .Min = 0
  635.         .Max = IIf(Picture1.Height > (Picture2.ScaleHeight * Screen.TwipsPerPixelX), 0, (Picture2.Height * Screen.TwipsPerPixelY) - Picture1.Height)
  636.         .SmallChange = (.Max / 20) + 1
  637.         .LargeChange = (.Max / 5) + 1
  638.         .Visible = (.Max > 0)
  639.         .Refresh
  640.     End With
  641.     '--- SetUp the HScroll1 Scroolbar
  642.     '--- incase the Image is Larger than the PictureBox
  643.     With HScroll1
  644.         .Value = 0
  645.         .Min = 0
  646.         .Max = IIf(Picture1.Width > (Picture2.Width * Screen.TwipsPerPixelX), 0, (Picture2.Width * Screen.TwipsPerPixelX) - Picture1.Width)
  647.         .SmallChange = (.Max / 20) + 1
  648.         .LargeChange = (.Max / 5) + 1
  649.         .Visible = (.Max > 0)
  650.         .Refresh
  651.     End With
  652.     '--- Some tweaks to get rid of the annoying "flashing" scroll buttons:
  653.     If Picture1.Visible Then
  654.         Set oActiveControl = Me.ActiveControl
  655.         Picture1.SetFocus
  656.         Select Case oActiveControl.Name
  657.             Case "HScroll1", "VScroll1"
  658.                 If oActiveControl.Max <> 0 Then
  659.                     'oActiveControl.SetFocus
  660.                 End If
  661.             Case Else
  662.                 oActiveControl.SetFocus
  663.         End Select
  664.         Set oActiveControl = Nothing
  665.     End If
  666. End Sub
  667. Public Sub ActivateRectangle()
  668.     '--- (not used in stand alone version of app)
  669.     '--- Exposed method so that if you include the project forms
  670.     '--- within another application, you can activate the "rectangle picker"
  671.     '--- from another part of the project without showing frmScreenCapture first.
  672.     mnuRectangle_Click
  673. End Sub
  674. Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  675. '--- This where we set the Begainning of the Box
  676. '--- that will be Drawn around the Capture Area
  677.     If mbCrop Then
  678.         mbDown = (Button = 1)
  679.         Picture2.MousePointer = vbCrosshair
  680.         
  681.         With Line1
  682.             .X1 = X
  683.             .X2 = X
  684.             .Y1 = Y
  685.             .Y2 = Y
  686.         End With
  687.             
  688.         With Line2
  689.             .X1 = X
  690.             .X2 = X
  691.             .Y1 = Y
  692.             .Y2 = Y
  693.         End With
  694.             
  695.         With Line3
  696.             .X1 = X
  697.             .X2 = X
  698.             .Y1 = Y
  699.             .Y2 = Y
  700.         End With
  701.             
  702.         With Line4
  703.             .X1 = X
  704.             .X2 = X
  705.             .Y1 = Y
  706.             .Y2 = Y
  707.         End With
  708.             
  709.         Line1.Visible = True
  710.         Line2.Visible = True
  711.         Line3.Visible = True
  712.         Line4.Visible = True
  713.         
  714.         nOldX = X
  715.         nOldY = Y
  716.     End If
  717. End Sub
  718. Private Sub Picture2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  719. '--- Where we Draw the Box around the Choosen Area as you hold down the Left Mouse
  720. '--- button and Drag in any direction to create a rectangle
  721.     If mbDown Then
  722.         With Line1
  723.             .X1 = nOldX
  724.             .X2 = X
  725.             .Y1 = nOldY
  726.             .Y2 = nOldY
  727.         End With
  728.         
  729.         With Line2
  730.             .X1 = nOldX
  731.             .X2 = nOldX
  732.             .Y1 = nOldY
  733.             .Y2 = Y
  734.         End With
  735.         
  736.         With Line3
  737.             .X1 = X
  738.             .X2 = X
  739.             .Y1 = nOldY
  740.             .Y2 = Y
  741.         End With
  742.         
  743.         With Line4
  744.             .X1 = nOldX
  745.             .X2 = X
  746.             .Y1 = Y
  747.             .Y2 = Y
  748.         End With
  749.     End If
  750. End Sub
  751. Private Sub Picture2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  752.     On Error Resume Next
  753.     Dim XUpperLeft As Long
  754.     Dim YUpperLeft As Long
  755.     Dim XLowerRight As Long
  756.     Dim YLowerRight As Long
  757.     Line1.Visible = False
  758.     Line2.Visible = False
  759.     Line3.Visible = False
  760.     Line4.Visible = False
  761.     Picture2.MousePointer = vbDefault
  762.     Toolbar1.Buttons(11).Value = tbrUnpressed
  763.     mbCrop = False
  764.     '--- Determine the upper left hand corner & lower right hand corner
  765.     '--- XY coordinates.  By doing this, it doesn't matter which
  766.     '--- direction the user "dragged" the rectangle:
  767.     XUpperLeft = Line1.X1
  768.     If Line1.X2 < XUpperLeft Then
  769.         XUpperLeft = Line1.X2
  770.     End If
  771.     With Line2
  772.         If .X1 < XUpperLeft Then
  773.             XUpperLeft = .X1
  774.         End If
  775.         If .X2 < XUpperLeft Then
  776.             XUpperLeft = .X2
  777.         End If
  778.     End With
  779.     YUpperLeft = Line1.Y1
  780.     If Line1.Y2 < YUpperLeft Then
  781.         YUpperLeft = Line1.Y2
  782.     End If
  783.     With Line2
  784.         If .Y1 < YUpperLeft Then
  785.             YUpperLeft = .Y1
  786.         End If
  787.         If .Y2 < YUpperLeft Then
  788.             YUpperLeft = .Y2
  789.         End If
  790.     End With
  791.     XLowerRight = Line1.X1
  792.     If Line1.X2 > XLowerRight Then
  793.         XLowerRight = Line1.X2
  794.     End If
  795.     With Line2
  796.         If .X1 > XLowerRight Then
  797.             XLowerRight = .X1
  798.         End If
  799.         If .X2 > XLowerRight Then
  800.             XLowerRight = .X2
  801.         End If
  802.     End With
  803.     YLowerRight = Line1.Y1
  804.     If Line1.Y2 > YLowerRight Then
  805.         YLowerRight = Line1.Y2
  806.     End If
  807.     With Line2
  808.         If .Y1 > YLowerRight Then
  809.             YLowerRight = .Y1
  810.         End If
  811.         If .Y2 > YLowerRight Then
  812.             YLowerRight = .Y2
  813.         End If
  814.     End With
  815.     '--- Selected a single pixel (clicked, no drag)
  816.     If XUpperLeft = XLowerRight Then XLowerRight = XLowerRight + 1
  817.     If YUpperLeft = YLowerRight Then YLowerRight = YLowerRight + 1
  818.     '--- Set the picRectangle to the size
  819.     '--- we will paint the Image to
  820.     With picRectangle
  821.         .Picture = LoadPicture()
  822.         .Cls
  823.         DoEvents
  824.         .Width = Abs(Line1.X2 - Line1.X1) * Screen.TwipsPerPixelX
  825.         .Height = Abs(Line2.Y2 - Line2.Y1) * Screen.TwipsPerPixelY
  826.         '--- Paint the Captured part of the screen to
  827.         '--- form3 Picture2
  828.         .PaintPicture Picture2.Picture, 0, 0, _
  829.             (XLowerRight - XUpperLeft), _
  830.             (YLowerRight - YUpperLeft), _
  831.             XUpperLeft, YUpperLeft, _
  832.             (XLowerRight - XUpperLeft), _
  833.             (YLowerRight - YUpperLeft)  ', opcode
  834.         
  835.         '--- IMPORTANT: DO NOT REMOVE THIS DoEvents! Windows needs to "catchup"
  836.         '--- before can use the "painted" picture.
  837.         DoEvents
  838.         mbDown = False
  839.     End With
  840.     '--- Load selected rectangle image into picture box:
  841.     With Picture2
  842.         '--- Incase picture was scrolled over (via scrollbars), reset it's position
  843.         .Left = 0
  844.         .Top = 0
  845.         '--- Just to be safe, clear picture before
  846.         '--- loading new image:
  847.         .Picture = LoadPicture()
  848.         .Cls
  849.         .Picture = picRectangle.Image
  850.     End With
  851.     AdjustScrollbars
  852. End Sub
  853. Private Sub Crop()
  854.     mbCrop = True
  855.     Picture2.MousePointer = vbCrosshair
  856.     Toolbar1.Buttons(11).Style = tbrCheck
  857.     Toolbar1.Buttons(11).Value = tbrPressed
  858. End Sub
  859.