Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.67 KB | None | 0 0
  1. // MonitorScreen.cpp : Defines the entry point for the application. //
  2.  
  3. #include "stdafx.h"
  4. #include "MonitorScreen.h
  5.  
  6. #define MAX_LOADSTRING 100
  7.  
  8. // Global Variables: HINSTANCE hInst; // current instance TCHAR szTitle[MAX_LOADSTRING]; // The title bar text TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
  9.  
  10. // Forward declarations of functions included in this code module: ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
  11.  
  12. int APIENTRY _tWinMain(HINSTANCE hInstance,
  13. HINSTANCE hPrevInstance,
  14. LPTSTR lpCmdLine,
  15. int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine);
  16.  
  17. // TODO: Place code here. MSG msg; HACCEL hAccelTable;
  18.  
  19. // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_MONITORSCREEN, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance);
  20.  
  21. // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; }
  22.  
  23. hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_MONITORSCREEN));
  24.  
  25. // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } }
  26.  
  27. return (int) msg.wParam; }
  28.  
  29.  
  30.  
  31. // // FUNCTION: MyRegisterClass() // // PURPOSE: Registers the window class. // // COMMENTS: // // This function and its usage are only necessary if you want this code // to be compatible with Win32 systems prior to the 'RegisterClassEx' // function that was added to Windows 95. It is important to call this function // so that the application will get 'well formed' small icons associated // with it. // ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex;
  32.  
  33. int s =sizeof(WNDCLASSEX); wcex.cbSize =sizeof(WNDCLASSEX);
  34.  
  35. wcex.style = DESKTOP_HOOKCONTROL ;//CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = NULL;//hInstance; wcex.hIcon = NULL;//LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MONITORSCREEN)); wcex.hCursor = NULL;//LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(9); wcex.lpszMenuName = NULL;//MAKEINTRESOURCE(IDC_MONITORSCREEN); wcex.lpszClassName = szWindowClass; wcex.hIconSm = NULL;//LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  36.  
  37. return RegisterClassEx(&wcex); }
  38.  
  39. // // FUNCTION: InitInstance(HINSTANCE, int) // // PURPOSE: Saves instance handle and creates main window // // COMMENTS: // // In this function, we save the instance handle in a global variable and // create and display the main program window. // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd;
  40.  
  41. hInst = hInstance; // Store instance handle in our global variable
  42.  
  43. hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  44. CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
  45.  
  46. if (!hWnd) {
  47. return FALSE; }
  48.  
  49. ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd);
  50.  
  51. return TRUE; }
  52.  
  53. // // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc;
  54.  
  55. switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent
  56. = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
  57.  
  58. // Message handler for about box. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); switch (message) { case WM_INITDIALOG: return (INT_PTR)TRUE;
  59.  
  60. case WM_COMMAND: if (LOWORD(wParam)
  61. == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); return (INT_PTR)TRUE; } break; } return (INT_PTR)FALSE; }
  62.  
  63. ShowWindow(hWnd, SW_MAXIMIZE);
  64.  
  65. void CaptureScreen(LPCTSTR lpszFilePathName)
  66. {
  67. BITMAPFILEHEADER bmfHeader;
  68. BITMAPINFO *pbminfo;
  69. HBITMAP hBMP;
  70. CFile oFile;
  71.  
  72. CDC *pDC = GetWindowDC();
  73. INT nSizeImage = 1024 * 768 * 3;
  74. CHAR *pBuff = new CHAR[sizeof(BITMAPINFOHEADER) + nSizeImage];
  75. pbminfo = (BITMAPINFO *)pBuff;
  76. hBMP = (HBITMAP)pDC->GetCurrentBitmap()->m_hObject;
  77.  
  78. ZeroMemory(pbminfo, sizeof(BITMAPINFO));
  79.  
  80. pbminfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  81.  
  82. GetDIBits(pDC->m_hDC,
  83. hBMP,
  84. 0,
  85. 1,
  86. NULL,
  87. pbminfo,
  88. DIB_RGB_COLORS);
  89.  
  90. GetDIBits(pDC->m_hDC,
  91. hBMP,
  92. 0,
  93. pbminfo->bmiHeader.biHeight,
  94. pBuff + sizeof(BITMAPINFOHEADER),
  95. pbminfo,
  96. DIB_RGB_COLORS);
  97.  
  98. ReleaseDC(pDC);
  99.  
  100. bmfHeader.bfType = 0x4d42; /*"BM"*/
  101. bmfHeader.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + nSizeImage;
  102. bmfHeader.bfReserved1 = 0;
  103. bmfHeader.bfReserved2 = 0;
  104. bmfHeader.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
  105.  
  106. oFile.Open(lpszFilePathName, CFile::modeWrite | CFile::modeCreate);
  107.  
  108. oFile.Write(&bmfHeader, sizeof(BITMAPFILEHEADER));
  109. oFile.Write(pBuff, sizeof(BITMAPINFOHEADER) + pbminfo->bmiHeader.biSizeImage);
  110. delete []pBuff;
  111. oFile.Close();
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement