IonicWind Software

IWBasic => General Questions => Topic started by: TonyMUK on August 21, 2009, 01:50:18 AM

Title: Copy graphics in a window to the clipboard
Post by: TonyMUK on August 21, 2009, 01:50:18 AM
Please Help. I have written my bar code program and it does what I originally wanted. It displays or prints a bar code. Now I am been asked if the bar code can be copied and pasted. I either need to write the bar code as an image that can be copied/saved or I need to output directly to the clipboard so it can be pasted straight away. Anyone have any ideas how it can be done.

Thanks

TonyM
Title: Re: Copy graphics in a window to the clipboard
Post by: sapero on August 21, 2009, 02:17:36 AM
Hi Tony,
Replace the call to PrintWindow with this: 'PrintWindow Win2
int left, top, width, height
GetClientSize Win2, left, top, width, height
CopyBarToClipboard(Win2, left, top, width, height)


The CopyBarToClipboard subroutine:$include "windowssdk.inc"

sub CopyBarToClipboard(window win, int left,int top,int width,int height)
if (OpenClipboard(win.hwnd))
' create a memory bitmap
HDC hdc = GetDC(0)
HDC cdc = CreateCompatibleDC(hdc)
HBITMAP hbm = SelectObject(cdc, CreateCompatibleBitmap(hdc, width, height))
' copy window pixels to this bitmap
HDC dc = GetHDC(win)
BitBlt(cdc, 0, 0, width, height, dc, left, top, SRCCOPY)
ReleaseHDC(win, dc)
hbm = SelectObject(cdc, hbm)
DeleteDC(cdc)
ReleaseDC(0, hdc)
' put the bitmap into clipboard
EmptyClipboard()
SetClipboardData(CF_BITMAP, hbm) ' do not delete hbm after this!
CloseClipboard()
endif
endsub
Title: Re: Copy graphics in a window to the clipboard
Post by: TonyMUK on August 21, 2009, 08:34:00 AM
Cheers Sapero. Your genius triumphs again.