Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transparent form 2

Status
Not open for further replies.

eyeshield21

Programmer
Aug 13, 2014
62
PH

how to transparent only the form and so the controls are visible in vfp

 
See thread184-1597816

You make one color transparent, other solutions make the whole form have a certain transparency level.

Bye, Olaf.
 
could you give me another solution other than that?..
what i want is the form to be transparent on init or load of form..
and only controls are seen or in other words, making an irregular shape form..
 
Olaf Doschke already gave you the answer.
1) give to the form a backcolor that can't be found on any of form's objects
2) in form's init event, apply the makeirregular method from C:\Program Files (x86)\Microsoft Visual FoxPro 9\Samples\Solution\Toledo\Irregular.scx

Here is a demo
Code:
PUBLIC ofrm
ofrm = CREATEOBJECT("MyForm")
ofrm.show()

DEFINE CLASS myform as Form
	backcolor = RGB(128,255,255)
	showwindow = 2
	nflags = 0
	ADD OBJECT cmd as commandbutton WITH caption = 'opaque'
	ADD OBJECT lbl as label WITH left = 100
	ADD OBJECT txt as textbox WITH top = 50
	ADD OBJECT cmb as combobox WITH top = 50, left = 100
	ADD OBJECT lst as listbox WITH top =100
	PROCEDURE init
		Thisform.Makeirr(Thisform.HWnd,Thisform.BackColor,1) && transparent
	ENDPROC
	PROCEDURE cmd.click 
		Thisform.Makeirr(Thisform.HWnd,Thisform.BackColor,2) && transparent
		ThisForm.Picture = ''
	ENDPROC
	PROCEDURE makeirr
		********************************************************************************
		* To create a non-rectangular form, a transparent color needs to be set.
		* Anything drawn using this color will be transparent, and any
		* mouse clicks in these regions will pass through to the visible form.
		*
		* This technique only works in Windows 2000/XP but it is much more efficient
		* than previous techniques of setting a bounding region for the form.
		*
		* This can be used to create non-rectangluar forms, to create hovering agents,
		* or simply to confuse your coworkers <g>.
		*
		* Although this function makes a form transparent, the Form must be setup
		* accept these changes. First, the ShowWindow property MUST BE set to
		* 2 'As Top-Level Form'. Otherwise the window cannot be drawn layered.
		* Second, if you want to turn off the window's frame, since it will not be
		* drawn transparent, you can set the following properties:
		*	BorderStyle = 0
		*	Caption		= ""
		*	Closable	= .F.
		*	ControlBox	= .F.
		*	TitleBar	= 0
		*
		********************************************************************************
		*-- Pass in the window handle (Thisform.HWIND) and the color to make transparent.
		LPARAMETERS nHWND, nColor, nAction
			DECLARE INTEGER SetLayeredWindowAttributes IN win32api;
				INTEGER HWND,  INTEGER crKey, INTEGER bAlpha, INTEGER dwFlags

			*These functions get and set a window's attributes
			DECLARE INTEGER SetWindowLong IN user32.DLL ;
				INTEGER hWnd, INTEGER nIndex, INTEGER dwNewLong

			DECLARE INTEGER GetWindowLong IN user32.DLL ;
				INTEGER hWnd, INTEGER nIndex

		*Constants for SetLayeredWindowAttributs
		#DEFINE LWA_COLORKEY	1
		#DEFINE LWA_ALPHA		2

		*Constants for SetWindowLong and GetWindowLong
		#DEFINE GWL_EXSTYLE		-20
		#DEFINE WS_EX_LAYERED	0x00080000

		LOCAL lnFlags

		*The form's window must be set to Layered, so that it is drawn
		* in a separate layer.
		do case 
		   case nAction = 1 && Make Transparent
		      lnFlags = GetWindowLong(nHWND, GWL_EXSTYLE)	&&Gets the existing flags from the window
		      thisform.nFlags = lnFlags 
		      lnFlags	= BITOR(lnFlags, WS_EX_LAYERED)			&&Appends the Layered flag to the existing ones
		      SetWindowLong(nHWND, GWL_EXSTYLE, lnFlags)		&&Sets the new flags to the window
		      SetLayeredWindowAttributes(nHWND, nColor, 0, LWA_COLORKEY)
		   case nAction = 2 && Make Opaque 
		      SetWindowLong(nHWND, GWL_EXSTYLE, thisform.nFlags)      &&Sets the original flags to the window
		      SetLayeredWindowAttributes(nHWND, nColor, 0, 0)
		endcase 
	ENDPROC
ENDDEF

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
If you can't understand the sample and simply put the essential command2.click code line into the form init, pr better yet even pit the API calls into init, you should perhaps learn very basic things about Foxpro first, before you dive into creating such a thing.

I suggest you take your time and watch some learning videos at
Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top