*--------------------------------------------------------------------------------------------------------------------------------------------------------
* (EN) AUTOGENERATED - ATTENTION!! - NOT INTENDED FOR EXECUTION!! USE ONLY FOR MERGING CHANGES AND STORING WITH SCM TOOLS!!
*--------------------------------------------------------------------------------------------------------------------------------------------------------
*< FOXBIN2PRG: Version="1.21" SourceFile="vfpx.vcx" CPID="1252" /> (Solo para binarios VFP 9 / Only for VFP 9 binaries)
*
*
DEFINE CLASS bindwindowseventsproxy AS custom 
 	*< CLASSDATA: Baseclass="custom" Timestamp="" Scale="Pixels" Uniqueid="" />

	*<DefinedPropArrayMethod>
		*m: _msghandler
		*p: _hwnd
		*p: _lparam
		*p: _msg
		*p: _result
		*p: _windowproc
		*p: _wparam
	*</DefinedPropArrayMethod>

	*<PropValue>
		Name = "bindwindowseventsproxy"
		_hwnd = 0
		_lparam = 0
		_msg = 0
		_result = .NULL.
		_windowproc = 0
		_wparam = 0
	*</PropValue>
	
	PROCEDURE Destroy
		#Define WM_THEMECHANGED        0x031A
		
		If Type("This.Parent") # "O" Then
		   Unbindevents(_vfp.HWnd, WM_THEMECHANGED)
		Endif
	ENDPROC

	PROCEDURE Init
		*!*	*!* Add BindWindowsEventsProxy property to _VFP :
		*!*	If Not Pemstatus(_vfp,"BindWindowsEventsProxy", 5)
		*!*		AddProperty(_vfp,"BindWindowsEventsProxy", .Null.)
		*!*	Endif
		
		*!*	*!* Create BindWindowsEventsProxy object:
		*!*	If Not Vartype(_vfp.BindWindowsEventsProxy) = "O"
		*!*		_vfp.BindWindowsEventsProxy = Newobject("BindWindowsEventsProxy", Addbs(Justpath(This.ClassLibrary))+"vfpx.vcx")
		*!*	Endif
		
		*!*	*!* Bind to BindWindowsEventsProxy _Msg property changes:
		*!*	Bindevent(_vfp.BindWindowsEventsProxy,"_Msg", This,"_VFPMessageHandler")
		
		*!*	*!* _VFPMessageHandler procedure
		*!*	Do Case
		*!*		Case _vfp.BindWindowsEventsProxy._Msg = WM_THEMECHANGED
		*!*		*!* Do your theme changing stuff here
		*!*	Endcase
		
		*!* Never destroy the BindWindowsEventsProxy object, some other object might be using it
		
		#Define WM_THEMECHANGED        0x031A
		#Define GWL_WNDPROC            (-4)
		
		Declare Integer GetWindowLong In win32api As apiGetWindowLong ;
			Integer HWnd, ;
			Integer nIndex
		
		Declare Integer CallWindowProc In win32api As apiCallWindowProc ;
			Integer lpPrevWndFunc, ;
			Integer HWnd, ;
			Integer Msg,;
			Integer wParam,;
			Integer Lparam
		
		This._WindowProc = apiGetWindowLong(_vfp.HWnd, GWL_WNDPROC)
		
		If Type("This.Parent") # "O" Then
			Bindevent(_vfp.HWnd, WM_THEMECHANGED, This, "_MsgHandler", 4)
		Endif
		
	ENDPROC

	PROCEDURE _msghandler
		Lparameters HWnd As Integer, Msg As Integer, wParam As Integer, Lparam As Integer
		
		Local lnResult
		
		This._hwnd 		= m.HWnd
		This._wParam 	= m.wParam
		This._lParam 	= m.lParam
		This._Msg 		= m.Msg
		
		If Isnull(This._Result) Then
			m.lnResult = apiCallWindowProc(This._WindowProc, m.HWnd, m.Msg, m.wParam, m.lParam)
		Else
			m.lnResult = This._Result
			This._Result = .Null.
		Endif
		
		Return m.lnResult
		
	ENDPROC

ENDDEFINE
