Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

QuickWin - SAVEIMAGE

blwiland
Beginner
490 Views
The QuickWin library has a function called SAVEIMAGE that allows one to save an image from a specified portion of the screen into a specified Windows bitmap file. Rather than save it to a file, I would like to save it to the Windows Clipboard. Does anyone know if there is a standard system filename that can be used to save it to the clipboard rather than to a disk file?
0 Kudos
2 Replies
dboggs
New Contributor I
490 Views
Can't say I know how to do this, but check out the QuickWin function APPENDMENUQQ, called with the argument WINCOPY, which "copies the selected text and/or graphics from the current window to the Clipboard."

Also, according to my documentation (CVF), there is a sample program called Cliptext that shows how to do this, at least for text. Apparently it involves an API call, and you'd also have to tweak it to work with images, so it may be more involved than you'd like. But at least it may give you a clue.

Here is the documentation description:

"The cliptext sample demonstrates copying text to and from the clipboard. It uses the Windows interface to manage the GUI, and as such, also demonstrates the use of WinMain and MainWndProc that contains the event dispatcher. It has an "about" box, located under the File menu item, as there is no Help."
0 Kudos
anthonyrichards
New Contributor III
490 Views
I am not sure if this will work with Quickwin, but it is worth trying as it works in a normal Win32 program.

First I assume a menu item IDM_PASTETOCLIPBOARD. Then in your subclassed window procedure, or within a call back,

!***************************************************************************
use user32
use dfwin (or IVF equivalent)
use dfwinty (or IVF equivalent)
use dflib (or IVF equivalent)

type (T_RECT) rc
! Bitmap stuff...
INTEGER :: hBmp, hdcQW, hdcComp, iSizeImage, cClrBits, iSt, hmemBmBits, hClipboard
INTEGER(1) :: bmBits(*); POINTER(pbmBits, bmBits)
TYPE(T_BITMAPINFO) :: BI; POINTER(pBI,BI)
TYPE(T_BITMAP) :: Bmp
!
! all other undefined variables should be defined as INTEGER
!***********************************************************************************

case (IDM_PASTETOCLIPBOARD)
! you need the window handle hWnd here...once you have this everything follows...
! And you need the window device context, hWndDC

hWnd = ????
hWndDC=GetWindowDC(hWnd)

! Get dimensions of window in pixels
retlog=getclientrect(hWnd,rc)
ixwidth=rc%right-rc%left
iywidth=rc%bottom-rc%top

!If you have drawing code, access it here to draw what you want ONTO A MEMORY BITMAP
! First, create a compatible device context. It will contain a 1x1 pixel bitmap as a placeholder
! which is then replaced with the full-size bitmap with dimensions to match the window
hMemDC=CreateCompatibleDC(hWndDC)
!create your pens, brushes etc.
IRGBCLASSDEFAULT = #ffbb00 ! light Blue background, or whatever you want
hclassbrush = CreateSolidBrush(IRGBCLASSDEFAULT)
hclassPen = CreatePen(PS_SOLID, 0, IRGBCLASSDEFAULT)

! select the class background brush into the drawing DC
hBackBrush=SelectObject(hMemDC, hClassBrush)
! create a compatible bitmap and select it into the compatible DC
hBitmap=CreateCompatibleBitmap(hWndDC,ixwidth,iywidth)
hOldBitmap=SelectObject(hMemDC, hBitmap)

!*******************************************
!some drawing commands...
! Fill the rectangular background with the class background brush
! to erase the previous drawing and prepare for next drawing. You must
! substitute a classpen for the default black, otherwise the border automatically
! drawn round the edge of the rectangle will show up. Re-select the white pen after
! the rectangle is filled and before drawing starts...
!
hOldPen=SelectObject(hMemDC, hclassPen) ! replaces the default pen with the class pen..
retlog=msfwin$rectangle(hMemDC,rc%left, rc%top, rc%right, rc%bottom)
! Start drawing to memory, beginning with the frame inside the edge...
hNewPen=SelectObject(hMemDC, hOldPen) ! restores default pen
! Draw frame
retlog=MoveToEx(hMemDC,rc%left+2,rc%top+2, NULL_POINT)
retlog=MSFWIn$LineTo(hMemDC,rc%right-3,rc%top+2 )
retlog=MSFWIn$LineTo(hMemDC,rc%right-3,rc%bottom-3)
retlog=MSFWIn$LineTo(hMemDC,rc%left+2,rc%bottom-3)
retlog=MSFWIn$LineTo(hMemDC,rc%left+2,rc%top+2)
!
!end of drawing commands
!*******************************************
!Fill a BIMAPINFO structure BI
!
!Get the color depth bits of the bitmap
cClrBits=GetDeviceCaps(hMemDC, BITSPIXEL)
! write(chbits,'(i5)') cClrBits
! message='Color bits = '//chbits//''c
! retlog=messagebox(hWnd,message,&
! "Color BITS RESULT"c, &
! IOR(MB_SYSTEMMODAL,IOR(MB_OK, MB_ICONHAND)))

iSizeImage=((ixwidth * cClrBits + 31) /8) * iywidth

!Allocate memory for BITMAPINFO structure. It consists of BITMAPINFOHEADER
!structure followed immediately in memory by array of color bits.
hmemBmBits = GlobalAlloc(GMEM_MOVEABLE+GMEM_DDESHARE, iSizeImage+SIZEOF(BI%bmiHeader))
pbmBits = GlobalLock(hmemBmBits)
pBI = pbmBits

!Fill in the BITMAPINFOHEADER.
BI%bmiHeader%biSize = SIZEOF(BI%bmiHeader)
BI%bmiHeader%biWidth = ixwidth
BI%bmiHeader%biHeight = iywidth
BI%bmiHeader%biPlanes = 1 !1 plane (e.g. icons have 2)
BI%bmiHeader%biBitCount = cClrBits !color depth
BI%bmiHeader%biCompression = BI_RGB !no compression
BI%bmiHeader%biSizeImage = iSizeImage
BI%bmiHeader%biXPelsPerMeter = 96*100/2.54+1
BI%bmiHeader%biYPelsPerMeter = 96*100/2.54+1
BI%bmiHeader%biClrImportant = 0

!Get the bitmap bits into BI. Actual bits start at this offset--v
iSt = GetDIBits(hMemDC, hBitmap, 0, iywidth, pbmBits+SIZEOF(BI%bmiHeader), pBI, DIB_RGB_COLORS)

!clean up
hBitmap=SelectObject(hMemDC, hOldBitmap)
retlog=DeleteObject(hBitmap)
retlog=DeleteDC(hMemDC)

hClipboard = OpenClipboard(hWnd)
retlog = EmptyClipboard()

iSt = SetClipboardData(CF_DIB, hmemBmBits) !Copy the contents onto clipboard

iSt = CloseClipboard() !Clean up
iSt = GlobalUnlock(hmemBmBits)
iSt = GlobalFree(hmemBmBits)
!
! Then clean up by deleting any pens, brushes you have created using DeleteObject(hPen) etc.

Hope this helps.






0 Kudos
Reply