Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Copy image to Windows clipboard
Message
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows NT
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01021590
Message ID:
01021606
Views:
32
I use this, note that lots of declare are not used, is just that I used this as testing grounds also.

The 2 parameters are the Form and the Image objects, note there is no verification or try catch etc.
* Copies an image to the clipboard
* The Image must be in a form
#define CF_BITMAP           2

lparameters toImage, toForm

local lnHwnd, lnHDC, lnHDC_Mem, lnHBitMap, lnHPrevBmp, lnLeft, lnTop, lnWidth, lnHeight


declare integer GetDC in win32api ;
		integer nhwnd

declare integer CreateCompatibleDC in win32api ;
		integer nhcd

declare integer BitBlt in win32api ;
		integer hDestDC, ;
		integer x, ;
		integer y, ;
		integer nWidth, ;
		integer nHeight, ;
		integer hScrDC, ;
		integer xsrc, ;
		integer ysrc, ;
		integer dwRop

declare integer SelectObject in win32api ;
		integer hDC, ;
		integer hObject

declare integer CreateCompatibleBitmap in win32api ;
		integer hDC, ;
		integer nWidth, ;
		integer nHeight

declare integer DeleteDC in win32api ;
		integer hDC

declare integer ReleaseDC in win32api ;
		integer nwnd, ;
		integer hdc

declare integer DeleteObject in win32api ;
		integer hDC
		
declare			OpenClipboard in win32api ;
		integer hWndNewOwner
		
declare			CloseClipboard in win32api

declare			EmptyClipboard in win32api

declare integer SetClipboardData in win32api ;
		integer nFormat, ;
		integer hObject

declare long	UuidFromString in rpcrt4.dll ;
		string	StringUuid, ;
		string 	@ Uuid

declare long	GdipSaveImageToFile in GdiPlus.dll ;
		long	GpImage, ;
		string	FileName, ;
		string	@ encoderClsid, ;
		string	@ encoderParams

declare integer WriteFile IN kernel32; 
		integer	hFile,; 
		string	@ lpBuffer,; 
		integer	nBt2Write,; 
		integer	@ lpBtWritten,; 
		integer	lpOverlapped 

declare integer	OpenFile IN kernel32; 
		string	lpFileName,; 
		string	@ lpReOpenBuff,; 
		integer	wStyle  
 
 


lnHWnd			= toForm.HWnd
lnHDC			= GetDC(lnHWnd)
lnHDC_Mem		= CreateCompatibleDC(lnHDC)
lnHBitMap		= CreateCompatibleBitmap(lnHDC, toImage.width, toImage.height)
if toImage.baseclass='Form'
	lnLeft			= 0
	lnTop			= 0
	lnWidth			= toImage.Width
	lnHeight		= toImage.Height
else
	lnLeft			= OBJTOCLIENT(toImage, 2)
	lnTop			= OBJTOCLIENT(toImage, 1)
	lnWidth			= OBJTOCLIENT(toImage, 3)
	lnHeight		= OBJTOCLIENT(toImage, 4)
endif

if lnHBitMap <> 0
	lnHPrevBmp	= SelectObject(lnHDC_Mem, lnHBitMap)
	BitBlt(lnHDC_Mem, 0, 0, lnWidth, lnHeight, lnHDC, lnLeft, lnTop, SRCCOPY)
	if OpenClipboard(lnHWnd)
		EmptyClipboard()
		SetClipboardData(CF_BITMAP, lnHBitMap)
		CloseClipboard()
	else
		wait window 'Could not open the ClipBoard! Operation failed'
	endif
	SelectObject(lnHDC_Mem, lnHPrevBmp)	&& Previous object should be re-selected
else
	wait window 'Could not create a copy of the bitmap!. Operation failed' 
endif

DeleteDC(lnHDC_Mem)
ReleaseDC(lnHWnd, lnHDC)
Also note that the only use of the Form parameter is it's window handle and for the image just the positioning, so it can be any container/object etc.
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform