home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Make_an_Ac53485262002.psc / SCREEN.cls < prev   
Encoding:
Visual Basic class definition  |  2002-02-06  |  5.7 KB  |  151 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "DISPLAY"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = True
  14. Option Explicit
  15. Public Enum MeasureType
  16.     mt_TWIPS = 0
  17.     mt_PIXEL = 1
  18. End Enum
  19. Private Const CCHDEVICENAME = 32
  20. Private Const CCHFORMNAME = 32
  21. Public Filename As String
  22. Private Type RECT
  23.     Left As Long
  24.     Top As Long
  25.     Right As Long
  26.     Bottom As Long
  27. End Type
  28. Private Type DevMode
  29.         dmDeviceName As String * CCHDEVICENAME
  30.         dmSpecVersion As Integer
  31.         dmDriverVersion As Integer
  32.         dmSize As Integer
  33.         dmDriverExtra As Integer
  34.         dmFields As Long
  35.         dmOrientation As Integer
  36.         dmPaperSize As Integer
  37.         dmPaperLength As Integer
  38.         dmPaperWidth As Integer
  39.         dmScale As Integer
  40.         dmCopies As Integer
  41.         dmDefaultSource As Integer
  42.         dmPrintQuality As Integer
  43.         dmColor As Integer
  44.         dmDuplex As Integer
  45.         dmYResolution As Integer
  46.         dmTTOption As Integer
  47.         dmCollate As Integer
  48.         dmFormName As String * CCHFORMNAME
  49.         dmUnusedPadding As Integer
  50.         dmBitsPerPel As Integer
  51.         dmPelsWidth As Long
  52.         dmPelsHeight As Long
  53.         dmDisplayFlags As Long
  54.         dmDisplayFrequency As Long
  55. End Type
  56. Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
  57. Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
  58. Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
  59. Private Declare Function EmptyClipboard Lib "user32" () As Long
  60. Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
  61. Private Declare Function CloseClipboard Lib "user32" () As Long
  62. Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
  63. Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
  64. Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
  65. Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As DevMode) As Long
  66. Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
  67. Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
  68. Private Sub ScrnCap(Lt, Top, Rt, Bot)
  69.     On Error GoTo ErrorScrnCap
  70.     Dim rWIDTH As Long, rHEIGHT As Long
  71.     Dim SourceDC As Long, DestDC As Long, bHANDLE As Long, Wnd As Long
  72.     Dim dHANDLE As Long, dm As DevMode
  73.     rWIDTH = Rt - Lt
  74.     rHEIGHT = Bot - Top
  75.     SourceDC = CreateDC("DISPLAY", 0&, 0&, dm)
  76.     DestDC = CreateCompatibleDC(SourceDC)
  77.     bHANDLE = CreateCompatibleBitmap(SourceDC, rWIDTH, rHEIGHT)
  78.     SelectObject DestDC, bHANDLE
  79.     BitBlt DestDC, 0, 0, rWIDTH, rHEIGHT, SourceDC, Lt, Top, &HCC0020
  80.     Wnd = 0
  81.     OpenClipboard Wnd
  82.     EmptyClipboard
  83.     SetClipboardData 2, bHANDLE
  84.     CloseClipboard
  85.     DeleteDC DestDC
  86.     ReleaseDC dHANDLE, SourceDC
  87.     Exit Sub
  88. ErrorScrnCap:
  89.     MsgBox Err & ":Error in ScrnCap().  Error Message:" & Err.Description, vbCritical, "Warning"
  90.     Exit Sub
  91. End Sub
  92. '------------------------------------------------------------
  93. ' Author:  Clint LaFever [lafeverc@usa.net]
  94. ' Purpose:  Captures a control/window based on hWnd and save to a .BMP.
  95. ' Parameters:  hWnd=Control/Window to capture, fNAME=Save .BMP to...
  96. ' Example:  obj.Capture lvLIST.hWnd,"TEST.BMP"
  97. ' Date: August,21 1998 @ 16:18:27
  98. '------------------------------------------------------------
  99. Public Sub Capture(control_hWnd As Long, Optional fNAME As String = "")
  100.     On Error GoTo ErrorCapture
  101.     Dim sp As RECT, x As Long
  102.     If fNAME = "" Then
  103.         fNAME = Me.Filename
  104.     Else
  105.         Me.Filename = fNAME
  106.     End If
  107.     If Me.Filename <> "" Then
  108.         x = GetWindowRect(control_hWnd, sp)
  109.         ScrnCap sp.Left, sp.Top, sp.Right, sp.Bottom
  110.         SavePicture Clipboard.GetData, Me.Filename
  111.     End If
  112.     Exit Sub
  113. ErrorCapture:
  114.     MsgBox Err & ":Error in Caputre().  Error Message:" & Err.Description, vbCritical, "Warning"
  115.     Exit Sub
  116. End Sub
  117.  
  118.  
  119. Public Function GetScreenWidth(Optional plngMeasure As MeasureType = mt_TWIPS) As Long
  120.     On Error GoTo ErrorGetScreenWidth
  121.     Select Case plngMeasure
  122.         Case mt_PIXEL
  123.             GetScreenWidth = SCREEN.Width / SCREEN.TwipsPerPixelX
  124.         Case mt_TWIPS
  125.             GetScreenWidth = SCREEN.Width
  126.         Case Else
  127.             GetScreenWidth = 0
  128.     End Select
  129.     Exit Function
  130. ErrorGetScreenWidth:
  131.     GetScreenWidth = 0
  132.     MsgBox Err & ":Error in GetScreenWidth.  Error Message: " & Err.Description, vbCritical, "Warning"
  133.     Exit Function
  134. End Function
  135. Public Function GetScreenHeight(Optional plngMeasure As MeasureType = mt_TWIPS) As Long
  136.     On Error GoTo ErrorGetScreenHeight
  137.     Select Case plngMeasure
  138.         Case mt_PIXEL
  139.             GetScreenHeight = SCREEN.Height / SCREEN.TwipsPerPixelY
  140.         Case mt_TWIPS
  141.             GetScreenHeight = SCREEN.Height
  142.         Case Else
  143.             GetScreenHeight = 0
  144.     End Select
  145.     Exit Function
  146. ErrorGetScreenHeight:
  147.     GetScreenHeight = 0
  148.     MsgBox Err & ":Error in GetScreenHeight.  Error Message: " & Err.Description, vbCritical, "Warning"
  149.     Exit Function
  150. End Function
  151.