Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Fighting again with trasparences
Message
From
28/06/2010 04:39:25
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Fighting again with trasparences
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01470769
Message ID:
01470769
Views:
122
I have a problem using trasparent forms.
Actually I made two forms to mix images and I have a third trasparent form where I place commandbuttons on that's because VFP does not manage PNG trasparence.
Now I was trying to put these.commandbuttons over a form which has its background totally trasparent. But doing that i got an error, maybe because I am invoking the same function in two different way.

Here is the form I use to mix images, I load two different form from this class and I manage them with a Timer
DEFINE CLASS Formix AS form 
	titlebar = 0
	ShowWindow = 2
	nFlags = 0
	alwaysonbottom = .f.
	alwaysontop = .T.
	eventi		= .f.
	
	PROCEDURE Load
		Declare SetLayeredWindowAttributes in Win32Api as _Sol_SetLWA Integer, string,integer, integer
		Declare SetWindowLong in Win32Api as _Sol_SetWL  Integer, Integer, Integer
		
		_Sol_SetWL(thisform.hWnd,-20, 0x00080000)
		_Sol_SetLWA(thisform.hwnd,0,255,2)
	ENDPROC
 
 
	Procedure init
			WITH Thisform
		            .TitleBar    = 1
		            .BackColor    = Rgb(255,255,255)
		            .BorderStyle= 0
		            .Caption    = ""
		            .Closable    = .F.
		            .ControlBox    = .F.
		            .icon = ''
		            .clipcontrols = .f.
		            .TitleBar    = 0
			EndWith 
	EndProc 

 	Procedure KeyPress
	    LPARAMETERS nKeyCode, nShiftAltCtrl
		If nkeycode = 27
			If this.eventi 
				Clear Events 
			Else
				Release thisform
			EndIf 	
		EndIf 	
	EndProc 	
 	
	Procedure chgtrasp
		Parameters XVAL
		_sol_SetlWA(thisform.hwnd,0,XVAL,2)
    	EndProc 
ENDDEFINE
Here is the form I use to put the commandbuttons on.
I launch it after I run the two previous forms
DEFINE CLASS FormButt AS form 
	activeclick       = .f.    
	ShowWindow = 2
	nFlags = 0
	Caption        = ""
	Closable    = .F.
	ControlBox    = .F.
*	TitleBar    = 0
	backcolor = Rgb(255,0,255)
	alwaysontop = .t.
	eventi		= .f.	

	PROCEDURE Load
		DECLARE Long ReleaseCapture IN WIN32API
		DECLARE Long SendMessage IN WIN32API ;
                Long HWND, Long wMsg, Long wParam, Long Lparam
	ENDPROC

 
     PROCEDURE Init
             
	    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
        
			WITH Thisform
		            .Caption    = ""
		            .Closable    = .F.
		            .ControlBox    = .F.
		            .TitleBar    = 0
		            .BackColor    = RGB(255,0,255)
		            .nFlags = 0
			EndWith 

         EndProc 

 
	Procedure MakeTrasp
	 	This.Makeirregular(Thisform.HWnd,Thisform.BackColor)	
	 EndProc 	

	Procedure click
 		If !this.activeclick
 			Return
 		EndIf 
 		this.Controls(1).click()	
 	EndProc 

	PROCEDURE MakeIrregular
	********************************************************************************
	* 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

*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.
      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)
ENDPROC

	
	
	PROCEDURE Destroy
		CLEAR DLLS    
	ENDPROC

ENDDEFINE
When I launch the application I got this error :

File '_sol_setlwa.prg' does not exist._sol_SetlWA(thisform.hwnd,0,XVAL,2)
Procedure : FORMIX.CHGTRASP

I guess it is due to the fact I set the same flags in two different way so that i overwrite the first setting, loosing its' reference
but I don't know what to do to make these two class keeping together :)


SetWindowLong(nHWND, GWL_EXSTYLE, lnFlags) &&Sets the new flags to the window
SetLayeredWindowAttributes(nHWND, nColor, 0, LWA_COLORKEY)

How can I go through that ?

thanks
Alessio
Reply
Map
View

Click here to load this message in the networking platform