mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
Reference: CaptureScreenDll
git-svn-id: svn://ultimatepp.org/upp/trunk@2444 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
32a1057440
commit
bbb571d916
3 changed files with 84 additions and 0 deletions
14
reference/CaptureScreenDll/CaptureScreenDll.upp
Normal file
14
reference/CaptureScreenDll/CaptureScreenDll.upp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
description "Demonstrates .dll in Win32 with single capture_screen function\377";
|
||||
|
||||
uses
|
||||
CtrlLib,
|
||||
plugin\jpg,
|
||||
plugin\gif,
|
||||
plugin\tif;
|
||||
|
||||
file
|
||||
main.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI DLL";
|
||||
|
||||
8
reference/CaptureScreenDll/init
Normal file
8
reference/CaptureScreenDll/init
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef _ScreenShotter_icpp_init_stub
|
||||
#define _ScreenShotter_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#include "plugin\jpg/init"
|
||||
#include "plugin\gif/init"
|
||||
#include "plugin\tif/init"
|
||||
#include "plugin\pcx/init"
|
||||
#endif
|
||||
62
reference/CaptureScreenDll/main.cpp
Normal file
62
reference/CaptureScreenDll/main.cpp
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
#include <CtrlLib/CtrlLib.h>
|
||||
#include <plugin/bmp/bmp.h>
|
||||
#include <plugin/jpg/jpg.h>
|
||||
#include <plugin/gif/gif.h>
|
||||
#include <plugin/tif/tif.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
Image ScreenShot(int x, int y, int cx, int cy)
|
||||
{
|
||||
HDC dcScreen = CreateDC("DISPLAY", NULL, NULL, NULL);
|
||||
|
||||
RGBA *pixels;
|
||||
|
||||
Buffer<byte> data;
|
||||
data.Alloc(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*256);
|
||||
BITMAPINFOHEADER *hi = (BITMAPINFOHEADER *) ~data;;
|
||||
memset(hi, 0, sizeof(BITMAPINFOHEADER));
|
||||
hi->biSize = sizeof(BITMAPINFOHEADER);
|
||||
hi->biPlanes = 1;
|
||||
hi->biBitCount = 32;
|
||||
hi->biCompression = BI_RGB;
|
||||
hi->biSizeImage = 0;
|
||||
hi->biClrUsed = 0;
|
||||
hi->biClrImportant = 0;
|
||||
hi->biWidth = cx;
|
||||
hi->biHeight = -cy;
|
||||
|
||||
HBITMAP hbmp = CreateDIBSection(dcScreen, (BITMAPINFO *)hi, DIB_RGB_COLORS, (void **)&pixels, NULL, 0);
|
||||
HDC dcMem = ::CreateCompatibleDC(dcScreen);
|
||||
HBITMAP hbmpOld = (HBITMAP) ::SelectObject(dcMem, hbmp);
|
||||
HDC hdcCompatible = CreateCompatibleDC(dcScreen);
|
||||
::BitBlt(dcMem, 0, 0, cx, cy, dcScreen, x, y, SRCCOPY);
|
||||
|
||||
ImageBuffer ib(cx, cy);
|
||||
memcpy(~ib, pixels, cx * cy * sizeof(RGBA));
|
||||
|
||||
::DeleteObject(::SelectObject(dcMem, hbmpOld));
|
||||
::DeleteDC(dcMem);
|
||||
::DeleteDC(dcScreen);
|
||||
|
||||
return ib;
|
||||
};
|
||||
|
||||
extern "C" __declspec(dllexport) int capture_screen(int x, int y, int cx, int cy, char *filename) {
|
||||
Image m = ScreenShot(x, y, cx, cy);
|
||||
String ext = ToLower(GetFileExt(filename));
|
||||
if(ext == ".png")
|
||||
PNGEncoder().SaveFile(filename, m);
|
||||
if(ext == ".bmp")
|
||||
BMPEncoder().Bpp(32).SaveFile(filename, m);
|
||||
if(ext == ".jpg")
|
||||
JPGEncoder().SaveFile(filename, m);
|
||||
if(ext == ".gif")
|
||||
GIFEncoder().SaveFile(filename, m);
|
||||
if(ext == ".tif" || ext == ".tiff")
|
||||
TIFEncoder().SaveFile(filename, m);
|
||||
return 0;
|
||||
}
|
||||
|
||||
DLL_APP_MAIN {
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue