我可以在不使用atlimage.h的情况下截取当前屏幕的截图吗?

时间:2017-01-17 11:07:18

标签: c++ winapi screenshot

如何在不使用atlimage.h的情况下截取当前屏幕的截图?

我尝试了几次似乎不需要#include <iostream> #include <windows.h> using namespace std; void GetScreenShot(void) { int x1, y1, x2, y2, w, h; // get screen dimensions x1 = GetSystemMetrics(SM_XVIRTUALSCREEN); y1 = GetSystemMetrics(SM_YVIRTUALSCREEN); x2 = GetSystemMetrics(SM_CXVIRTUALSCREEN); y2 = GetSystemMetrics(SM_CYVIRTUALSCREEN); w = x2 - x1; h = y2 - y1; // copy screen to bitmap HDC hScreen = GetDC(NULL); HDC hDC = CreateCompatibleDC(hScreen); HBITMAP hBitmap = CreateCompatibleBitmap(hScreen, w, h); HGDIOBJ old_obj = SelectObject(hDC, hBitmap); BOOL bRet = BitBlt(hDC, 0, 0, w, h, hScreen, x1, y1, SRCCOPY); // save bitmap to clipboard OpenClipboard(NULL); EmptyClipboard(); SetClipboardData(CF_BITMAP, hBitmap); CloseClipboard(); // clean up SelectObject(hDC, old_obj); DeleteDC(hDC); ReleaseDC(NULL, hScreen); DeleteObject(hBitmap); } 的尝试,但我从链接器中获得了许多未解决的外部错误,可以通过添加atlimage来解决。

下面你可以看到我的一次尝试:

Error   LNK1120 13 unresolved externals ScreenShot          
Error   LNK2019 unresolved external symbol __imp__BitBlt@36 referenced in function "void __cdecl GetScreenShot(void)" (?GetScreenShot@@YAXXZ)   ScreenShot      
Error   LNK2019 unresolved external symbol __imp__CloseClipboard@0 referenced in function "void __cdecl GetScreenShot(void)" (?GetScreenShot@@YAXXZ)    ScreenShot      
Error   LNK2019 unresolved external symbol __imp__CreateCompatibleBitmap@12 referenced in function "void __cdecl GetScreenShot(void)" (?GetScreenShot@@YAXXZ)   ScreenShot      
Error   LNK2019 unresolved external symbol __imp__CreateCompatibleDC@4 referenced in function "void __cdecl GetScreenShot(void)" (?GetScreenShot@@YAXXZ)    ScreenShot      
Error   LNK2019 unresolved external symbol __imp__DeleteDC@4 referenced in function "void __cdecl GetScreenShot(void)" (?GetScreenShot@@YAXXZ)  ScreenShot  
Error   LNK2019 unresolved external symbol __imp__DeleteObject@4 referenced in function "void __cdecl GetScreenShot(void)" (?GetScreenShot@@YAXXZ)  ScreenShot  
Error   LNK2019 unresolved external symbol __imp__EmptyClipboard@0 referenced in function "void __cdecl GetScreenShot(void)" (?GetScreenShot@@YAXXZ)    ScreenShot      
Error   LNK2019 unresolved external symbol __imp__GetDC@4 referenced in function "void __cdecl GetScreenShot(void)" (?GetScreenShot@@YAXXZ) ScreenShot      
Error   LNK2019 unresolved external symbol __imp__GetSystemMetrics@4 referenced in function "void __cdecl GetScreenShot(void)" (?GetScreenShot@@YAXXZ)  ScreenShot      
Error   LNK2019 unresolved external symbol __imp__OpenClipboard@4 referenced in function "void __cdecl GetScreenShot(void)" (?GetScreenShot@@YAXXZ) ScreenShot      
Error   LNK2019 unresolved external symbol __imp__ReleaseDC@8 referenced in function "void __cdecl GetScreenShot(void)" (?GetScreenShot@@YAXXZ) ScreenShot      
Error   LNK2019 unresolved external symbol __imp__SelectObject@8 referenced in function "void __cdecl GetScreenShot(void)" (?GetScreenShot@@YAXXZ)  ScreenShot  
Error   LNK2019 unresolved external symbol __imp__SetClipboardData@8 referenced in function "void __cdecl GetScreenShot(void)" (?GetScreenShot@@YAXXZ)  ScreenShot  

我的错误是:

[
   {
       id: "38485ndndndn4848",
       value : 120, // kw
       ts: 1456983266,
       sensor_id: 20
   },
   {
       id: "48485ndndndn4848",
       value : 189, //kw
       ts: 1456984286,
      sensor_id: 20
   },
   {
       id: "98485ndndndn4848",
       value : 99, // kw
       ts: 1457984286,
       sensor_id: 21
   },
  {
       id: "64640485ndndndn4848",
       value : 56,  // kw
       ts: 1458984286,
       sensor_id: 21
   }
.
.
.
]

0 个答案:

没有答案