#include "stdafx.h"
#include <gdiplus.h>
using namespace Gdiplus;
int GetEncoderClsid( const WCHAR * format, CLSID * pClsid )
{
UINT num = 0;
UINT size = 0;
ImageCodecInfo * pImageCodecInfo = NULL;
GetImageEncodersSize( & num, & size );
if( size == 0 )
return - 1;
pImageCodecInfo =( ImageCodecInfo * )( malloc( size ) );
if( pImageCodecInfo == NULL )
return - 1;
GetImageEncoders( num, size, pImageCodecInfo );
for( UINT j = 0; j < num; ++j )
{
if( wcscmp( pImageCodecInfo[ j ].MimeType, format ) == 0 )
{
* pClsid = pImageCodecInfo[ j ].Clsid;
free( pImageCodecInfo );
return j;
}
}
free( pImageCodecInfo );
return - 1;
}
void ScreenShot( void )
{
HGLOBAL hMem;
HDC hdcScreen = CreateDC( _T( "DISPLAY" ), NULL, NULL, NULL );
HDC hdcCapture = CreateCompatibleDC( hdcScreen );
int nWidth = GetDeviceCaps( hdcScreen, HORZRES ),
nHeight = GetDeviceCaps( hdcScreen, VERTRES ),
nBPP = GetDeviceCaps( hdcScreen, BITSPIXEL );
LPBYTE lpCapture;
BITMAPINFO bmiCapture = { {
sizeof( BITMAPINFOHEADER ), nWidth, - nHeight, 1, nBPP, BI_RGB, 0, 0, 0, 0, 0,
} };
HBITMAP hbmCapture = CreateDIBSection( hdcScreen, & bmiCapture,
DIB_PAL_COLORS,( LPVOID * ) & lpCapture, NULL, 0 );
if( !hbmCapture ) {
DeleteDC( hdcCapture );
DeleteDC( hdcScreen );
return;
}
int nCapture = SaveDC( hdcCapture );
SelectObject( hdcCapture, hbmCapture );
BitBlt( hdcCapture, 0, 0, nWidth, nHeight, hdcScreen, 0, 0, SRCCOPY );
RestoreDC( hdcCapture, nCapture );
DeleteDC( hdcCapture );
DeleteDC( hdcScreen );
if( hMem = GlobalAlloc( GMEM_MOVEABLE, 0 ) )
{
IStream * pStream;
if( CreateStreamOnHGlobal( hMem, FALSE, & pStream ) == S_OK )
{
Bitmap * pScreenShot = new Bitmap( hbmCapture,( HPALETTE ) NULL );
CLSID imageCLSID;
Status result;
GetEncoderClsid( L"image/jpeg", & imageCLSID );
result = pScreenShot->Save( pStream, & imageCLSID );
pStream->Release();
if( result == Ok )
{
unsigned char * pBytes;
if( pBytes =( unsigned char * ) GlobalLock( hMem ) )
{
DWORD size = GlobalSize( hMem );
FILE * fp;
if( fp = _tfopen( _T( "c:\\test.jpg" ), _T( "wb" ) ) )
{
fwrite( pBytes, size, 1, fp );
fclose( fp );
}
}
}
}
else
{
printf( "error CreateStreamOnHGlobal. Last err: %d\n", GetLastError() );
return;
}
}
else
{
printf( "error GlobalAlloc. Last err: %d\n", GetLastError() );
return;
}
}
int _tmain( int argc, _TCHAR * argv[] )
{
ULONG_PTR gdiplusToken;
GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup( & gdiplusToken, & gdiplusStartupInput, NULL );
ScreenShot();
return 0;
}
Może Ciebie to na coś naprowadzi... w każdym razie spróbuj zrobić "Go to declaration" i zobaczyć czy istnieje deklaracja wymienionej przez Ciebie metody.
Z tego co się doczytałem to chodzi o to, że do drugiego (trzeciego) argumentu metody podajesz obiekt zamiast wskaźnik na obiekt.