Use CaptureWindow.h Use vWin32fh.pkg Use cApplication.pkg Use cIniFile.pkg Define CS_CaptureSection for "Capture" Define CS_CaptureFolder for "Capture Folder" // Declare Function GetActiveWindow% Lib "User" () #IFNDEF Get_GetActiveWindow External_Function GetActiveWindow "GetActiveWindow" User32.dll ; Returns Handle #ENDIF // Declare Function GetDesktopWindow% Lib "User" () #IFNDEF Get_GetDesktopWindow External_Function GetDesktopWindow "GetDesktopWindow" User32.dll ; Returns Handle #ENDIF // Declare Sub GetWindowRect Lib "User" (ByVal Hwnd%, lpRect As RECT_Type) #IFNDEF Get_GetWindowRect External_Function GetWindowRect 'GetWindowRect' User32.dll ; Handle hwnd Pointer lprect Returns Integer #ENDIF // Declare Function GetDC% Lib "User" (ByVal Hwnd%) #IFNDEF Get_GetDC External_Function GetDC "GetDC" User32.dll ; Handle hWnd Returns Integer #ENDIF // Declare Function CreateCompatibleDC% Lib "GDI" (ByVal hdc%) #IFNDEF Get_CreateCompatibleDC External_Function CreateCompatibleDC "CreateCompatibleDC" Gdi32.dll ; Handle hdc ; // Handle to an existing DC. If this handle is NULL, the function creates a memory DC compatible with the application's current screen. Returns Handle // handle to a new memory DC, or null if it fails. #ENDIF // Declare Function CreateCompatibleBitmap% Lib "GDI" (ByVal hdc%, ByVal nWidth%, ByVal nHeight%) #IFNDEF get_CreateCompatibleBitmap External_Function CreateCompatibleBitmap "CreateCompatibleBitmap" gdi32.dll ; Handle hDC ; Integer nWidth ; Integer nHeight ; Returns Handle #ENDIF // Declare Function SelectObject% Lib "GDI" (ByVal hdc%, ByVal hObject%) #IFNDEF Get_SelectObject External_Function SelectObject "SelectObject" Gdi32.dll ; Handle hdc ; // handle to DC Handle hgdiobj; // Handle to the object to be selected. Returns Handle // handle to the object being replaced #ENDIF // Declare Function BitBlt% Lib "GDI" (ByVal hDestDC%, ByVal X%, ByVal Y%, ByVal nWidth%, ; // ByVal nHeight%, ByVal hSrcDC%, ByVal XSrc%, ByVal YSrc%, ByVal dwRop&) #IFNDEF get_BitBlt External_Function BitBlt "BitBlt" gdi32.dll ; Handle hdcDest ; Integer nXDest ; Integer nYDest ; Integer nWidth ; Integer nHeight ; Handle hdcSrc ; Integer nXSrc ; Integer nYSrc ; Integer dwRop ; Returns Boolean #ENDIF // Declare Function OpenClipboard% Lib "User" (ByVal Hwnd%) #IFNDEF Get_OpenClipboard External_Function OpenClipboard "OpenClipboard" User32.dll ; Handle hWnd Returns Integer #ENDIF // Declare Function EmptyClipboard% Lib "User" () #IFNDEF Get_EmptyClipboard External_Function EmptyClipboard "EmptyClipboard" User32.dll ; Returns Integer #ENDIF // Declare Function SetClipboardData% Lib "User" (ByVal wFormat%, ByVal hMem%) #IFNDEF Get_SetClipboardData External_Function SetClipboardData "SetClipboardData" User32.dll ; Integer wFormat Handle hMem Returns Integer #ENDIF // Declare Function CloseClipboard% Lib "User" () #IFNDEF Get_CloseClipboard External_Function CloseClipboard "CloseClipboard" User32.dll ; Returns Integer #ENDIF // Declare Function ReleaseDC% Lib "User" (ByVal Hwnd%, ByVal hdc%) #IFNDEF Get_ReleaseDC External_Function ReleaseDC "ReleaseDC" User32.dll ; Handle hWnd Handle hDC Returns Integer #ENDIF // Declare Function DeleteDC% Lib "GDI" (ByVal hdc%) #IFNDEF Get_DeleteDC External_Function DeleteDC "DeleteDC" Gdi32.dll ; Handle hdc ; // Handle to the device context being deleted. Returns Boolean // True if successful. #ENDIF #IFNDEF Get_CreateDIBSection External_Function CreateDIBSection "CreateDIBSection" Gdi32.dll ; Handle hdc ; // Handle to the device context pointer pbmi ; //puntero a BITMAPINFO UInteger iUsage ; Pointer ppvBits ; Handle hSection ; DWord dwOffset ; Returns Handle // HBITMAP #ENDIF #IFNDEF Get_GetDIBits External_Function GetDIBits "GetDIBits" Gdi32.dll ; handle hdc ; handle hbmp ; Uinteger uStartScan ; uinteger cScanLines ; pointer lpvBits ; pointer lpbi ; // LPBITMAPINFO uinteger uUsage ; Returns Integer #ENDIF #IFNDEF Get_Createfile External_Function Createfile "CreateFileA" kernel32.dll ; Pointer lpFile ; //filename DWord dwDesAccess ; // access mode DWord dwShare ; // share mode Pointer lpSecAtt ; // SD DWord dwCrDisp ; // how to create DWord dwFlags ; // file attributes Handle hTempFile ; // handle to template fil Returns Integer //Returns handle that can be used to access the object #ENDIF #IFNDEF Get_WriteFile External_Function WriteFile "WriteFile" Kernel32.dll ; Handle hFile ; // Handle to the file Pointer lpBuffer ; // data buffer DWord nNumberOfBytesToWrite ; Pointer lpNumberOfBytesWritten ; Pointer lpOverlapped ; Returns Boolean #ENDIF #IFNDEF Get_CloseHandle External_Function CloseHandle "CloseHandle" kernel32.dll ; Handle hObject ; // handle to object Returns Integer #ENDIF #IFNDEF Get_GetDeviceCaps External_Function GetDeviceCaps "GetDeviceCaps" Gdi32.dll ; Handle hdc ; // Handle to the device context integer nIndex ; // function Returns Integer #ENDIF #IFNDEF Get_GetDIBColorTable External_Function GetDIBColorTable "GetDIBColorTable" Gdi32.dll ; handle hdc ; uinteger uStartIndex ; uinteger cEntries ; pointer pColors ; Returns Integer #ENDIF #IFNDEF Get_GetObject External_Function GetObject "GetObjectA" Gdi32.dll ; handle hgdiobj ; integer cbBuffer ; pointer lpvObject ; Returns Integer #ENDIF #IFNDEF Get_DeleteObject External_Function DeleteObject "DeleteObject" Gdi32.dll ; Handle hObject Returns Boolean #ENDIF // Check if focus is what you search or a child of it Function Find_Parent Global Handle hofocus Handle hofind Returns Boolean If (hoFocus = hoFind) Begin Function_Return True End While (hofocus>Desktop) If (Parent(hoFocus) = hoFind) Begin Function_Return True End Move (Parent(hofocus)) to hofocus Loop Function_Return False End_Function // Returns the view object (outmost container) of the currently focused object. Function Current_View Global Returns Integer Integer Obj# Move (Focus(Self)) to Obj# Repeat Move (Parent(Obj#)) to Obj# Until (Scope_State(Obj#) = True) Function_Return Obj# End_Function // Helper function. See also main message TakeSnapshot. // Capture an bitmap image of the current object and saves it to disk. Function CaptureImage Global Handle hVent String sFile Returns Integer Handle hwnd deskhwnd hfile hnulo Handle hdcScreen Handle hdcWindow Handle hdcMemDC Handle hbmScreen BITMAP bmpScreen BITMAPFILEHEADER bmfHeader BITMAPINFOHEADER bi RECT_Type rcClient Integer junk fwidth fheight iret DWord dwSizeofDIB dwBytesWritten dwBmpSize Boolean baux Pointer lpbitmap pnulo //--------------------------------------------------- // Get window handle to Windows and our View //--------------------------------------------------- Move (GetDesktopWindow()) to DeskHwnd Get Window_Handle of hVent to hwnd // Retrieve the handle to a display device context for the client // area of the window. Move (GetDC(hwnd)) to hdcScreen //what you want to paint (getdc(null)=full screen) Move (GetDC(deskhwnd)) to hdcWindow //context = GetDC(hWnd); // Create a compatible DC which is used in a BitBlt from the window DC Move (CreateCompatibleDC(hdcWindow)) to hdcMemDC Move 0 to iret If (hdcMemDC) Begin // Get the client area for size calculation Move (GetWindowRect(hwnd,AddressOf(rcClient))) to junk Move (rcClient.iright-rcClient.ileft) to fwidth Move (rcClient.ibottom-rcClient.itop) to fheight // Create a compatible bitmap from the Window DC Move (CreateCompatibleBitmap(hdcWindow, fwidth, fheight)) to hbmScreen If hbmScreen Begin // Select the compatible bitmap into the compatible memory DC. Move (SelectObject(hdcMemDC,hbmScreen)) to junk // Bit block transfer into our compatible memory DC. If (BitBlt(hdcMemDC,0,0, fwidth, fheight,hdcWindow, rcClient.ileft,rcClient.itop,SRCCOPY)) Begin // Get the BITMAP from the HBITMAP Move (GetObject(hbmScreen,SizeOfType(BITMAP),AddressOf(bmpScreen))) to junk Move (SizeOfType(BITMAPINFOHEADER)) to bi.biSize Move bmpScreen.bmWidth to bi.biWidth Move bmpScreen.bmHeight to bi.biHeight Move 1 to bi.biPlanes Move 32 to bi.biBitCount Move bi_rgb to bi.biCompression Move 0 to bi.biSizeImage Move 0 to bi.biXPelsPerMeter Move 0 to bi.biYPelsPerMeter Move 0 to bi.biClrUsed Move 0 to bi.biClrImportant Move (((bmpScreen.bmWidth * bi.biBitCount + 31) / 32) * 4 * bmpScreen.bmHeight ) to dwBmpSize Move (Alloc(dwBmpSize+100)) to lpbitmap // Gets the "bits" from the bitmap and copies them into a buffer // which is pointed to by lpbitmap. Move (GetDIBits(hdcWindow, hbmScreen, 0,bmpScreen.bmHeight, ; lpbitmap,AddressOf(bi), DIB_RGB_COLORS) ) to junk // A file is created, this is where we will save the screen capture. Move (CreateFile(AddressOf(sFile),GENERIC_WRITE, 0, ; hnulo,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL, hnulo)) to hfile // Add the size of the headers to the size of the bitmap to get the total file size Move (dwBmpSize + SizeOfType(BITMAPFILEHEADER) + SizeOfType(BITMAPINFOHEADER)) to dwSizeofDIB // Offset to where the actual bitmap bits start. Move (SizeOfType(BITMAPFILEHEADER) + SizeOfType(BITMAPINFOHEADER)) to bmfHeader.bfOffBits // Size of the file Move dwSizeofDIB to bmfHeader.bfSize // bfType must always be BM for Bitmaps Move 19778 to bmfHeader.bfType //= 0x4D42; //BM 19778 Move 0 to dwBytesWritten Move (WriteFile(hFile, AddressOf(bmfHeader), SizeOfType(BITMAPFILEHEADER), AddressOf(dwBytesWritten), pnulo)) to baux Move (WriteFile(hFile, AddressOf(bi), SizeOfType(BITMAPINFOHEADER), AddressOf(dwBytesWritten), pnulo)) to baux Move (WriteFile(hFile, lpbitmap, dwBmpSize, AddressOf(dwBytesWritten), pnulo)) to baux //Close the handle for the file that was created Move (CloseHandle(hFile)) to junk // Write image from clipboard Move (OpenClipboard(DeskHwnd)) to junk Move (EmptyClipboard()) to junk Move (SetClipboardData(CF_BITMAP,hbmScreen)) to junk Move (CloseClipboard()) to junk Move (DeleteObject(hbmScreen)) to baux Move (Free(lpbitmap)) to baux Move 1 to iret End End End Move (ReleaseDC(hWnd, hdcMemDC)) to junk Move (ReleaseDC(hwnd,hdcScreen)) to junk Move (ReleaseDC(deskhwnd,hdcWindow)) to junk Function_Return iret End_Function // *** MAIN MESSAGE *** // Takes a snapshot of the currently active view and saves it as a bitmap file, // in the current workspace's Capture folder. If that folder doesn't exist, // it will be created. // Pass False to take snapshot of the currently active view, or pass True // to take snapshot of the entire application. Procedure TakeSnapshot Global Boolean bApplicationShot Integer iRetval String sPath sToday sFileName Handle hObjTo Sysdate sToday Move (Replace("/", sToday, "-")) to sToday // Select the view to capture If (bApplicationShot = False) Begin Get Current_View to hObjTo End Else Begin Move (Parent(ghoCommandBars)) to hObjTo End Get SnapShotFolder to sPath Get vFolderFormat sPath to sPath Move (sPath + (Object_Label(hObjTo)) + sToday + ".bmp") to sFileName Get CaptureImage hObjTo sFileName to iRetval If (iRetval <> 0) Begin // Send Info_Box ("The snapshot image was saved here:\n" + sPath) Move ("/select, " + sFileName) to sFileName Send vShellExecute "open" "explorer.exe" sFileName "" // Runprogram Shell Background sFileName End End_Procedure // Function to get the folder where snapshots are saved. // The pathing is read from the esqtid.ini file. // Returns the full folder path. If the folder doesn't exist // it will be created. // Returns: The full snapshot folder path. Function SnapShotFolder Global Returns String String sHome sPath sWorkSpaceFile Boolean bExist Integer iRetval Handle hoIniFile Get psWorkspaceWSFile of (phoWorkspace(ghoApplication)) to sWorkSpaceFile Get psHome of (phoWorkspace(ghoApplication)) to sHome Get vFolderFormat sHome to sHome Get Create (RefClass(cIniFile)) to hoIniFile Set psFileName of hoIniFile to sWorkSpaceFile Get ReadString of hoIniFile CS_CaptureSection CS_CaptureFolder CS_CaptureSection to sPath Send Destroy of hoIniFile If (Pos("..\", sPath)) Begin Move (Replace("..\", sPath, "")) to sPath Move (sHome + sPath) to sPath End Else If (Pos(".\", sPath)) Begin Move (Replace(".\", sPath, "")) to sPath Move (sHome + sPath) to sPath End Else Begin Move (sHome + sPath) to sPath End Get vFolderExists sPath to bExist If (bExist = False) Begin If (sPath = "") Begin Get vSHGetFolderPath vCSIDL_MYPICTURES to sPath // E.g. "C:\Documents and Settings\username\My Documents\My Pictures" End Else Begin Get vCreateDirectory sPath to iRetval If (iRetval <> 0) Begin Send Info_Box ("Could not create the 'Capture' folder for saving shapshots to." * sPath) Function_Return "" End End End Function_Return sPath End_Function