Thinking Outside the Box
Thanks to the urging by Craig Bailey and Eric kindly providing the web space, I've decided to bite the bullet and get blogging.
The projects at work are keeping me very busy since I am exploring new areas of VFP usage.
My explorations into the capabilities of the FOX have led me to some strange areas and have really made me think about things more "outside the box"
What I mean by that is mostly we approach vfp objects with a standard view. Previously this has led me to do things in a very staid way. But now I approach things very differently.
Here's an example of that.
As we all know VFP does not have native scroll bar objects, so if we want scroll bars we have to use other means. I have seen many implementations of a scrollable container. There are those that use VB ActiveX scroll bars, others that use the WIN API completely and still others like the one found at Craig Boyd's site - http://www.sweetpotatosoftware.com/SPSBlog/PermaLink,guid,df3cb71d-588f-4bc6-b63e-9c94017edd7f.aspx that uses VFP objects.
While all these are nice, they do have their own problems. You have to have the VB runtimes for the ActiveX, you have to have API's so the implementation is not very visual in the VFP Editor, and in Craig's case he has documented some shortcomings like objects “bleeding” through the container into the main form, you can’t hold down the mouse on the scroll bars to get a repeated effect and sometimes the scrolling effect is jerky.
So this led me to think of other alternatives. Which objects in VFP have native scrollbar support and are also containers? The only two are a Grid and a form. I discounted the grid because it was a bit too difficult to manipulate easily and add objects. That left the form.
So I created a form and set the scrollbars property = 3 (both), removed the Title and set the border to 0. This gave me a scrollable container to which I could easily add objects.
Base Scroll Class

I ran the form and scrolled about. So far so good. I then saved it as a class. Next I added it to my Toolbox and created a form from it.
To this form based on my original scroll form class I then added objects as below. The scrollbars then appeared. I saved this too as a class. Now I could easily open this class and add/remove items etc. This form could be instantiated on its own as well. So much for the GUI part.
Scroll Class + Objects

Now if we try and add this class to a new form we get asked if we want to create a form set. I hate formsets so that is not the way to go. Also ADDOBJECT at runtime does not work in a form. If only…
Then I remembered reading somewhere/sometime on Foxite about the 2 Windows API’s SetParent & GetParent and the with that the ideas flowed....
So I created a new form and added a shape as a place holder for my scrollable container, which would give me a visual representation of where the scrollable window would appear and its dimensions. Also the form has a custom property oScroller and a custom method GetScroller
In the INIT of this form I added a call to the custom method – GetScroller()
The code for GetScroller is here:
DECLARE INTEGER SetParent IN User32 INTEGER HWND, INTEGER ParenthWnd
DECLARE INTEGER GetParent IN User32 INTEGER HWND
DECLARE INTEGER MoveWindow IN user32 INTEGER HWND, INTEGER X, ;
INTEGER Y, INTEGER nWidth, INTEGER nHeight, INTEGER bRepaint
SET CLASSLIB TO bbscroll addit
thisForm.oScroller = CREATEOBJECT("scrollobject")
WITH thisForm.oScroller
SetParent(.hWnd, THISFORM.hWnd)
* this positions and refreshes the form
MoveWindow(.HWnd, ThisForm.Scrollplaceholder2.Left, ThisForm.Scrollplaceholder2.Top,;
ThisForm.Scrollplaceholder2.width, ThisForm.Scrollplaceholder2.height , 1)
.visible = .T.
ENDWITH
And that’s it. I now had a scrollable view port with none of the problems of the other classes, that was GUI enabled, editable, no bleed thru and was also ActiveX friendly.
Here’s a look at the form running:
Scroll Form


I also created another subclass of the original form class and this time inserted an IMAGE object into it. Now I had a scrollable view port:
An Image Viewport

There is only 1 problem I see with this above class. ![Sad [:(]](/emoticons/emotion-6.gif)
It does NOT like being moved. You can see the effect by moving the form and then trying to scroll. I have still to come up with an elegant solution to counteract this but till then either you do not move the form or if you have to, then you can use BINDEVENTS and LockScreen to recreate the scroll object once the form has stopped moving.
Any ideas are very welcome. So are comments Till next time…