Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. sponsors. rss.
 From: Boudewijn Lutgerink
  Where is Boudewijn Lutgerink?
 Paalbalk Huissen
 Netherlands
 Boudewijn Lutgerink
 To: Steve Bloodsworth
  Where is Steve Bloodsworth?
 Sarasota
 Florida - United States
 Steve Bloodsworth
 Tags
Subject: RE: Hook into form resize?
Thread ID: 25129 Message ID: 25289 # Views: 19 # Ratings: 0
Version: Visual FoxPro 7 Category: Forms
Date: Tuesday, July 01, 2003 8:40:42 AM         
   


There are, in the given example, two controls involved. One is the form, the other is the behavior control that is based on a customclass.

The form has a property oFormBehavior that is, initially, set to .null.
Another property is the cFormbehavior which is a comma delimited list containing the names of behaviorclasses.

The load of the form looks like this:
WITH THIS
	.LoadDataBehavior()
	.LoadFormBehavior()
	.LoadMouseBehavior()
ENDWITH


At this place the formbehavior classes are loaded. That method looks like this.

LOCAL lcSaveBehavior, lcBehavior, loBehavior, lnI

*
* Save the behavior property
*
lcSaveBehavior = ThisForm.cFormBehavior

*
* Create the hook property
*
Thisform.AddProperty('oFormBehavior', NULL)

*
* Load the linked list of FormBehavior objects.
*
DO WHILE !EMPTY(ThisForm.cFormBehavior)

	* Loop through all behaviors
	*
	ThisForm.cFormBehavior = CHRTRAN(ThisForm.cFormBehavior, ' ', '')
	lnI = AT( ',', ThisForm.cFormBehavior)
	
	IF lnI = 0

		* The last behavior
		*
		lcBehavior = ThisForm.cFormBehavior
		ThisForm.cFormBehavior = ''
	ELSE

		* More to come
		*
		lcBehavior = SUBSTR(ThisForm.cFormBehavior, 1, lnI - 1)
		ThisForm.cFormBehavior = STUFF(SUBSTR(ThisForm.cFormBehavior, lnI), 1, 1, '')
	ENDIF
	
	IF NOT EMPTY(lcBehavior)

		* A behavior class found, load it
		*
		loBehavior = CreateObject(lcBehavior, ThisForm)
         
		IF ISNULL(ThisForm.oFormBehavior) 
			IF TYPE('loBehavior') = 'O' AND !ISNULL(loBehavior)

				* The first behavior
				*
				ThisForm.oFormBehavior = loBehavior
			ENDIF
		ELSE

			* Add it to the end of the list
			*
			ThisForm.oFormBehavior.AddBehavior(ThisForm, loBehavior)
		ENDIF
	ENDIF
ENDDO

* Make sure there is at least one object.
*
IF ISNULL(ThisForm.oFormBehavior)
	ThisForm.oFormBehavior = CreateObject('BaseFormBehavior', ThisForm)
	* by passing a reference from the form to the object to be created that ref comes in the init of that object...
ENDIF

ThisForm.cFormBehavior = lcSaveBehavior


This approach gives you the possibilities to add any behavior to forms, the only thing you have to do is add the classname to the list.

Now, among other things you will find, in the init of the form a line like this:

llReturn = ThisForm.oFormBehavior.FormInit(ThisForm)


As you can see the form passes itself to the forminit of the behaviorclass, which looks like this:

VFP>
* forminit method of a behaviorclass.

LPARAMETERS toForm

#INCLUDE Include\AppInc.h

WITH toForm

* Save the original size
*
THIS.nOldWidth = .Width
THIS.nOldHeight = .Height


* Set the maximum size
*
.MaxHeight = .Height * 1.25
.MaxWidth = .Width * 1.25

* Set the minimum size
*
.MinHeight = .Height / 1.25
.MinWidth = .Width / 1.25

* Enable the maximize button and set the form border
*
.maxbutton = TRUE
.BorderStyle = BORDER_SYSTEM && 3
ENDWITH


I had to tweak the code a bit for showing it on the forum.
If you have any Q's ask them!

For more info on this technique see my articles on "Hooked on objects" in the article section of foxite.

Boudewijn Lutge®ink
Boudewijn.Lutgerink@foxite.com
"Unless something happens that we can't predict, I don't think a lot will happen."



COMPLETE THREAD
Hook into form resize? Posted by Michael Gill @ 6/25/2003 10:10:14 PM
RE: Hook into form resize? Posted by mike castillo @ 6/26/2003 1:56:58 AM
RE: Hook into form resize? Posted by Karben Selim Mejia @ 6/26/2003 4:57:35 PM
RE: Hook into form resize? Posted by Boudewijn Lutgerink @ 6/29/2003 5:19:13 AM
RE: Hook into form resize? Posted by Steve Bloodsworth @ 6/30/2003 4:45:04 PM
RE: Hook into form resize? Posted by Boudewijn Lutgerink @ 7/1/2003 8:40:42 AM