Add Background Image to VFP desktop

The code below shows how to add a background image to the VFP desktop using the VFP Image control.

This is sample code. Add error handling and adjust to your requirements as necessary.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

lcImage = "Whatever.jpg"
* Center Image
lcBgType = "CENTER"
* Stretch image
*lcBgType = "STRETCH"
* Stretch image while maintaining its original proportions
*lcBgType = "ISOMETRIC"

IF NOT PEMSTATUS(_Screen, "oImg", 5)
	_Screen.AddObject("oImg", "Image")
ENDIF

WITH _Screen.oImg
	.Visible = .F.
	.Stretch = 0
	.Picture = lcImage 
	DO CASE
	CASE lcBgType == "STRETCH"
		.Top     = 0
		.Left    = 0
		.Stretch = 2
		.Height	 = _Screen.Height
		.Width	 = _Screen.Width
	CASE lcBgType == "ISOMETRIC"
		.Stretch = 1
		.Height	 = _Screen.Height
		.Width	 = _Screen.Width
		.Top  = (_Screen.Height - .Height) / 2
		.Left = (_Screen.Width - .Width) / 2
	CASE lcBgType == "CENTER"
		.Stretch = 0
		.Top  = (_Screen.Height - .Height) / 2
		.Left = (_Screen.Width - .Width) / 2
	OTHERWISE	
		.Top  = 0
		.Left = 0
		.Stretch = 0
	ENDCASE
	.Visible = .T.
ENDWITH

Comments

An image has a .jpg file as the picture. How can this picture be put into window's clipboard so it can be pasted to other applications.

Try <a href = "https://www.universalthread.com/ViewPageNewDownload.aspx?ID=18584"><B>GDI+ image class</B> Download #18584</a> It has ToClipboard() method.

You may also check <a href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=VFPX&title=GDIPlusX">GdiPlusX library</> from <a href="http://www.codeplex.com/VFPX">VFP<sub>x</sub></a>

Is it possible to use a HTML-file as the VFP-background ?

I would like to create a different background (based on text) every time i start my application...

Calvin Hsia shows how to put Web Browser control on VFP desktop at http://blogs.msdn.com/calvin_hsia/archive/2004/08/20/217915.aspx
Basicly, you create AlwaysOnBottom form with Web Browser control on it and use BindEvent() to bind to Screen.Resize() to make sure that it covers VFP desktop if it ever resized.

nice post, thanks

Thanks to this post. Nice article