Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to capture the Desktop Window into a jpeg image?
Message
 
To
10/11/2003 23:04:50
General information
Forum:
Visual FoxPro
Category:
Pictures and Image processing
Miscellaneous
Thread ID:
00847508
Message ID:
00848614
Views:
19
Peter,
>Your estimate for me to create the simple C++ dll is too low. I don't know anything about C++ and VB. I guess I need to compile a simple C++ dll (win32 dll) using the gdiplusflat.h and a source file.

You should include GdiPlus.h and use classes instead of flat API. It may look as follow:
#include "GdiPlus.h"
using namespace Gdiplus;

__declspec( dllexport ) int _stdcall CaptureToJPEG( LPCSTR FileName )
{
	GdiplusStartupInput gdiplusStartupInput;
	ULONG_PTR           gdiplusToken;

	RECT r;
	::GetWindowRect(GetDesktopWindow(), &r);
	HDC dc = ::GetWindowDC(0);
	HDC memDC = ::CreateCompatibleDC(dc);

	HBITMAP bm = ::CreateCompatibleBitmap(dc, (r.right-r.left), (r.bottom-r.top));
	HBITMAP oldbm = (HBITMAP) ::SelectObject(memDC, bm);
	::BitBlt(memDC, 0, 0, r.right-r.left, r.bottom-r.top, dc, 0, 0, SRCCOPY);
	::ReleaseDC(0, dc);
	::SelectObject(memDC, oldbm);
	::DeleteDC(memDC);

	// Initialize GDI+
	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
	{
		Bitmap img(bm, NULL);
		wchar_t fn[MAX_PATH];
		MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, FileName, -1, fn, MAX_PATH);
		CLSID jpegClsid;
		int result = GetCodecClsid(L"image/jpeg", &jpegClsid);
		img.Save(fn, &jpegClsid);
	}
	GdiplusShutdown(gdiplusToken);

	return 0;
}
You'll get the VC++ project and compiled DLL by email. Sorry, there is no error and exception handling.

>Let's assume that I find out how to compile this dll. How do I use it?
Declare Integer CaptureToJPEG in Capture.dll String FileName
CaptureToJPEG("screenshot.jpg")
If you would prefer to make a COM library, then instead of Declare you will use CreateObject().
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform