Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sample code for paste from another application
Message
 
To
29/04/2003 02:11:33
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00782573
Message ID:
00782920
Views:
9
>hi all, i've a image control on my form,
>i want picture appear on it when i cut from another image then paste to my image. how do i do, code would be help... thank's. (like an image on ms-access)

Hi,

In addition to Rubinov's reply:
1. You can use code in message #701154 to store image in clipboard to file.
2. Instead of image control you can use any ActiveX control which is able to display an image, for example Microsoft ListView control. Then you can use the modified code from the above mentioned message to create a Picture object from clipboard content and pass it to ListView control:
ThisForm.oleListView.Picture = ClipToPicture()
The code is following (requires VFP7):
#define PICTYPE_BITMAP		1
#define CF_BITMAP			2
#define CF_PALETTE			9
#define OBJ_BITMAP			7

#define IID_IDispatch Chr(0x00)+Chr(0x04)+Chr(0x02)+Chr(0x00)+ ;
		Replicate(Chr(0x00), 4)+Chr(0xC0)+Replicate(Chr(0x00), 6)+Chr(0x46)
#define VT_DISPATCH			9
#define CP_ACP 0		&& default to ANSI code page

*-- Global Memory Flags
#define GMEM_MOVEABLE       0x0002
#define GMEM_ZEROINIT       0x0040
#define GMEM_SHARE          0x2000

Procedure ClipToPicture()
	* API declarations
	Declare Long OpenClipboard in user32 Long hWnd
	Declare Long CloseClipboard in user32
	Declare Long GetClipboardData in user32 Long uFormat
	Declare Long GetObjectType in gdi32 Long h

	Declare Long OleCreatePictureIndirect In oleaut32 ;
		String @ PicDesc, String @ RefIID, Long fPictureOwnsHandle, Object @ IPic

	Local hBmp, hPal, PistDesc, IPic, iid, lnStrLen, var, lhMem, lnPtr
	hBmp = 0
	hPal = 0
	If OpenClipboard(0) != 0
		hBmp = GetClipboardData(CF_BITMAP)
		hPal = GetClipboardData(CF_PALETTE)
		CloseClipboard()
	Else
		Error "Cannot open the clipboard"
	EndIf
	If hBmp = 0 Or GetObjectType(hBmp) <> OBJ_BITMAP
		Error "No bitmap data found on the clipboard"
	EndIf

	* Create Picture object according to PICTDESC structure
	PictDesc = DWord(16) ;				&& Size of PICTDESC structure
			 + DWord(PICTYPE_BITMAP) ;	&& Type of picture
			 + DWord(hBmp) ;			&& HBMP
			 + DWord(hPal)					&& HPALETTE
	IPic = 0
	iid = IID_IDispatch
	OleCreatePictureIndirect(@PictDesc, @iid, 0, @IPic)
	Return Ipic
EndProc

Function DWord(lnValue)
* Creates a DWORD (unsigned 32-bit) string from a number
	Local byte(4)
	If lnValue < 0
		lnValue = lnValue + 4294967296
	EndIf
	byte(1) = lnValue % 256
	byte(2) = BitRShift(lnValue, 8) % 256
	byte(3) = BitRShift(lnValue, 16) % 256
	byte(4) = BitRShift(lnValue, 24) % 256
	Return Chr(byte(1))+Chr(byte(2))+Chr(byte(3))+Chr(byte(4))
EndFunc
Previous
Reply
Map
View

Click here to load this message in the networking platform