Simple Snapshot Tool (1)
;==========================================================================================================================================
; Simple Snapshot Tool
;
; (c) Detlev Dalitz.20091217.20091225.
;==========================================================================================================================================

#DefineFunction udfSnapshot (strFileBMP)
blnPixelWrapExists = @TRUE ; Set this to @TRUE, if created bmp file has pixels wrapped.
Snapshot (0) ; Takes a bitmap snapshot of the screen and pastes it to the clipboard.
intDataSize = BinaryClipGet (0, 8)
hdlBB = BinaryAlloc (intDataSize) ; Allocates a data buffer.
BinaryClipGet (hdlBB, 8) ; Read file format type CF_DIB.
intBmpDataSize = 14
intBmpSize = intDataSize + intBmpDataSize ; Need to add first 14 bytes to make it a BMP file format.
hdlBB2 = BinaryAlloc (intBmpSize)
BinaryPokeStr (hdlBB2, 0, "BM") ; The characters identifying the bitmap 'BM'.
BinaryPoke4 (hdlBB2, 2, intBmpSize)
intTableLoc = BinaryPeek4 (hdlBB, 0) + intBmpDataSize + (blnPixelWrapExists * 12)
BinaryPoke4 (hdlBB2, 10, intTableLoc)
BinaryCopy (hdlBB2, intBmpDataSize, hdlBB, 0, intDataSize)
BinaryWrite (hdlBB2, strFileBMP)
hdlBB2 = BinaryFree (hdlBB2)
hdlBB = BinaryFree (hdlBB)
Return FileExist (strFileBMP)
#EndFunction

#DefineFunction udfSaveSnapshot (strFileName, strFileExt, intFileCounterLen, intNum)
strFileBMP = strFileName : ".bmp"
If udfSnapshot (strFileBMP) != 1 Then Return intNum
intNum = intNum + 1
strFileSnapshot = strFileName : "." : StrFixLeft (intNum, "0", intFileCounterLen) : "." : strFileExt
intResult = ImgConvert (FileFullname (strFileBMP), FileFullname (strFileSnapshot))
intResult = FileDelete (strFileBMP)
Return intNum
#EndFunction


; Main.

; Display instructions.
strMsgTitle = "Simple Snapshot Tool"
strMsgText = "Instructions:" : @LF : @LF : "Press [Ctrl] to shot." : @LF : "Press [Shift] to exit."
Pause (strMsgTitle, strMsgText)

; Get home folder.
strFolderHome = DirGet ()

; Get temp folder
strFolderTemp = ShortCutDir ("Local Settings", 0, 0) : "\Temp\" ; User temp folder.

; Set work folder.
strFolderWork = strFolderTemp : "Snapshots\"
Terminate (!DirMake (strFolderWork), "Terminated.", "Cannot create folder: " : @LF : strFolderWork)
Terminate (!DirChange (strFolderWork), "Terminated.", "Cannot access folder: " : @LF : strFolderWork)

; Note:
; When using a "delegates.mgk" file and delegating the image conversion to Irfanview ...
; ... we can create jpg files with better resolution and quality than the Pixie extender.
; See example "delegates.mgk" file at end of the script.

; Set file type and mask.
strFileExt = "jpg"
strFileName = "Snapshot"
intFileCounterLen = 5
strFileMask = strFileName : "." : StrFill ("?", intFileCounterLen) : "." : strFileExt

; Get last number.
intNum = 0
strListFiles = FileItemize (strFileMask)
If strListFiles != ""
   strListFiles = ItemSort (strListFiles, @TAB)
   strNum = ItemExtract (-1, strListFiles, @TAB)
   strNum = ItemRemove (-1, strNum, ".")
   strNum = ItemExtract (-1, strNum, ".")
   intNum = Int (strNum)
EndIf

; Load Pixie extender for image conversion.
AddExtender ("WWIMG44I.DLL")

; Loop.
WinTitle ("", intNum : " snapshots")
While @TRUE
   If IsKeyDown (@CTRL)
      intNum = udfSaveSnapshot (strFileName, strFileExt, intFileCounterLen, intNum)
      WinTitle ("", intNum : " snapshots")
   EndIf
   If IsKeyDown (@SHIFT) Then Break
   TimeDelay (.1)
EndWhile

; Back to home folder.
Terminate (!DirChange (strFolderHome), "Terminated.", "Cannot access folder: " : @LF : strFolderHome)

; Say Goodbye.
strMsgText = "Goodbye."
Display (1, strMsgTitle, strMsgText)

; Display snapshots.
; Try to start IrfanView application otherwise Explorer.
strIrfanViewUninstall = RegQueryValue (@REGMACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\IrfanView[UninstallString]")
strIrfanViewExe = FilePath (strIrfanViewUninstall) : "i_view32.exe" ; e. g. "C:\Program Files\IrfanView\i_view32.exe"
If FileExist (strIrfanViewExe) == 1
   ShellExecute (strIrfanViewExe, '"' : strFolderWork : '"' : " /thumbs", strFolderWork, @ZOOMED, "")
Else
   ShellExecute ("explorer.exe", "/e," : '"' : strFolderWork : '"', strFolderWork, @ZOOMED, "")
EndIf

:CANCEL
Exit

;==================================================================================================================================================================================================================================================================
; Here is an example of the ImageMagick "delegates.mgk" (xml formatted text file) for usage with the WinBatch Pixie extender.
; The WinBatch Pixie extender can access this file, if stored in the WinBatch\System folder.
;
; An image conversion, which Pixie cannot do, e. g. from BMP to PNG, can be realized
; by delegation to some image converter application, e. g. Irfanview application.
; Irfanview allows to change jpg quality and other properties, which Pixie cannot do.
;..................................................................................................................................................................................................................................................................
; <?xml version="1.0"?>
; <delegatemap>
; <delegate decode="eps" encode="pdf" mode="bi" command='C:\Program Files\gs\gs8.64\bin\gswin32c -q -dBATCH -dMaxBitmap=300000000 -dNOPAUSE -dSAFER -sDEVICE=pdfwrite -sOutputFile=%o -- "%i" -c quit' />
; <delegate decode="eps" encode="ps" mode="bi" command='C:\Program Files\gs\gs8.64\bin\gswin32c -q -dBATCH -dMaxBitmap=300000000 -dNOPAUSE -dSAFER -sDEVICE=pswrite -sOutputFile=%o -- "%i" -c quit' />
; <delegate decode="gs-color" restrain="True" command='C:\Program Files\gs\gs8.64\bin\gswin32c -q -dBATCH -dMaxBitmap=300000000 -dNOPAUSE -dSAFER -sDEVICE=pnmraw -dTextAlphaBits=%u -dGraphicsAlphaBits=%u -g%s -r%s %s -sOutputFile=%s -- "%s" -c quit' />
; <delegate decode="gs-mono" restrain="True" command='C:\Program Files\gs\gs8.64\bin\gswin32c -q -dBATCH -dMaxBitmap=300000000 -dNOPAUSE -dSAFER -sDEVICE=pbmraw -dTextAlphaBits=%u -dGraphicsAlphaBits=%u -g%s -r%s %s -sOutputFile=%s -- "%s" -c quit' />
; <delegate decode="pdf" encode="eps" mode="bi" command='C:\Program Files\gs\gs8.64\bin\gswin32c -q -dBATCH -dMaxBitmap=300000000 -dNOPAUSE -dSAFER -sDEVICE=epswrite -sOutputFile=%o -- "%i" -c quit' />
; <delegate decode="pdf" encode="ps" mode="bi" command='C:\Program Files\gs\gs8.64\bin\gswin32c -q -dBATCH -dMaxBitmap=300000000 -dNOPAUSE -dSAFER -sDEVICE=pswrite -sOutputFile=%o -- "%i" -c quit' />
; <delegate decode="ps" encode="eps" mode="bi" command='C:\Program Files\gs\gs8.64\bin\gswin32c -q -dBATCH -dMaxBitmap=300000000 -dNOPAUSE -dSAFER -sDEVICE=epswrite -sOutputFile=%o -- "%i" -c quit' />
; <delegate decode="ps" encode="pdf" mode="bi" command='C:\Program Files\gs\gs8.64\bin\gswin32c -q -dBATCH -dMaxBitmap=300000000 -dNOPAUSE -dSAFER -sDEVICE=pdfwrite -sOutputFile=%o -- "%i" -c quit' />
; <delegate decode="pdf" encode="jpg" mode="bi" command='C:\Program Files\IrfanView\i_view32.exe "%i" /resample /dpi=(200,200) /jpgq=95 /convert=%o' />
; <delegate decode="pdf" encode="png" mode="bi" command='C:\Program Files\IrfanView\i_view32.exe "%i" /resample /dpi=(200,200) /convert=%o' />
; <delegate decode="pdf" encode="emf" mode="bi" command='C:\Program Files\IrfanView\i_view32.exe "%i" /resample /dpi=(200,200) /convert=%o' />
; <delegate decode="bmp" encode="png" mode="bi" command='C:\Program Files\IrfanView\i_view32.exe "%i" /resample /dpi=(200,200) /convert=%o' />
; <delegate decode="bmp" encode="jpg" mode="bi" command='C:\Program Files\IrfanView\i_view32.exe "%i" /resample /dpi=(200,200) /jpgq=95 /convert=%o' />
; </delegatemap>
;==================================================================================================================================================================================================================================================================