I am lucky to find this nice forum. I am beginner in C++ and I am getting error in my program to capture content of Window. Any help?

h
Qt Code:
  1. #include "targetver.h"
  2. #include <stdio.h>
  3. #include <tchar.h>
  4. #include <windows.h>
  5. #include <fstream>
  6. #include <stdio.h>
  7. #include <wingdi.h>
  8. #include <gdiplus.h>
  9. #include <ostream>
To copy to clipboard, switch view to plain text mode 

cpp
Qt Code:
  1. /*Window capture example*/
  2. //using namespace Gdiplus;
  3.  
  4. #include "stdafx.h"
  5. #define SCREENWIDTH GetSystemMetrics(SM_CXSCREEN)
  6. #define SCREENHEIGHT GetSystemMetrics(SM_CYSCREEN)
  7.  
  8. // HBITMAP g_hDeskBmp;
  9. HDC g_hMemDC;
  10. int g_nDCdata;
  11.  
  12. int main()
  13. {
  14. // get desktop window handle (but can be handle of any window)
  15. HWND HCapture = FindWindow(NULL, _T("Map Viewer") );
  16. // HWND HCapture = GetDesktopWindow();
  17. if(!IsWindow(HCapture)) return 1;
  18.  
  19. /*
  20.  BOOL PrintWindow(
  21.   HWND hwnd, // A handle to the window that will be copied.
  22.   HDC hdcBlt, // A handle to the device context.
  23.   UINT nFlags // The drawing options: PW_CLIENTONLY
  24.   // Only the client area of the window is copied to hdcBlt. By default, the entire window is copied.
  25. );
  26. */
  27.  
  28. // get window dimensions
  29. RECT rect;
  30. GetWindowRect(HCapture, &rect);
  31.  
  32. size_t dx = rect.right - rect.left;
  33. size_t dy = rect.bottom - rect.top;
  34.  
  35. // create BITMAPINFO structure
  36. // used by CreateDIBSection
  37. BITMAPINFO info;
  38. info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  39. info.bmiHeader.biWidth = dx;
  40. info.bmiHeader.biHeight = dy;
  41. info.bmiHeader.biPlanes = 1;
  42. info.bmiHeader.biBitCount = 24;
  43. info.bmiHeader.biCompression = BI_RGB;
  44. info.bmiHeader.biSizeImage = 0;
  45. info.bmiHeader.biXPelsPerMeter = 0;
  46. info.bmiHeader.biYPelsPerMeter = 0;
  47. info.bmiHeader.biClrUsed = 0;
  48. info.bmiHeader.biClrImportant = 0;
  49.  
  50. // a bitmap handle and a pointer its bit data
  51. HBITMAP HBitmap = 0;
  52. BYTE* memory = 0;
  53.  
  54. /** We should create Bitmap first and then Device Context,
  55.   however when I want to create snapshot of window, I need to use
  56. fnc PrintWindow to copy the visual window to Device Context.
  57. So I need to create DC first. The DC will be compatible with
  58. current screen.
  59.  */
  60.  
  61. // 1. FIRST we need to Create DC for PrintWindow function
  62. // HDC device = GetDC(HCapture);
  63. HDC device = CreateCompatibleDC(NULL);
  64.  
  65. // 2. SECOND we need to CREATE BITMAP (Device Independent Bitmap)
  66. // bitmap = CreateDIBSection(device, &info, DIB_RGB_COLORS, (void**)&memory, 0, 0);
  67. unsigned int * pBitmap;
  68.  
  69. if (!PrintWindow(HCapture, device, PW_CLIENTONLY)) return 2;
  70. HBitmap = GdipCreateBitmapFromHBITMAP(HBitmap, 0, pBitmap);
  71. ReleaseDC(HCapture, device);
  72. if(!HBitmap || !memory) return 1;
  73.  
  74. // blit the contents of the desktop (winDC)
  75. // to the bitmap (selected in memDC)
  76. HDC winDC = GetWindowDC(HCapture);
  77. HDC memDC = CreateCompatibleDC(winDC);
  78. SelectObject(memDC, HBitmap);
  79. BitBlt(memDC, 0, 0, dx, dy, winDC, 0, 0, SRCCOPY);
  80. DeleteDC(memDC);
  81. ReleaseDC(HCapture, winDC);
  82.  
  83. /** THIS IS WRONG! VARIABLE CANNOT POINT TO NOWHERE!*/
  84. // char *buffer; // First set the type and range and then make pointer:
  85. char *buffer = new char[50]; // RIGHT DECLARATION
  86. sprintf(buffer,"capture%d%d.bmp",dx,dy);
  87. // create bitmap file
  88. std::basic_ofstream <char> file(buffer, std::ios::binary);
  89. if(!file) { DeleteObject(HBitmap); return 1; }
  90.  
  91. // initialize bitmap file headers
  92. BITMAPFILEHEADER fileHeader;
  93. BITMAPINFOHEADER infoHeader;
  94.  
  95. fileHeader.bfType = 0x4d42;
  96. fileHeader.bfSize = 0;
  97. fileHeader.bfReserved1 = 0;
  98. fileHeader.bfReserved2 = 0;
  99. fileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
  100.  
  101. infoHeader.biSize = sizeof(infoHeader);
  102. infoHeader.biWidth = dx;
  103. infoHeader.biHeight = dy;
  104. infoHeader.biPlanes = 1;
  105. infoHeader.biBitCount = 24;
  106. infoHeader.biCompression = BI_RGB;
  107. infoHeader.biSizeImage = 0;
  108. infoHeader.biXPelsPerMeter = 0;
  109. infoHeader.biYPelsPerMeter = 0;
  110. infoHeader.biClrUsed = 0;
  111. infoHeader.biClrImportant = 0;
  112.  
  113. // save file headers
  114. file.write((char*)&fileHeader, sizeof(fileHeader));
  115. file.write((char*)&infoHeader, sizeof(infoHeader));
  116.  
  117. // save 24-bit bitmap data
  118. int wbytes = (((24*dx + 31) & (~31))/8);
  119. int tbytes = (((24*dx + 31) & (~31))/8)*dy;
  120. file.write((char*)memory, tbytes);
  121. // delete bitmap
  122. DeleteObject(HBitmap);
  123. HBitmap = 0;
  124. memory = 0;
  125. return 0;
  126. //......................................................................................
  127. }
To copy to clipboard, switch view to plain text mode 

Error:
error C3861: 'GdipCreateBitmapFromHBITMAP': identifier not found