Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Files in a Control

Status
Not open for further replies.

Scott24x7

Programmer
Jul 12, 2001
2,828
JP
Is it possible to show a file in a control inside VFP?
For example, if I have a PDF that I have associated with a record (store the PDF path and file name in a Memo field for example), when I "view" that record in my form, can I get the PDF to display in some control on the form? (And can this be made to show any file type that is installed on the machine, i.e. Office file, PDF, image, maybe even movie file?)

The idea is more to have a "thumbnail" kind of view, not meant to read or edit from it, but give people some idea of what that file is without having to launch it (which I already have set up with SHELLEXE).

This will be particularly handy on things like presentations (PowerPoing), WMV "movie" file (which I assume needs some play/stop/volume control)?

How does one go about doing this?


Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Even Windows itself has nothing so general, turn on preview in a folder in windows explorer and you don't get a preview of any file type.

The most common thing in the 80s and perhaps 90s was the general field and the oleboundcontrol, but it depends on an ole server available for the file type and it will work even worse than the windows explorer preview. Since avoiding general fields is strongly recommended the only use of it would be a cursor for temporary storage of a single file for the sake of preview. That has it's limitations even for filetypes like doc/docx, which are previewed but look odd, eg Word Docs will be drawn with transparent instead of white background and fonts are not rendered good. Pictures are not showing a preview. And most videos will take quite sime time to load into the general field.

You may play around with some file types amd see for yourself:

Design a new Form, add an oleboundcontol, set its controlsource to curFile.gFile
In the Form Load:
Code:
Create Cursor curFile (gFile G)
In a Button Click:
Code:
lcFile = GetFile() 
ZAP IN curFile
APPEND BLANK
APPEND GENERAL gFile FROM (lcFile)

What's working a little better is the webbrowser control, but it'll depend on plugins what it'll display and how it will display.
If you limit yourself to some file types you can use that quite well, but that's about all I know of.

Discussions here about preview typically are about PDF only and there are ways to use Acrobat OLE classes, but that makes acrobat reader a prerequisite and only works up to an older version, if I remember correctly.

What I could imagine is some kind of ActiveX control specialising on general file previews or a tool generating preview thumbnail graphic files you could display via Image control.

If you look around even C# developers lack a general control for all previews, eg look at what type of controls are used here.
Vista introduced a concept called Previewhandlers, but The interface is hardly implemented for anythong but MS Office document types: and
The concept depends on application developers implementing that interface and since it's a COM interface and most applications don't offer OLE automation of themselves, you can't expect much from that.

Bye, Olaf.
 
>Pictures are not showing a preview.
Especially if you set default application for picture types to some image processing software other than MS Paint.
Eg some picture types for me have gimp associated, most others have irfan view, since it loads much faster.

The Oleboundcontrol shows the icon of Irfanview with the picture file name, when appended into the general field and that is because Irfan has no ole classes handling pictures, so there is no preview even for BMP, unless I'd reset the association. That also was the most known problem with BMPs embedded in General fields on one computer not showing on another.

The solution is executng the shell command ASSOC .BMP=Paint.Picture, executed with cmd.exe started elevated as administrator. But this shows the association is not with the executable mspaint.exe, but with the ole server class Paint.Picture.

In general users won't like, if you play around with file associations, and even if you would for sake of your software previewing correctly, you won't find ole servers you can associate for most file types since Iknow no vendor but MS doing OLE, Acrobat offers a bit in that direction and Apples iTunes is OLE automatable. OLE always lacked support from other vendors.

Bye, Olaf.
 
I have Foxit PDF reader installed and when I make an Olecontrol1 on my form and Insert Control Foxit Reader Control, I can display the PDF in that form. e.g. thisform.olecontrol1.openfile("f:\test.pdf")

But it is not a preview, it's the real reader with all options.

Of course you need to distribute the FoxitReaderBrowserAx.dll I guess.
 
Thanks guys. It sounds like this is another of those features I'll set aside for awhile, while I go for some more critical functionality. It is a "nice to have" for one of my screens, but I think we can live without it for now, since I can already SHELLEXE the files and run them in their full app. It would just be slick to show them in form... particularly video files, which some of our work in Computational Fluid Dynamics is best viewed from the output .WMV animations... But I'll try to think of something.

Thanks heaps.


Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
In general users won't like, if you play around with file associations

You're being kind, Olaf. Any application that does that on my PC will immediately be uninstalled. (And I'll probably spend a lot of time on message boards and other social media fuming about how arrogant and clueless the publisher is. [thumbsup2])

 
In regard of video you can automate the windows media player. WMPLayer.OCX.7 or add an olecontrol and pick "Windows Meida Player" from the list of available controls. Then set olecontrol1.URL = "file://"+home()+"samples\solution\ole\foxrain.avi"

As said, if you concentrate on certain document/file types you find individual controls for them. Solution.app has a samples "Play multimedia files using MCI commands", which also still work.
The mci sample plays the windows sampe nature.wmv video, for example.

Bye, Olaf.
 
Olaf,
Now that is cool. I can have a container that is only visible when the extension is .AVI or .WMV or .MKV etc, any other types like .Doc, .XLSX, etc can just not show that control (even if I have it overlay something else, treat it like I do some image files where I allow them to click it to make it bigger or smaller, but to a fixed size).

The idea of being able to play the media files in the form is still very very useful, and could still allow something like a right click to SHELLEXEC it, in whatever their "native" viewer is if they are really bent on launching it in something else.

I agree with you otherwise, that I don't want to go changing file associations, as that would be annoying, unless I can "manage" it in the application, while still allowing people to control their own PCs.

That said... our objective is a little different, in that this application is for our own enterprise, and we can be a bit more bullish about what people can/can't use (though that's not really my personal philosophy). Point is if we "mandate" VLC then everyone has to follow along... if we "mandate" Office 2013, then since we're covering the licenses anyway, we kind of can decide what people use. (Note that I'm an "Early Adopter" too, so I'm all for the latest and greatest... it's why I'm using VFP9 :)


Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top