PageRenderTime 22ms CodeModel.GetById 13ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/reporting/crashsender/ScreenCap.h

http://crashrpt.googlecode.com/
C++ Header | 180 lines | 104 code | 37 blank | 39 comment | 0 complexity | 01426dcdd9563939e1e2b16c63242914 MD5 | raw file
  1/************************************************************************************* 
  2This file is a part of CrashRpt library.
  3Copyright (c) 2003-2013 The CrashRpt project authors. All Rights Reserved.
  4
  5Use of this source code is governed by a BSD-style license
  6that can be found in the License.txt file in the root of the source
  7tree. All contributing project authors may
  8be found in the Authors.txt file in the root of the source tree.
  9***************************************************************************************/
 10
 11#ifndef __SCREENCAP_H__
 12#define __SCREENCAP_H__
 13
 14#include "stdafx.h"
 15
 16extern "C" {
 17#include "png.h"
 18}
 19#include "jpeglib.h"
 20
 21// Window information
 22struct WindowInfo
 23{
 24    CString m_sTitle; // Window title
 25    CRect m_rcWnd;    // Window rect
 26    DWORD dwStyle;
 27    DWORD dwExStyle;
 28};
 29
 30// Monitor info
 31struct MonitorInfo
 32{
 33    CString m_sDeviceID; // Device ID
 34    CRect m_rcMonitor;   // Monitor rectangle in screen coordinates
 35    CString m_sFileName; // Image file name corresponding to this monitor
 36};
 37
 38// Desktop screen shot info
 39struct ScreenshotInfo
 40{
 41	// Constructor
 42    ScreenshotInfo()
 43    {
 44        m_bValid = FALSE;
 45    }
 46
 47    BOOL m_bValid;           // If TRUE, this structure's fields are valid.
 48	time_t m_CreateTime;     // Time of screenshot capture.
 49    CRect m_rcVirtualScreen; // Coordinates of virtual screen rectangle.
 50    std::vector<MonitorInfo> m_aMonitors; // The list of monitors captured.
 51    std::vector<WindowInfo> m_aWindows; // The list of windows captured.	
 52};
 53
 54// Screenshot type
 55enum SCREENSHOT_TYPE
 56{
 57	SCREENSHOT_TYPE_VIRTUAL_SCREEN      = 0, // Screenshot of entire desktop.
 58	SCREENSHOT_TYPE_MAIN_WINDOW         = 1, // Screenshot of given process' main window.
 59	SCREENSHOT_TYPE_ALL_PROCESS_WINDOWS = 2  // Screenshot of all process windows.
 60};
 61
 62// What format to use when saving screenshots
 63enum SCREENSHOT_IMAGE_FORMAT
 64{
 65    SCREENSHOT_FORMAT_PNG = 0, // Use PNG format
 66    SCREENSHOT_FORMAT_JPG = 1, // Use JPG format
 67    SCREENSHOT_FORMAT_BMP = 2  // Use BMP format
 68};
 69
 70// Desktop screenshot capture
 71class CScreenCapture
 72{
 73public:
 74
 75    // Constructor.
 76    CScreenCapture();
 77
 78	// Destructor.
 79    ~CScreenCapture();
 80	
 81	// Takes desktop screenshot and returns information about it.
 82	BOOL TakeDesktopScreenshot(	
 83			LPCTSTR szSaveToDir,
 84			ScreenshotInfo& ssi, 
 85			SCREENSHOT_TYPE type=SCREENSHOT_TYPE_VIRTUAL_SCREEN, 
 86			DWORD dwProcessId = 0, 
 87			SCREENSHOT_IMAGE_FORMAT fmt=SCREENSHOT_FORMAT_PNG,
 88			int nJpegQuality = 95,
 89			BOOL bGrayscale=FALSE,
 90			int nIdStartFrom=0);
 91
 92private:
 93
 94	// Returns current virtual screen rectangle
 95    void GetScreenRect(LPRECT rcScreen);
 96
 97    // Returns an array of visible windows for the specified process or 
 98    // the main window of the process.
 99    BOOL FindWindows(DWORD dwProcessId, BOOL bAllProcessWindows, 
100        std::vector<WindowInfo>* paWindows);
101
102    // Captures the specified screen area and returns the list of image files
103    BOOL CaptureScreenRect(
104        std::vector<CRect> arcCapture, 
105        CString sSaveDirName, 
106        int nIdStartFrom, 
107        SCREENSHOT_IMAGE_FORMAT fmt, 
108        int nJpegQuality,
109        BOOL bGrayscale,
110        std::vector<MonitorInfo>& monitor_list);
111
112	// Monitor enumeration callback.
113	static BOOL CALLBACK EnumMonitorsProc(HMONITOR hMonitor, 
114		HDC /*hdcMonitor*/, LPRECT lprcMonitor, LPARAM dwData);
115
116	// Window enumeration callback.
117	static BOOL CALLBACK EnumWndProc(HWND hWnd, LPARAM lParam);
118
119    /* PNG management functions */
120
121    // Initializes PNG file header
122    BOOL PngInit(int nWidth, int nHeight, BOOL bGrayscale, CString sFileName);
123
124    // Writes a scan line to the PNG file
125    BOOL PngWriteRow(LPBYTE pRow, int nRowLen, BOOL bGrayscale);
126
127    // Closes PNG file
128    BOOL PngFinalize();
129
130    /* JPEG management functions */
131
132	// Initializes JPEG file header.
133    BOOL JpegInit(int nWidth, int nHeight, BOOL bGrayscale, int nQuality, CString sFileName);
134
135	// Writes a scan line to JPEG file.
136    BOOL JpegWriteRow(LPBYTE pRow, int nRowLen, BOOL bGrayscale);
137
138	// Closes PNG file.
139    BOOL JpegFinalize();
140
141	/* BMP management functions */
142
143	// Initializes BMP file header
144    BOOL BmpInit(int nWidth, int nHeight, BOOL bGrayscale, CString sFileName);
145
146    // Writes a scan line to the BMP file
147    BOOL BmpWriteRow(LPBYTE pRow, int nRowLen, BOOL bGrayscale);
148
149    // Closes BMP file
150    BOOL BmpFinalize();
151
152	// The following structure stores window find data.
153	struct FindWindowData
154	{
155		DWORD dwProcessId;                   // Process ID.
156		BOOL bAllProcessWindows;             // If TRUE, finds all process windows, else only the main one
157		std::vector<WindowInfo>* paWindows;  // Output array of window handles
158	};
159
160    /* Internal member variables. */
161
162    CPoint m_ptCursorPos;                 // Current mouse cursor pos
163    std::vector<CRect> m_arcCapture;      // Array of capture rectangles
164    CURSORINFO m_CursorInfo;              // Cursor info  
165    int m_nIdStartFrom;                   // An ID for the current screenshot image 
166    CString m_sSaveDirName;               // Directory name to save screenshots to
167    SCREENSHOT_IMAGE_FORMAT m_fmt;        // Image format
168    int m_nJpegQuality;                   // Jpeg quality
169    BOOL m_bGrayscale;                    // Create grayscale image or not
170    FILE* m_fp;                           // Handle to the file
171    png_structp m_png_ptr;                // libpng stuff
172    png_infop m_info_ptr;                 // libpng stuff
173    struct jpeg_compress_struct m_cinfo;  // libjpeg stuff
174    struct jpeg_error_mgr m_jerr;         // libjpeg stuff
175    std::vector<MonitorInfo> m_monitor_list; // The list of monitor devices   
176};
177
178#endif //__SCREENCAP_H__
179
180