Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to save the screen from clipboard copy image.
Message
 
To
17/09/2002 02:28:52
General information
Forum:
Visual FoxPro
Category:
Pictures and Image processing
Miscellaneous
Thread ID:
00701106
Message ID:
00701154
Views:
25
>Long Time ago, I get a code here about Capture Screen into clipboard.
>
>Previously, thanks cetin this API and I made user manual by this.
>
>Now, for remote control another PC, I need more function to save the image
>file, how to do?!
>
>SAVEPICTURE() doesn't work.. :(
>e.g. SAVEPICTURE(_SCREEN, [c:\abc.bmp])
>
>Of cos, best save will be GIF or JPG.

Hi,

Take a look on http://www.news2news.com/vfp/?example=189&function=311
This sample stores clipboard content in BMP format. Here is another sample:
* Usage: SaveClipImage("clipfile.bmp")

#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 SaveClipImage(tcFileName)
	If Vartype(tcFileName) != 'C'
		Error 11
	EndIf
	tcFileName = DefaultExt(tcFileName, "bmp")

	* 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, Long @ IPic
	Declare Long GlobalAlloc In kernel32 Long wFlags, Long dwBytes  
	Declare Long GlobalFree In kernel32 Long hMem 
	Declare Long GlobalLock In kernel32 Long hMem
	Declare Long GlobalUnlock In kernel32 Long hMem
	Declare Long MultiByteToWideChar In kernel32 ;
		Long iCodePage, Long dwFlags, String @ lpStr, Long iMultiByte, ;
		Long lpWideStr, Long iWideChar
	Declare Long SysAllocString In oleaut32 Long szString
	Declare Long VariantClear in oleaut32 String @ pvarg

	* This function is not documented in MSDN, but present in Platform SDK .h file
	Declare Long OleSavePictureFile In oleaut32 Long IPic, Long bstrFile

	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)

	lnStrLen = Len(tcFileName)
	lhMem = GlobalAlloc(GMEM_MOVEABLE+GMEM_ZEROINIT+GMEM_SHARE, 2*(lnStrLen+1))
	lnPtr = GlobalLock(lhMem)
	MultiByteToWideChar(CP_ACP, 0, @tcFileName, lnStrLen, lnPtr, lnStrLen+1)
	OleSavePictureFile(IPic, SysAllocString(lnPtr))

	* IPic.Release()
	var = Chr(VT_DISPATCH) + Replicate(Chr(0), 7) + DWord(IPic)
	VariantClear(@var)

	GlobalUnlock(lhMem)
	GlobalFree(lhMem)
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
I have also a code for storing clipboard content in JPG, GIF and other formats, but this code is based on another approach and I'm going to publish it later.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform