Re: How to write graphics to MS Windows clipboard

new topic     » goto parent     » topic index » view thread      » older message » newer message

CChris wrote:
> 

> 
> I assume your graphics are displayed on some window.
> 
> Didn't test it; part of cleanup may be redundant.
> 
> CChris



-- from my global code:
constant ptx = 1
constant pty = 2
--

atom hDC,hMemDC,hOldBmp,hBmp
atom void
sequence DRAWINsize

-- place my child window control DRAWIN in clipboard

hDC=getDC(DRAWIN)
-- create a memory target DC
hMemDC=w32Func(xCreateCompatibleDC,{hDC})
if not hMemDC then
void=message_box("Failed to create temporary
bitmap.","Error",MB_ICONERROR+MB_OK)
else
-- create the bitmap we'll send to clipboard, with supplied dimensions.
-- It will be written to using hMemDC.
DRAWINsize = getCtlSize(DRAWIN)
hBmp=w32Func(xCreateCompatibleBitmap,{hMemDC,DRAWINsize[ptx],DRAWINsize[pty]})
if not hBmp then
void=message_box("Failed to create temporary
bitmap.","Error",MB_ICONERROR+MB_OK)
else
-- use hMemDC o write to it.
hOldBmp=w32Func(xSelectObject,{hMemDC,hBmp})
-- now copy source rectangle to it
void=w32Func( xBitBlt, {hMemDC, 0, 0, DRAWINsize[ptx], DRAWINsize[pty], hDC, 0,
0, SrcCopy} )
-- send bitmap to clipboard
if not w32Func(xOpenClipboard, {NULL}) then
	void=message_box("Failed to open clipboard.","Error",MB_ICONERROR+MB_OK)
else
-- current thread now has exclusive access to clipboard
void=w32Func(xEmptyClipboard,{})
if w32Func(xSetClipboardData,{CF_BITMAP,hBmp}) != hBmp then
void=message_box("Failed to copy bitmap to
clipboard.","Error",MB_ICONERROR+MB_OK)
end if
w32Proc(xCloseClipboard,{})

-- now we no longer own it
-- clean up
-- releaseDC(hMemDC) Not sure how to clean up
-- deselect the bitmap so as to own it
hBmp=w32Func(xSelectObject,{hMemDC,hOldBmp})
releaseDC(DRAWIN)
end if
end if
end if


I have made many small changes to CChris's code and tested it. And I have
managed to get the drawing into Paint with Paste. Except that it only has 2
colors - white or black - and any color is being seen as black. So, where do we
go from here?

Andy Katz
B.S. Computer Science, 1978
Rensselaer Polytechnic Institute (RPI)

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu