Сделал в заголовочном файле объявления типов наподобие:
typedef long(__stdcall*GDIPLUSSTARTUP)(unsigned long*, const GDIPLUS_STARTUP_INPUT*, void*);В
cpp-файле
GDIPLUSSTARTUP GdiplusStartup;Также и по остальным функциям:
GdiplusShutdown, GdipCreateBitmapFromHBITMAP etc.
Для компилятора типы
Bitmap и
Image неизвестны:
c:\createjpg\createjpg\savescreen.cpp(194) : error C2065: 'Bitmap' : undeclared identifier
c:\createjpg\createjpg\savescreen.cpp(194) : error C2065: 'bmp' : undeclared identifier
c:\createjpg\createjpg\savescreen.cpp(194) : error C2061: syntax error : identifier 'Bitmap'
c:\createjpg\createjpg\savescreen.cpp(195) : error C2065: 'Image' : undeclared identifier
c:\createjpg\createjpg\savescreen.cpp(195) : error C2065: 'img' : undeclared identifier
c:\createjpg\createjpg\savescreen.cpp(195) : error C2065: 'bmp' : undeclared identifier
c:\createjpg\createjpg\savescreen.cpp(195) : error C2227: left of '->GetThumbnailImage' must point to class/struct/union/generic type
type is ''unknown-type''
c:\createjpg\createjpg\savescreen.cpp(201) : error C2065: 'EncoderQuality' : undeclared identifier
c:\createjpg\createjpg\savescreen.cpp(208) : error C2065: 'bmp' : undeclared identifier
c:\createjpg\createjpg\savescreen.cpp(208) : error C2541: 'delete' : cannot delete objects that are not pointers
c:\createjpg\createjpg\savescreen.cpp(209) : error C2065: 'img' : undeclared identifier
c:\createjpg\createjpg\savescreen.cpp(209) : error C2541: 'delete' : cannot delete objects that are not pointers
Как их объявлять?
// Сохраннение в файл на диске в формате JPG
int SaveScreenShotJPG()
{
int result = 0;
//Остатки прошлого кода, когда GDI+ линковался статически
//ULONG_PTR gdiplusToken;
//GdiplusStartupInput gdiplusStartupInput;
//GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
// В ней мы вызываем LoadLibrary(...) и получаем адреса функций через GetProcAddress()
InitDeinitGdiPlus(true);
int Width, Height;
HDC scrdc, memdc;
HBITMAP membit;
scrdc = GetDC(0);
Height = GetSystemMetrics(SM_CYSCREEN);
Width = GetSystemMetrics(SM_CXSCREEN);
memdc = CreateCompatibleDC(scrdc);
membit = CreateCompatibleBitmap(scrdc, Width, Height);
SelectObject(memdc, membit);
BitBlt(memdc, 0, 0, Width, Height, scrdc, 0, 0, SRCCOPY);
Bitmap *bmp = new Bitmap(membit, NULL);
Image *img = bmp->GetThumbnailImage(Width, Height);
CLSID imgClsid;
//EncoderParameters encoderParams;
ENCODER_PARAMETERS encoderParams;
int quality = 65;
encoderParams.Count = 1;
encoderParams.Parameter[0].Guid = EncoderQuality;
encoderParams.Parameter[0].Type = 4;
encoderParams.Parameter[0].NumberOfValues = 1;
encoderParams.Parameter[0].Value = &quality;
//GetEncoderClsid(L"image/jpeg", &imgClsid);
//result = img->Save(L"Z:\\ImageDesktop.jpeg", &imgClsid, &encoderParams);
delete bmp;
delete img;
//GdiplusShutdown(gdiplusToken);
InitDeinitGdiPlus(false);
DeleteObject(membit);
DeleteObject(memdc);
ReleaseDC(0, scrdc);
return result;
}