Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <windows.h>
  2. #include <vector>
  3. #include <chrono>
  4. #include <numeric>
  5.  
  6. int main()
  7. {
  8.     std::vector<unsigned long long> times(40);
  9.     HDC hdcScreen = ::GetDC(HWND_DESKTOP);
  10.     HDC hdcShot = ::CreateCompatibleDC(hdcScreen);
  11.     int cx = GetDeviceCaps(hdcScreen, HORZRES);
  12.     int cy = GetDeviceCaps(hdcScreen, VERTRES);
  13.     HGDIOBJ hbmpShot = ::CreateCompatibleBitmap(hdcScreen, cx, cy);
  14.     hbmpShot = SelectObject(hdcShot, hbmpShot);
  15.     for( size_t i = times.size(); i--; ) {
  16.         auto start = std::chrono::high_resolution_clock::now();
  17.         ::BitBlt(hdcShot, 0, 0, cx, cy, hdcScreen, 0, 0, SRCCOPY);
  18.         auto finish = std::chrono::high_resolution_clock::now();
  19.         times[i] = std::chrono::duration_cast<std::chrono::milliseconds>(finish - start).count();
  20.     }
  21.     ::ReleaseDC(HWND_DESKTOP, hdcScreen);
  22.     hbmpShot = SelectObject(hdcShot, hbmpShot);
  23.     ::DeleteObject(hbmpShot);
  24.     ::DeleteDC(hdcShot);
  25.     printf("Time: %f\n", double(std::accumulate(times.begin(), times.end(), (unsigned long long)0)) / times.size());
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement