May 04, 2024, 08:11:08 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Copy graphics in a window to the clipboard

Started by TonyMUK, August 21, 2009, 01:50:18 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

TonyMUK

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
Check out www.arnoldchiari.co.uk. If you don't know what Arnold Chiari is you are very lucky.

sapero

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

TonyMUK

Check out www.arnoldchiari.co.uk. If you don't know what Arnold Chiari is you are very lucky.