7 replies
by gdalbr
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.
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?
by gdalbr
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.
by gdalbr
Continuing the saga of the "perfect" viewport.
As anyone who has read my previous blog about the scrollable view port knows, if you start moving the Parent window around, funky things happen. Basically by using the API's to set one window as a child of the other, windows knows about this, but VFP does not. Thus if you move the parent window, the child "appears" to move as well. But Windows keeps this a secret and does not tell VFP. Hence the clickable areas of the viewport are left behind. So if you move the Parent window, you lose the ability to click anything in the viewport. If you move the window exactly back to where it was clicking returns. Go figure.
Read about it here
Foxprow 2.6 has a command where you could open a window INSIDE another:
SHOW WINDOW child IN WINDOW Parent. However the VFP help files says that Show window can be used only with windows defined using DEFINE WINDOW....bummer. How to do that with a visual class form?
But wait theres more...
There is a way to do this by specifying the NAME of the window.Once you have set the NAME property of your form you can refer to it as any other object.
Armed with this, there is only a couple more steps to do.Since I have added my form class WITH the objects in it to the VFP Toolbox, I right click on it in the toolbox and select the menu option Create Form. This creates a form for me based on my form class, complete with scroll bars and objects. I changed the property Name = scroller and saved it.
One more thing to do. I opened my parent form and gave it too a name = ScrollParent. I opened the INIT code and deleted all those API calls of Set Parent etc.
I added the following code in the INIT:
DO FORM scroller NOSHOW
SHOW WUNDOW scroller IN WINDOW scrollparent
With Scroller
.Top = ThisForm.Placeholder.Top
.Left = ThisForm.Placeholder.Left
.Height = ThisForm.Placeholder.Height
.Width = ThisForm.Placeholder.Width
ENDWITH
Thats all. I then ran my parent form and voila the viewport appeared. This time VFP knew about the new window acting as a child. I could move the main window and the child followed. I could even click. Begone API's Viva la Foxpro.
My friend Malcolm Greene has been providing me feedback and this encouraged me to dig deeper and try to fix the main clicking/moving problem. Now I have a proper scrollable viewport. I can move the form and the clicks move with it. Still one more problem to solve - the Activate/Deactivate of the parent gets fired if I switch to the viewport (That Malcolm is persistent)
For now, I can live with that in my app that uses this viewport. One can't have everything can one?
Later..
by gdalbr
After solving the problem of the funky behaviour of the scroll bar in this post I was ready for new pastures. But my pal Malcolm would not let up.
How is your scrollbar class handling the following challenges:
1. Parent form Deactivate/Active events fired when scrollable container (window and/or window scrollbars) get focus.
2. Having your scrollable container have a working .Anchor property so it can automatically shift and resize as its parent form is resized.
he fired back at me.
Well a form does NOT have an anchor property but that should not stop us.
Although I have not exactly done as requested, I have a solution. Remember the invisible ScrollViewport placeholder? It's still on the form and is still an object that VFP can see, although you can't because it's VISIBLE = .F.
So open the parent form and set the Anchor property of the placeholder to (you have upgraded to VFP9 I hope) :
Anchor = 15
One more thing to do. Bind the child form to the anchors of the viewport. To do this we need a reference. Create a custom property of the parent form called oChild. Add the following line after the original code in the INIT so that it looks now:
DO FORM scroller NOSHOW
SHOW WUNDOW scroller IN WINDOW scrollparent
With Scroller
.Top = ThisForm.Placeholder.Top
.Left = ThisForm.Placeholder.Left
.Height = ThisForm.Placeholder.Height
.Width = ThisForm.Placeholder.Width
ENDWITH
ThisForm.oChild = scroller
Finally in the RESIZE of the parent form add this smidgen of code:
WITH ThisForm.oChild
.Top = ThisForm.Placeholder.Top
.Left = ThisForm.Placeholder.Left
.Height = ThisForm.Placeholder.Height
.Width = ThisForm.Placeholder.Width
ENDWITH
And that's that for the Anchor where the Anchor = 15
Next task is to get this code in the Scroll Class iteslf. This should be trivial. Just move the above code from the resize event of the parent into a custom method of the child and add code to BIND EVENTS () of the Parent Resize to the custom resize of the child, based on a property. Also this is for an anchor of 15 so if you wanted to handle all the other Anchor settings then a case statement is the go.
#1 I still haven't solved (yet) but it should only be a matter of time.
Bring it on Mal.
Later...
by gdalbr
Craig Bailey on his blog talks about how to make VFP look cool. As he says, its all in the mind ? perception - VFP is xbase and is old technology, VFP controls look dated etc. We need to change that.This is a must read...(read more)
by gdalbr
The techniques involved with making these tabs are simple and straight forward. Since I use no API?s , to achieve the gradient effect requires a bitmap, one for each colour used. The techniques used here are my own. Opinions may vary but this is how I do it....(read more)
by gdalbr
The Windows Vista CPT is out and is being downloaded desperately by whoever has the bandwidth. One of the "eye candy" items of Vista themes is something called Glass Forms. When applied, it gives an effect that the form is transparent - like glass.
However don't rush out and set this up since your current graphics card may not support its requirements. Also it is a huge resource hog and recommendations are that only a small part of the window should be glassed.
So what should we others do then?...(read more)
This discussion is closed to new replies.
Trending After Hours posts
Sort by Trending