截取屏幕截图

Orr*_*ren 3 c screenshot image screen

即时尝试使用此代码:

bool SaveBMPFile(char *filename, HBITMAP bitmap, HDC bitmapDC, int width, int height);

bool ScreenCapture(int x, int y, int width, int height, char *filename){
// get a DC compat. w/ the screen
HDC hDc = CreateCompatibleDC(0);

// make a bmp in memory to store the capture in
HBITMAP hBmp = CreateCompatibleBitmap(GetDC(0), width, height);

// join em up
SelectObject(hDc, hBmp);

// copy from the screen to my bitmap
BitBlt(hDc, 0, 0, width, height, GetDC(0), x, y, SRCCOPY);

// save my bitmap
bool ret = SaveBMPFile(filename, hBmp, hDc, width, height);

// free the bitmap memory
DeleteObject(hBmp);

return ret;
}
Run Code Online (Sandbox Code Playgroud)

它抛出这些错误:

bot.c|185|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'SaveBMPFile'|
bot.c|187|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'ScreenCapture'|
Run Code Online (Sandbox Code Playgroud)

我能做什么?尝试不同的代码将无法正常工作,并尝试使用Gdi + - 也错误.

Dan*_*ing 6

我想你错过了#include <stdbool.h>.

bool不是C中的原始类型.必须包含<stdbool.h>标题才能获得其定义.