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 [:(]

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…

2 Responses to Thinking Outside the Box

  • fdbozzo says:

    You can do that in VFP without Windows API. Just use this in a form to see a form inside that is movable and sizeable and minimizable:

    THISFORM.ADDPROPERTY("ofrm_interior", CREATEOBJECT("Form"))

    THISFORM.oFrm_Interior.MOVE(50,50,300,200)

    SHOW WINDOW (THISFORM.ofrm_interior.NAME) IN WINDOW (THISFORM.NAME)

    If you want the scrollbars, then replace "Form" with a custom form class with scrollbars enabled.

    Hope that this helps,

    Fernando D. Bozzo

    Madrid/Spain

  • edyshor says:

    Thanks Bernard, and thanks Fernando,

    i needed a fast scrollable container and I’ve settled for Fernando’s simple method. For now at least, when I’ll have more time I’ll be looking into it for a neat and almost foolproof solution.

    Thank you both.

Leave a Reply

Your email address will not be published. Required fields are marked *