home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD47964142000.psc / Module2.bas < prev    next >
Encoding:
BASIC Source File  |  2000-04-14  |  23.6 KB  |  548 lines

  1. Attribute VB_Name = "mZip"
  2. ' This OCX control is made by M. Schermer from the Netherlands
  3. ' This OCX can be used to capture the fullscreen or the active
  4. ' window. I'm take no care about damage on your computer but
  5. ' that is impossible.
  6. '
  7. ' To use this control compile it to an OCX and start an new project
  8. ' Goto COMPONENTS and add the compiled OCX file
  9. ' Now you can use it to add the control to your form and for
  10. ' example:
  11.  
  12. '   Dim FileToOpen as String
  13. '
  14. '   FileToOpen = CaptureScreen1.CaptureActiveScreen("C:\MyScreen.BMP", BMP, True)
  15. '   Image1.Picture = LoadPictures(FileToOpen)
  16. '
  17. ' PS: If you want to make a loop (for example: refresh picture every 1 second)
  18. ' check the CaptureScreen1.ReadyState
  19. ' it returns True if the process is ready
  20. ' it returns False if the process is not ready
  21. '
  22. '                           Have fun using this control
  23.  
  24.  
  25. Private Declare Function ZpInit Lib "vbzip10.dll" (ByRef tUserFn As ZIPUSERFUNCTIONS) As Long ' Set Zip Callbacks
  26. Private Declare Function ZpSetOptions Lib "vbzip10.dll" (ByRef tOpts As ZPOPT) As Long ' Set Zip options
  27. Private Declare Function ZpGetOptions Lib "vbzip10.dll" () As ZPOPT ' used to check encryption flag only
  28. Private Declare Function ZpArchive Lib "vbzip10.dll" (ByVal argc As Long, ByVal funame As String, ByRef argv As ZIPNAMES) As Long ' Real zipping action
  29. Public Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
  30. Public Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
  31. Public Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal iCapabilitiy As Long) As Long
  32. Public Declare Function GetSystemPaletteEntries Lib "gdi32" (ByVal hdc As Long, ByVal wStartIndex As Long, ByVal wNumEntries As Long, lpPaletteEntries As PALETTEENTRY) As Long
  33. Public Declare Function CreatePalette Lib "gdi32" (lpLogPalette As LOGPALETTE) As Long
  34. Public Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
  35. Public Declare Function BitBlt Lib "gdi32" (ByVal hDCDest As Long, ByVal XDest As Long, ByVal YDest As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hDCSrc As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
  36. Public Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
  37. Public Declare Function SelectPalette Lib "gdi32" (ByVal hdc As Long, ByVal hPalette As Long, ByVal bForceBackground As Long) As Long
  38. Public Declare Function RealizePalette Lib "gdi32" (ByVal hdc As Long) As Long
  39. Public Declare Function GetWindowDC Lib "USER32" (ByVal hwnd As Long) As Long
  40. Public Declare Function GetDC Lib "USER32" (ByVal hwnd As Long) As Long
  41. Public Declare Function ReleaseDC Lib "USER32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
  42. Public Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
  43. Public Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, lpRect As Rect) As Long
  44. Public Declare Function GetForegroundWindow Lib "USER32" () As Long
  45. Public Declare Function GetDesktopWindow Lib "USER32" () As Long
  46. Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
  47. Private Declare Function lopen Lib "kernel32" Alias "_lopen" (ByVal lpPathName As String, ByVal iReadWrite As Long) As Long
  48. Private Declare Function lclose Lib "kernel32" Alias "_lclose" (ByVal hFile As Long) As Long
  49. Private Declare Function SetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
  50. Private Declare Function SetFileAttributes Lib "kernel32" Alias "SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long
  51. Private Declare Function ijlInit Lib "ijl11.dll" (jcprops As Any) As Long
  52. Private Declare Function ijlFree Lib "ijl11.dll" (jcprops As Any) As Long
  53. Private Declare Function ijlRead Lib "ijl11.dll" (jcprops As Any, ByVal ioType As Long) As Long
  54. Private Declare Function ijlWrite Lib "ijl11.dll" (jcprops As Any, ByVal ioType As Long) As Long
  55. Private Declare Function ijlGetLibVersion Lib "ijl11.dll" () As Long
  56. Private Declare Function ijlGetErrorString Lib "ijl11.dll" (ByVal code As Long) As Long
  57. Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
  58. Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
  59. Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
  60. Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
  61. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
  62.     Public Const RASTERCAPS As Long = 38
  63.     Public Const RC_PALETTE As Long = &H100
  64.     Public Const SIZEPALETTE As Long = 104
  65.     Private Const OF_WRITE = &H1
  66.     Private Const OF_SHARE_DENY_WRITE = &H20
  67.     Private Const GENERIC_WRITE = &H40000000
  68.     Private Const GENERIC_READ = &H80000000
  69.     Private Const FILE_SHARE_WRITE = &H2
  70.     Private Const CREATE_ALWAYS = 2
  71.     Private Const FILE_BEGIN = 0
  72.     Private Const SECTION_MAP_WRITE = &H2
  73.     Private Const GMEM_DDESHARE = &H2000
  74.     Private Const GMEM_DISCARDABLE = &H100
  75.     Private Const GMEM_DISCARDED = &H4000
  76.     Private Const GMEM_FIXED = &H0
  77.     Private Const GMEM_INVALID_HANDLE = &H8000
  78.     Private Const GMEM_LOCKCOUNT = &HFF
  79.     Private Const GMEM_MODIFY = &H80
  80.     Private Const GMEM_MOVEABLE = &H2
  81.     Private Const GMEM_NOCOMPACT = &H10
  82.     Private Const GMEM_NODISCARD = &H20
  83.     Private Const GMEM_NOT_BANKED = &H1000
  84.     Private Const GMEM_NOTIFY = &H4000
  85.     Private Const GMEM_SHARE = &H2000
  86.     Private Const GMEM_VALID_FLAGS = &H7F72
  87.     Private Const GMEM_ZEROINIT = &H40
  88.     Private Const GPTR = (GMEM_FIXED Or GMEM_ZEROINIT)
  89.     Private Const MAX_PATH = 260
  90.         Global Setting As Integer
  91.  
  92.     Private Enum IJLERR
  93.         IJL_OK = 0
  94.         IJL_INTERRUPT_OK = 1
  95.         IJL_ROI_OK = 2
  96.         IJL_EXCEPTION_DETECTED = -1
  97.         IJL_INVALID_ENCODER = -2
  98.         IJL_UNSUPPORTED_SUBSAMPLING = -3
  99.         IJL_UNSUPPORTED_BYTES_PER_PIXEL = -4
  100.         IJL_MEMORY_ERROR = -5
  101.         IJL_BAD_HUFFMAN_TABLE = -6
  102.         IJL_BAD_QUANT_TABLE = -7
  103.         IJL_INVALID_JPEG_PROPERTIES = -8
  104.         IJL_ERR_FILECLOSE = -9
  105.         IJL_INVALID_FILENAME = -10
  106.         IJL_ERROR_EOF = -11
  107.         IJL_PROG_NOT_SUPPORTED = -12
  108.         IJL_ERR_NOT_JPEG = -13
  109.         IJL_ERR_COMP = -14
  110.         IJL_ERR_SOF = -15
  111.         IJL_ERR_DNL = -16
  112.         IJL_ERR_NO_HUF = -17
  113.         IJL_ERR_NO_QUAN = -18
  114.         IJL_ERR_NO_FRAME = -19
  115.         IJL_ERR_MULT_FRAME = -20
  116.         IJL_ERR_DATA = -21
  117.         IJL_ERR_NO_IMAGE = -22
  118.         IJL_FILE_ERROR = -23
  119.         IJL_INTERNAL_ERROR = -24
  120.         IJL_BAD_RST_MARKER = -25
  121.         IJL_THUMBNAIL_DIB_TOO_SMALL = -26
  122.         IJL_THUMBNAIL_DIB_WRONG_COLOR = -27
  123.         IJL_RESERVED = -99
  124.     End Enum
  125.     
  126.     Private Enum IJLIOTYPE
  127.         IJL_SETUP = -1&
  128.         IJL_JFILE_READPARAMS = 0&
  129.         IJL_JBUFF_READPARAMS = 1&
  130.         IJL_JFILE_READWHOLEIMAGE = 2&
  131.         IJL_JBUFF_READWHOLEIMAGE = 3&
  132.         IJL_JFILE_READHEADER = 4&
  133.         IJL_JBUFF_READHEADER = 5&
  134.         IJL_JFILE_READENTROPY = 6&
  135.         IJL_JBUFF_READENTROPY = 7&
  136.         IJL_JFILE_WRITEWHOLEIMAGE = 8&
  137.         IJL_JBUFF_WRITEWHOLEIMAGE = 9&
  138.         IJL_JFILE_WRITEHEADER = 10&
  139.         IJL_JBUFF_WRITEHEADER = 11&
  140.         IJL_JFILE_WRITEENTROPY = 12&
  141.         IJL_JBUFF_WRITEENTROPY = 13&
  142.         IJL_JFILE_READONEHALF = 14&
  143.         IJL_JBUFF_READONEHALF = 15&
  144.         IJL_JFILE_READONEQUARTER = 16&
  145.         IJL_JBUFF_READONEQUARTER = 17&
  146.         IJL_JFILE_READONEEIGHTH = 18&
  147.         IJL_JBUFF_READONEEIGHTH = 19&
  148.         IJL_JFILE_READTHUMBNAIL = 20&
  149.         IJL_JBUFF_READTHUMBNAIL = 21&
  150.     End Enum
  151.     
  152.     Private Type JPEG_CORE_PROPERTIES_VB ' Sadly, due to a limitation in VB (UDT variable count)
  153.         UseJPEGPROPERTIES As Long                      '// default = 0
  154.         DIBBytes As Long ';                  '// default = NULL 4
  155.         DIBWidth As Long ';                  '// default = 0 8
  156.         DIBHeight As Long ';                 '// default = 0 12
  157.         DIBPadBytes As Long ';               '// default = 0 16
  158.         DIBChannels As Long ';               '// default = 3 20
  159.         DIBColor As Long ';                  '// default = IJL_BGR 24
  160.         DIBSubsampling As Long  ';            '// default = IJL_NONE 28
  161.         JPGFile As Long 'LPTSTR              JPGFile;                32   '// default = NULL
  162.         JPGBytes As Long ';                  '// default = NULL 36
  163.         JPGSizeBytes As Long ';              '// default = 0 40
  164.         JPGWidth As Long ';                  '// default = 0 44
  165.         JPGHeight As Long ';                 '// default = 0 48
  166.         JPGChannels As Long ';               '// default = 3
  167.         JPGColor As Long           ';                  '// default = IJL_YCBCR
  168.         JPGSubsampling As Long  ';            '// default = IJL_411
  169.         JPGThumbWidth As Long ' ;             '// default = 0
  170.         JPGThumbHeight As Long ';            '// default = 0
  171.         cconversion_reqd As Long ';          '// default = TRUE
  172.         upsampling_reqd As Long ';           '// default = TRUE
  173.         jquality As Long ';                  '// default = 75.  100 is my preferred quality setting.
  174.         jprops(0 To 19999) As Byte
  175.     End Type
  176.     
  177.     Private Type FILETIME
  178.         dwLowDateTime As Long
  179.         dwHighDateTime As Long
  180.     End Type
  181.     
  182.     Private Type WIN32_FIND_DATA
  183.         dwFileAttributes As Long
  184.         ftCreationTime As FILETIME
  185.         ftLastAccessTime As FILETIME
  186.         ftLastWriteTime As FILETIME
  187.         nFileSizeHigh As Long
  188.         nFileSizeLow As Long
  189.         dwReserved0 As Long
  190.         dwReserved1 As Long
  191.         cFileName As String * MAX_PATH
  192.         cAlternate As String * 14
  193.     End Type
  194.     
  195.     Type Rect
  196.         left As Long
  197.         top As Long
  198.         right As Long
  199.         bottom As Long
  200.     End Type
  201.     
  202.     Public Type PALETTEENTRY
  203.         peRed As Byte
  204.         peGreen As Byte
  205.         peBlue As Byte
  206.         peFlags As Byte
  207.     End Type
  208.     
  209.     Public Type LOGPALETTE
  210.         palVersion As Integer
  211.         palNumEntries As Integer
  212.         palPalEntry(255) As PALETTEENTRY
  213.     End Type
  214.     
  215.     Public Type GUID
  216.         Data1 As Long
  217.         Data2 As Integer
  218.         Data3 As Integer
  219.         Data4(7) As Byte
  220.     End Type
  221.     
  222.     Public Type PicBmp
  223.         Size As Long
  224.         Type As Long
  225.         hBmp As Long
  226.         hPal As Long
  227.         Reserved As Long
  228.     End Type
  229.     
  230.     Private Type ZIPNAMES         ' argv
  231.         s(0 To 1023)   As String
  232.     End Type
  233.     
  234.     Private Type CBCHAR           ' Callback large "string" (sic)
  235.         ch(0 To 4096)  As Byte
  236.     End Type
  237.     
  238.     Private Type CBCH             ' Callback small "string" (sic)
  239.         ch(0 To 255)   As Byte
  240.     End Type
  241.     
  242.     Private Type ZIPUSERFUNCTIONS ' Store the callback functions
  243.         lPtrPrint      As Long    ' Pointer to application's print routine
  244.         lptrPassword   As Long    ' Pointer to application's password routine.
  245.         lptrComment    As Long
  246.         lptrService    As Long    ' callback function designed to be used for allowing the app to process Windows messages, or cancelling the operation as well as giving option of progress. If this function returns non-zero, it will terminate what it is doing. It provides the app with the name of the archive member it has just processed, as well as the original size.
  247.     End Type
  248.     
  249.     Public Type ZPOPT
  250.         date           As String  ' US Date (8 Bytes Long) "12/31/98"?
  251.         szRootDir      As String  ' Root Directory Pathname (Up To 256 Bytes Long)
  252.         szTempDir      As String  ' Temp Directory Pathname (Up To 256 Bytes Long)
  253.         fTemp          As Long    ' 1 If Temp dir Wanted, Else 0
  254.         fSuffix        As Long    ' Include Suffixes (Not Yet Implemented!)
  255.         fEncrypt       As Long    ' 1 If Encryption Wanted, Else 0
  256.         fSystem        As Long    ' 1 To Include System/Hidden Files, Else 0
  257.         fVolume        As Long    ' 1 If Storing Volume Label, Else 0
  258.         fExtra         As Long    ' 1 If Excluding Extra Attributes, Else 0
  259.         fNoDirEntries  As Long    ' 1 If Ignoring Directory Entries, Else 0
  260.         fExcludeDate   As Long    ' 1 If Excluding Files Earlier Than Specified Date, Else 0
  261.         fIncludeDate   As Long    ' 1 If Including Files Earlier Than Specified Date, Else 0
  262.         fVerbose       As Long    ' 1 If Full Messages Wanted, Else 0
  263.         fQuiet         As Long    ' 1 If Minimum Messages Wanted, Else 0
  264.         fCRLF_LF       As Long    ' 1 If Translate CR/LF To LF, Else 0
  265.         fLF_CRLF       As Long    ' 1 If Translate LF To CR/LF, Else 0
  266.         fJunkDir       As Long    ' 1 If Junking Directory Names, Else 0
  267.         fGrow          As Long    ' 1 If Allow Appending To Zip File, Else 0
  268.         fForce         As Long    ' 1 If Making Entries Using DOS File Names, Else 0
  269.         fMove          As Long    ' 1 If Deleting Files Added Or Updated, Else 0
  270.         fDeleteEntries As Long    ' 1 If Files Passed Have To Be Deleted, Else 0
  271.         fUpdate        As Long    ' 1 If Updating Zip File-Overwrite Only If Newer, Else 0
  272.         fFreshen       As Long    ' 1 If Freshing Zip File-Overwrite Only, Else 0
  273.         fJunkSFX       As Long    ' 1 If Junking SFX Prefix, Else 0
  274.         fLatestTime    As Long    ' 1 If Setting Zip File Time To Time Of Latest File In Archive, Else 0
  275.         fComment       As Long    ' 1 If Putting Comment In Zip File, Else 0
  276.         fOffsets       As Long    ' 1 If Updating Archive Offsets For SFX Files, Else 0
  277.         fPrivilege     As Long    ' 1 If Not Saving Privileges, Else 0
  278.         fEncryption    As Long    ' Read Only Property!!!
  279.         fRecurse       As Long    ' 1 (-r), 2 (-R) If Recursing Into Sub-Directories, Else 0
  280.         fRepair        As Long    ' 1 = Fix Archive, 2 = Try Harder To Fix, Else 0
  281.         flevel         As Byte    ' Compression Level - 0 = Stored 6 = Default 9 = Max
  282.     End Type
  283.  
  284. Private Function plAddressOf(ByVal lPtr As Long) As Long
  285.     plAddressOf = lPtr ' VB Bug workaround fn
  286. End Function
  287.  
  288. Public Function VBZip(cZipObject As cZip, tZPOPT As ZPOPT, sFileSpecs() As String, iFileCount As Long) As Long
  289.     Dim tUser As ZIPUSERFUNCTIONS
  290.     Dim lR As Long
  291.     Dim i As Long
  292.     Dim sZipFile As String
  293.     Dim tZipName As ZIPNAMES
  294.     
  295.     m_bCancel = False
  296.     Set m_cZip = cZipObject
  297.         If Not Len(Trim$(m_cZip.BasePath)) = 0 Then
  298.             ChDir m_cZip.BasePath
  299.         End If
  300.     tUser.lPtrPrint = plAddressOf(AddressOf ZipPrintCallback)      ' Set address of callback functions
  301.     tUser.lptrPassword = plAddressOf(AddressOf ZipPasswordCallback)
  302.     tUser.lptrComment = plAddressOf(AddressOf ZipCommentCallback)
  303.     tUser.lptrService = plAddressOf(AddressOf ZipServiceCallback)  ' not coded yet :-)
  304.     lR = ZpInit(tUser)
  305.     lR = ZpSetOptions(tZPOPT) ' Set options
  306.         For i = 1 To iFileCount   ' Go for it!
  307.             tZipName.s(i - 1) = sFileSpecs(i)
  308.             DoEvents
  309.         Next i
  310.     tZipName.s(i) = vbNullChar
  311.     sZipFile = cZipObject.ZipFile
  312.     lR = ZpArchive(iFileCount, sZipFile, tZipName) ' Dit neemt tijd in beslag
  313.     Debug.Print lR
  314.     VBZip = lR
  315. End Function
  316.  
  317. Private Function ZipServiceCallback(ByRef mname As CBCHAR, ByVal X As Long) As Long
  318.   On Error Resume Next                  'Always Put This In Callback Routines!
  319.     Dim iPos As Long
  320.     Dim sInfo As String
  321.     Dim bCancel As Boolean
  322.     
  323.     If X > 1 And X < 32000 Then       ' Check we've got a message:
  324.         ReDim b(0 To X) As Byte       ' If so, then get the readable portion of it:
  325.         CopyMemory b(0), mname, X
  326.         DoEvents
  327.         sInfo = StrConv(b, vbUnicode) ' Convert to VB string:
  328.         iPos = InStr(sInfo, vbNullChar)
  329.             If iPos > 0 Then
  330.                 sInfo = left$(sInfo, iPos - 1)
  331.             End If
  332.         m_cZip.Service sInfo, bCancel
  333.             If bCancel Then
  334.                 ZipServiceCallback = 1
  335.             Else
  336.                 ZipServiceCallback = 0
  337.             End If
  338.     End If
  339. End Function
  340.  
  341. Private Function ZipPrintCallback(ByRef fname As CBCHAR, ByVal X As Long) As Long
  342.     On Error Resume Next
  343.     Dim iPos As Long
  344.     Dim sFile As String
  345.     
  346.     If X > 1 And X < 32000 Then        ' Check we've got a message:
  347.         ReDim b(0 To X) As Byte        ' If so, then get the readable portion of it:
  348.         CopyMemory b(0), fname, X
  349.         sFile = StrConv(b, vbUnicode)  ' Convert to VB string:
  350.             If iPos > 0 Then
  351.                 sFile = left$(sFile, iPos - 1)
  352.                 DoEvents
  353.             End If
  354.         ReplaceSection sFile, "/", "\" ' Fix up backslashes:
  355.         m_cZip.ProgressReport sFile    ' Tell the caller about it
  356.     End If
  357.     
  358.     ZipPrintCallback = 0
  359. End Function
  360.  
  361. Private Function ZipCommentCallback(ByRef s1 As CBCHAR) As CBCHAR
  362.  On Error Resume Next    ' always put this in callback routines!
  363.    
  364.    s1.ch(0) = vbNullString ' not supported always return \0
  365.    ZipCommentCallback = s1
  366. End Function
  367.  
  368. Private Function ZipPasswordCallback(ByRef pwd As CBCH, ByVal X As Long, ByRef s2 As CBCH, ByRef Name As CBCH) As Long
  369.   On Error Resume Next
  370.     Dim bCancel As Boolean
  371.     Dim sPassword As String
  372.     Dim b() As Byte
  373.     Dim lSize As Long
  374.  
  375.     ZipPasswordCallback = 1                   ' The default:
  376.         If m_bCancel Then
  377.             Exit Function
  378.         End If
  379.     m_cZip.PasswordRequest sPassword, bCancel ' Ask for password:
  380.     sPassword = Trim$(sPassword)
  381.         If bCancel Or Len(sPassword) = 0 Then     ' Cancel out if no useful password:
  382.             m_bCancel = True
  383.             Exit Function
  384.         End If
  385.     lSize = Len(sPassword)                    ' Put password into return parameter:
  386.         If lSize > 254 Then
  387.             lSize = 254
  388.         End If
  389.     b = StrConv(sPassword, vbFromUnicode)
  390.     CopyMemory pwd.ch(0), b(0), lSize
  391.     ZipPasswordCallback = 0                   ' Ask UnZip to process it:
  392. End Function
  393.  
  394. Private Function ReplaceSection(ByRef sString As String, ByVal sToReplace As String, ByVal sReplaceWith As String) As Long
  395.     Dim iPos As Long
  396.     Dim iLastPos As Long
  397.     Dim ReadyProcess As Boolean
  398.     
  399.     iLastPos = 1
  400.     ReadyProcess = False
  401.     
  402.     Do Until ReadyProcess = True
  403.         iPos = InStr(sString, Chr(0))
  404.         If iPos <> 0 Then
  405.             sString = Mid(sString, 1, iPos - 1)
  406.         Else
  407.             ReadyProcess = True
  408.         End If
  409.     Loop
  410.     
  411.     Do
  412.         iPos = InStr(iLastPos, sString, "/")
  413.         If (iPos > 1) Then
  414.             Mid$(sString, iPos, 1) = "\"
  415.             iLastPos = iPos + 1
  416.         End If
  417.     Loop While Not (iPos = 0)
  418.     
  419.     ReplaceSection = iLastPos
  420. End Function
  421.  
  422. Public Function CreateBitmapPicture(ByVal hBmp As Long, ByVal hPal As Long) As Picture
  423.     Dim r As Long
  424.     Dim Pic As PicBmp
  425.     Dim IPic As IPicture
  426.     Dim IID_IDispatch As GUID
  427.  
  428.     With IID_IDispatch
  429.         .Data1 = &H20400
  430.         .Data4(0) = &HC0
  431.         .Data4(7) = &H46
  432.     End With
  433.  
  434.     With Pic
  435.         .Size = Len(Pic) ' Length of structure
  436.         .Type = vbPicTypeBitmap ' Type of Picture (bitmap)
  437.         .hBmp = hBmp ' Handle to bitmap
  438.         .hPal = hPal ' Handle to palette (may be null)
  439.     End With
  440.  
  441.     DoEvents
  442.     r = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)
  443.     DoEvents
  444.     Set CreateBitmapPicture = IPic
  445. End Function
  446.  
  447. Public Function CaptureWindow(ByVal hWndSrc As Long, ByVal Client As Boolean, ByVal LeftSrc As Long, ByVal TopSrc As Long, ByVal WidthSrc As Long, ByVal HeightSrc As Long) As Picture
  448.     Dim hDCMemory As Long
  449.     Dim hBmp As Long
  450.     Dim hBmpPrev As Long
  451.     Dim r As Long
  452.     Dim hDCSrc As Long
  453.     Dim hPal As Long
  454.     Dim hPalPrev As Long
  455.     Dim RasterCapsScrn As Long
  456.     Dim HasPaletteScrn As Long
  457.     Dim PaletteSizeScrn As Long
  458.     Dim LogPal As LOGPALETTE
  459.         If Client Then
  460.             hDCSrc = GetDC(hWndSrc) ' Get device context For client area
  461.         Else
  462.             hDCSrc = GetWindowDC(hWndSrc) ' Get device context For entire window
  463.         End If
  464.     hDCMemory = CreateCompatibleDC(hDCSrc) ' Create a memory device context for the copy process
  465.     DoEvents
  466.     hBmp = CreateCompatibleBitmap(hDCSrc, WidthSrc, HeightSrc) ' Create a bitmap and place it in the memory DC
  467.     hBmpPrev = SelectObject(hDCMemory, hBmp) ' Get screen properties
  468.     RasterCapsScrn = GetDeviceCaps(hDCSrc, RASTERCAPS) ' Raster capabilities
  469.     HasPaletteScrn = RasterCapsScrn And RC_PALETTE ' Palette support
  470.     PaletteSizeScrn = GetDeviceCaps(hDCSrc, SIZEPALETTE) ' Size of palette
  471.         If HasPaletteScrn And (PaletteSizeScrn = 256) Then ' Create a copy of the system palette
  472.             LogPal.palVersion = &H300
  473.             LogPal.palNumEntries = 256
  474.             r = GetSystemPaletteEntries(hDCSrc, 0, 256, LogPal.palPalEntry(0))
  475.             hPal = CreatePalette(LogPal)
  476.             hPalPrev = SelectPalette(hDCMemory, hPal, 0) ' Select the new palette into the memoryDC and realize it
  477.             r = RealizePalette(hDCMemory)
  478.         End If
  479.     r = BitBlt(hDCMemory, 0, 0, WidthSrc, HeightSrc, hDCSrc, LeftSrc, TopSrc, vbSrcCopy) ' Copy the on-screen image into the memory DC
  480.     DoEvents
  481.     hBmp = SelectObject(hDCMemory, hBmpPrev)
  482.         If HasPaletteScrn And (PaletteSizeScrn = 256) Then ' If the screen has a palette get back the palette that was selected in previously
  483.             hPal = SelectPalette(hDCMemory, hPalPrev, 0)
  484.         End If
  485.     DoEvents
  486.     r = DeleteDC(hDCMemory) ' Release the device context resources back to the system
  487.     r = ReleaseDC(hWndSrc, hDCSrc) ' Call CreateBitmapPicture to create a picture object from the bitmap and palette handles. Then return the resulting picture object.
  488.     DoEvents
  489.     Set CaptureWindow = CreateBitmapPicture(hBmp, hPal)
  490. End Function
  491.  
  492. Public Function SaveJPG(ByRef cDib As cDIBSection, ByVal sFile As String, Optional ByVal lQuality As Long = 90) As Boolean
  493.     Dim tJ As JPEG_CORE_PROPERTIES_VB
  494.     Dim bFile() As Byte
  495.     Dim lPtr As Long
  496.     Dim lR As Long
  497.     Dim tFnd As WIN32_FIND_DATA
  498.     Dim hFile As Long
  499.     Dim bFileExisted As Boolean
  500.     Dim lFileSize As Long
  501.    
  502.     hFile = -1
  503.     
  504.     lR = ijlInit(tJ)
  505.     If lR = IJL_OK Then
  506.     
  507.     bFileExisted = (FindFirstFile(sFile, tFnd) <> -1)
  508.         If bFileExisted Then
  509.         Kill sFile
  510.         End If
  511.     tJ.DIBWidth = cDib.Width
  512.     tJ.DIBHeight = -cDib.Height
  513.     tJ.DIBBytes = cDib.DIBSectionBitsPtr
  514.     tJ.DIBPadBytes = cDib.BytesPerScanLine - cDib.Width * 3
  515.     bFile = StrConv(sFile, vbFromUnicode)
  516.     ReDim Preserve bFile(0 To UBound(bFile) + 1) As Byte
  517.     bFile(UBound(bFile)) = 0
  518.     lPtr = VarPtr(bFile(0))
  519.     DoEvents
  520.     CopyMemory tJ.JPGFile, lPtr, 4
  521.     DoEvents
  522.     tJ.JPGWidth = cDib.Width
  523.     tJ.JPGHeight = cDib.Height
  524.     tJ.jquality = lQuality
  525.     lR = ijlWrite(tJ, IJL_JFILE_WRITEWHOLEIMAGE)
  526.     If lR = IJL_OK Then
  527.     If bFileExisted Then
  528.     hFile = lopen(sFile, OF_WRITE Or OF_SHARE_DENY_WRITE)
  529.     If hFile = 0 Then
  530.     Else
  531.     SetFileTime hFile, tFnd.ftCreationTime, tFnd.ftLastAccessTime, tFnd.ftLastWriteTime
  532.     lclose hFile
  533.     SetFileAttributes sFile, tFnd.dwFileAttributes
  534.     End If
  535.     End If
  536.     lFileSize = tJ.JPGSizeBytes - tJ.JPGBytes
  537.     SaveJPG = True
  538.     Else
  539.     Err.Raise 26001, App.EXEName & ".mIntelJPEGLibrary", "Failed to save to JPG " & lR, vbExclamation
  540.     End If
  541.     ijlFree tJ
  542.     Else
  543.     Err.Raise 26001, App.EXEName & ".mIntelJPEGLibrary", "Failed to initialise the IJL library: " & lR
  544.     End If
  545. End Function
  546.  
  547.  
  548.