From e3bb55da1a8015390ea85bafe45bea1c704a6fb1 Mon Sep 17 00:00:00 2001 From: FellippeHeitor Date: Wed, 6 Sep 2017 11:19:54 -0300 Subject: [PATCH] Add _CLIPBOARDIMAGE (statement and function) - Fetch an image from the clipboard with handle& = _CLIPBOARDIMAGE - If there isn't an image in the clipboard, handle& will be -1. - Copy a valid image to the clipboard (All screen modes, except 0) with _CLIPBOARDIMAGE = handle& --- internal/c/libqb.cpp | 137 +++++++++++++++++++++++ internal/c/qbx.cpp | 2 + source/global/version.bas | 2 +- source/subs_functions/subs_functions.bas | 18 +++ 4 files changed, 158 insertions(+), 1 deletion(-) diff --git a/internal/c/libqb.cpp b/internal/c/libqb.cpp index 0a1d3b391..e357b8ab5 100644 --- a/internal/c/libqb.cpp +++ b/internal/c/libqb.cpp @@ -24238,6 +24238,143 @@ if (x11selectionowner!=None){ qbs_set(internal_clipboard,text); } +void sub__clipboardimage(int32 src) { +#ifdef QB64_WINDOWS + + if (new_error) return; + + static int32 i,i2,ii,w,h; + static uint32 *o,*o2; + static int32 x,y,n,c,i3,c2; + + //validation + i=src; + if (i>=0){//validate i + validatepage(i); i=page[i]; + }else{ + i=-i; if (i>=nextimg){error(258); return;} if (!img[i].valid){error(258); return;} + } + + if (img[i].text){error(5); return;} + //end of validation + + w=img[i].width; + h=img[i].height; + + //source[http://support.microsoft.com/kb/318876] + HDC hdc; + BITMAPV5HEADER bi; + HBITMAP hBitmap; + void *lpBits; + ZeroMemory(&bi,sizeof(BITMAPV5HEADER)); + bi.bV5Size = sizeof(BITMAPV5HEADER); + bi.bV5Width = w; + bi.bV5Height = h; + bi.bV5Planes = 1; + bi.bV5BitCount = 32; + bi.bV5Compression = BI_RGB; + + hdc = GetDC(NULL); + // Create the DIB section with an alpha channel. + hBitmap = CreateDIBSection(hdc, (BITMAPINFO *)&bi, DIB_RGB_COLORS, + (void **)&lpBits, NULL, (DWORD)0); + + //Transfer the source image to a new 32-bit image to avoid incompatible formats) + i2=func__newimage(w,h,32,1); + sub__putimage(NULL,NULL,NULL,NULL,-i,i2,NULL,NULL,NULL,NULL,8+32); + + o=img[-i2].offset32; + o2=(uint32*)lpBits; + for (y=0;yoffset,(BITMAPINFO*)&bi, DIB_RGB_COLORS); + sub__dest(i2); + + ReleaseDC(NULL,hdc); + DeleteObject(bitmap); + return i; + +} else return -1; +#endif +return -1; +} + qbs *func__clipboard(){ #ifdef QB64_WINDOWS static qbs *text; diff --git a/internal/c/qbx.cpp b/internal/c/qbx.cpp index e6f026144..ee8c130dd 100644 --- a/internal/c/qbx.cpp +++ b/internal/c/qbx.cpp @@ -249,6 +249,8 @@ extern void sub__fullscreen(int32 method,int32 passed); extern int32 func__fullscreen(); extern void sub__clipboard(qbs*); extern qbs *func__clipboard(); +extern int32 func__clipboardimage(); +extern void sub__clipboardimage(int32 src); extern int32 func__exit(); extern char *fixdir(qbs*); extern void revert_input_check(); diff --git a/source/global/version.bas b/source/global/version.bas index ebec49758..e74f4e63a 100644 --- a/source/global/version.bas +++ b/source/global/version.bas @@ -4,4 +4,4 @@ DIM SHARED AutoBuildMsg AS STRING Version$ = "1.1" 'BuildNum format is YYYYMMDD/id, where id is a ever-increasing 'integer. If you make a change, update the date and increase the id! -BuildNum$ = "20170822/63" +BuildNum$ = "20170906/64" diff --git a/source/subs_functions/subs_functions.bas b/source/subs_functions/subs_functions.bas index 5bcd819de..2a72aab9d 100644 --- a/source/subs_functions/subs_functions.bas +++ b/source/subs_functions/subs_functions.bas @@ -681,6 +681,24 @@ id.ret = STRINGTYPE - ISPOINTER id.NoCloud = 1 regid +clearid +id.n = "_CLIPBOARDIMAGE" +id.subfunc = 1 +id.callname = "func__clipboardimage" +id.ret = LONGTYPE - ISPOINTER +id.NoCloud = 1 +regid + +clearid +id.n = "_CLIPBOARDIMAGE" +id.subfunc = 2 +id.callname = "sub__clipboardimage" +id.args = 1 +id.arg = MKL$(LONGTYPE - ISPOINTER) +id.specialformat = "=?" +id.NoCloud = 1 +regid + clearid id.n = "_EXIT" id.subfunc = 1