Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Yousfi Benameur
  Where is Yousfi Benameur?
 El Bayadh
 Algeria
 Yousfi Benameur
 To: pichimedia pichimedia
  Where is pichimedia pichimedia?
 HD
 Romania
 pichimedia pichimedia
 Tags
Subject: RE: Transparent form Opaque objects
Thread ID: 310545 Message ID: 310577 # Views: 58 # Ratings: 3
Version: Visual FoxPro 8 Category: General VFP Topics
Date: Wednesday, June 22, 2011 4:58:43 PM         
   


> Hello,
>
> I have created a news like ticker for desktop, which displays my to do's.
> Now I want to somehow make it more visual appealing. I know how to make the whole form transparent,
> but is there a way to make just the form transparent but not the objects. For example, I want my form to be transparent, and my labels to remain opaque. Is such a procedure possible in VFP, or some technique to achieve this effect?
>
> Thank you.

try this code
publi yform
yform=newObject("ytransp")
yform.show
read events
return

DEFINE CLASS ytransp AS form
	Height = 370
	Width = 666
	ShowWindow = 2     &&or desktop=.t. for showWindow=0,1
	ShowTips = .T.
	AutoCenter = .T.
	BorderStyle = 0
	Caption = ""
	BackColor = RGB(255,0,255)
	Name = "Form1"

	ADD OBJECT list1 AS listbox WITH ;
		Height = 181, ;
		Left = 12, ;
		Top = 12, ;
		Width = 180, ;
		Name = "List1"

	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 24, ;
		Left = 468, ;
		Height = 132, ;
		Width = 156, ;
		Picture =home()+ "graphics\gifs\morphfox.gif", ;
		Caption = "", ;
		Name = "Command1"

	ADD OBJECT optiongroup1 AS optiongroup WITH ;
		AutoSize = .T., ;
		ButtonCount = 2, ;
		Value = 2, ;
		Height = 46, ;
		Left = 288, ;
		Top = 312, ;
		Width = 95, ;
		Name = "Optiongroup1", ;
		Option1.Caption = "Transparent", ;
		Option1.Value = 0, ;
		Option1.Height = 17, ;
		Option1.Left = 5, ;
		Option1.Top = 5, ;
		Option1.Width = 85, ;
		Option1.AutoSize = .T., ;
		Option1.Name = "Option1", ;
		Option2.Caption = "Opaque", ;
		Option2.Value = 1, ;
		Option2.Height = 17, ;
		Option2.Left = 5, ;
		Option2.Top = 24, ;
		Option2.Width = 61, ;
		Option2.Name = "Option2"

	ADD OBJECT label1 AS label WITH ;
		AutoSize = .T., ;
		FontBold = .T., ;
		FontSize = 14, ;
		Caption = "X", ;
		Height = 25, ;
		Left = 636, ;
		Top = 0, ;
		Width = 15, ;
		ForeColor = RGB(0,0,255), ;
		BackColor = RGB(255,0,255), ;
		Name = "Label1"

	ADD OBJECT label2 AS label WITH ;
		AutoSize = .T., ;
		FontBold = .T., ;
		FontSize = 14, ;
		Caption = "-", ;
		Height = 25, ;
		Left = 612, ;
		Top = 0, ;
		Width = 8, ;
		ForeColor = RGB(0,0,255), ;
		BackColor = RGB(255,0,255), ;
		Name = "Label2"

	ADD OBJECT shape1 AS shape WITH ;
		Top = 312, ;
		Left = 600, ;
		Height = 49, ;
		Width = 49, ;
		Curvature = 15, ;
		MousePointer = 15, ;
		BackColor = RGB(0,255,0), ;
		Name = "Shape1"

	ADD OBJECT image1 AS image WITH ;
		Picture = home()+"graphics\cursors\4way03.cur", ;
		BackStyle = 0, ;
		Height = 32, ;
		Left = 609, ;
		MousePointer = 15, ;
		Top = 320, ;
		Width = 32, ;
		ToolTipText = "Move form", ;
		Name = "Image1"

	ADD OBJECT ylab AS label WITH ;
		FontName = "Tahoma", ;
		FontSize = 12, ;
		Caption = "", ;
		Height = 132, ;
		Left = 216, ;
		Top = 168, ;
		Width = 348, ;
		ForeColor = RGB(128,0,64), ;
		BackColor = RGB(255,255,185), ;
		Name = "yLab"

	PROCEDURE ytransp
		#DEFINE LWA_COLORKEY 1
		#DEFINE LWA_ALPHA 2
		#DEFINE GWL_EXSTYLE -20
		#DEFINE WS_EX_LAYERED 0x80000
		    LOCAL nExStyle, nRgb, nAlpha, nFlags
		    nExStyle = GetWindowLong(THISform.HWnd, GWL_EXSTYLE)
		    nExStyle = BITOR(nExStyle, WS_EX_LAYERED)
		    = SetWindowLong(THISform.HWnd, GWL_EXSTYLE, nExStyle)
		   = SetLayeredWindowAttributes(THISform.HWnd, thisform.backcolor, 190,LWA_COLORKEY+LWA_ALPHA)
	ENDPROC

	PROCEDURE yopaque
		#DEFINE LWA_COLORKEY 1
		#DEFINE LWA_ALPHA 2
		#DEFINE GWL_EXSTYLE -20
		#DEFINE WS_EX_LAYERED 0x80000
		    LOCAL nExStyle
		    nExStyle = GetWindowLong(THISform.HWnd, GWL_EXSTYLE)
		    nExStyle = BITXOR(nExStyle, WS_EX_LAYERED)
		    = SetWindowLong(THISform.HWnd, GWL_EXSTYLE, nExStyle)
		 thisform.cls
		thisform.backcolor=thisform.backcolor   
		 thisform.refresh
	ENDPROC

	PROCEDURE Init
		this.titlebar=0
		text to this.ylab.caption noshow
		this form can be made transparent with Apis.
		it must be -top level form (showWindow=2)
		           -desktop=.t. for showWindow=0,1
		can make one color transparent in the API and
		set the transparency level (0-255)            
		endtext
	ENDPROC

	PROCEDURE Load
		DECLARE INTEGER GetWindowLong IN user32;
		        INTEGER hWnd, INTEGER nIndex
		 
		    DECLARE INTEGER SetWindowLong IN user32;
		        INTEGER hWnd, INTEGER nIndex, INTEGER dwNewLong
		 
		    DECLARE INTEGER SetLayeredWindowAttributes IN user32;
		        INTEGER hwnd, INTEGER crKey,;
		        SHORT bAlpha, INTEGER dwFlags
    	ENDPROC

	PROCEDURE optiongroup1.InteractiveChange
		do case
		case this.value=1
		thisform.ytransp()
		case this.value=2
		thisform.yopaque()
		endcase
	ENDPROC

	PROCEDURE label1.Click
		thisform.release
	ENDPROC

	PROCEDURE label2.Click
		thisform.windowstate=1
	ENDPROC

	PROCEDURE image1.MouseDown
		LPARAMETERS nButton, nShift, nXCoord, nYCoord
		DECLARE INTEGER GetFocus IN WIN32API
		lnHandle = thisform.hwnd
		param1 = 274
		param2 = 0xF012
		DECLARE INTEGER ReleaseCapture IN WIN32API
		DECLARE INTEGER SendMessage IN WIN32API INTEGER, INTEGER, INTEGER, INTEGER
		bb=ReleaseCapture()
		bb=SendMessage(lnHandle, param1, param2,0)
	ENDPROC
       Procedure destroy
          clea events
       Endproc

ENDDEFINE

NB: you can adjust the transparency level (here 190....0 to 255)

Regards
Yousfi Benameur

COMPLETE THREAD

Transparent form Opaque objects Posted by pichimedia pichimedia @ 6/22/2011 1:32:45 PM
RE: Transparent form Opaque objects Posted by Yousfi Benameur @ 6/22/2011 4:58:43 PM
RE: Transparent form Opaque objects Posted by Bernard Bout @ 6/23/2011 2:17:38 AM
RE: Transparent form Opaque objects Posted by Yousfi Benameur @ 6/23/2011 11:14:30 AM
RE: Transparent form Opaque objects Posted by pichimedia pichimedia @ 6/23/2011 12:49:58 PM
RE: Transparent form Opaque objects Posted by Bernard Bout @ 6/23/2011 2:21:30 AM