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!

VFP Project Manager "Other" tab to open appropriate Editors like MS WORD for every file ty 3

Status
Not open for further replies.

dkean4

Programmer
Feb 15, 2015
282
US
First, VFP ROCKS!

VFP Project Manager allows you to add any type of file on the "Other" Tab. But trying to Modify only works for text, JPG and possibly BMP files (It would seem only for a few of us.). So, then, in my case, to be able to open any file "type" using the default editor, you need to use Project Hook. Don't faint yet. There is advice on how to add a project Hook, here on Tek-Tips. It is very easy. Once you have added it, you must shut down your Project Manager and open the project hook manually... something like this:

MODIFY CLASS phook OF f:\a_i\classes\phook.vcx

Once the PHook class is opened, find the Event "QueryModifyFile" and add something like this to it.

LPARAMETERS oFile, cClassName

IF LOWER(JUSTEXT(oFile.name))="docx" ;
OR LOWER(JUSTEXT(oFile.name))="doc";
OR LOWER(JUSTEXT(oFile.name))="graphml";
OR LOWER(JUSTEXT(oFile.name))="ufo"; && Make sure that the file Extension case is correctly entered

NODEFAULT
DECLARE INTEGER ShellExecute IN shell32.dll ;
INTEGER hndWin, ;
STRING cAction, ;
STRING cFileName, ;
STRING cParams, ;
STRING cDir, ;
INTEGER nShowWin

cAction = "open"
ShellExecute(0,cAction,oFile.name,"","",1)
ELSE
DODEFAULT(oFile, cClassName)
ENDIF


Save your Project Hook. And now you have full power over every kind of default file editor used to edit your extraneous files... for your VFP Project. No need to get out of VFP and go find files in their own directory. Just DoubleClick the files added in the Other Tab of your VFP Project Manager. I use Flow chart editors, GimpShop, MS WORD 2003, 2010, NotePad++, InkScape, Blender, Photoimpact and other. You can use the "Text Files" sub-heading or the "Other Files" sub-heading to add your new resources. Have fun... (And if it is only me, then, I'm having a blast.)

Dennis
 
You could edit your post and change the Thread Type to "Helpful Tip".

It really is, though I have to say this doesn't need any project hook for me, a double click on any file type opens the default associated application to me, without any project hook.
Did you have any case of files not acting that way, before you introduced this ShellExecute handling?
Did you perhaps have problems due to the OS or another project hook overriding the base behaviour?

Bye, Olaf.


 
If you need to implement what's really default behavior, you must have broken something earlier.
 
Hello Dennis,

Welcome to the forum. I don't want to discourage you from posting this sort of helpful tip, especially when you have put some effort into posting your code. But it is not correct to say that "trying to Modify only works for text, JPG and possibly BMP files". In fact, you can do that for any file type that has an association within Windows.

Some years ago I wrote a piece for Foxpro Advisor that suggested keeping your documentation files in a project in certain circumstances. Those files might well be DOC or DOCX files created in Microsoft Word. You can certainly edit them - and save the edits - by clicking Modify in the Project Manager.

The important thing is to remember to exclude them from the build.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Sorry, guys, but try as I may, that was not working for me. Thank you all for the quick reply, I will test it without the hook again. But I spent an afternoon testing it and in fact read some posts on TT which agree with me that only text files and images are properly invoked with the default editors. One guy claimed that WordPad was default as well, but not for me. I went to the Command prompt, and tried opening files in File Explorer, and they default correctly. So it is not the OS.

This was critical functionality for me. I do lots of graphics, FlowCharts to make VFP screens look modern. And I finally got ticked off last night and used the Hook! So I got my fish and thought I would share it with others. I would have asked, but I ran into an answer which concurred with my former conclusion that only text and images default properly.

Anyway, you guys are tops. Your contribution is so appreciated! The VFP community and VFP ROCK!

Dennis
 
Well, when I asked about the OS I meant perhaps the VFP Project manager behaves differently per OS, maybe also per VFP version.
It's no question you get the right associated applications started from within the Windows Explorer, but I believe you did this hook code for a reason, that's undoubted.

You know, I once added a feature to an Intellisense extension ISX.prg to turn typing of var++ into var = var + 1, not seeing that VFP did this on its own anyway...

Bye, Olaf.
 
It would be interesting to know exactly what happens when you click on Modify. If you see a message saying "The file named xxxx could not be edited", that indicates that there is no file association.

Just as an experiment, I've just tried adding a Kindle e-book, an MP3 file, a binary file associated with my note-taking program, and several CSS and PHP files. They all get launched as expected when you click on Modify (of course, that doesn't mean that you can edit all those file types; the e-book is by its nature read-only, for example).

Having said all this, your efforts with the project hook are by no means wasted - if only as an interesting mental exercise.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Olaf,

I have been using VFP 9.0 since the day it came out. I am now using WIN 7 Ultimate and come to think of if, I was able to invoke the *.DOC files in the Win 7 Professional PCs. Ultimate has its own ticks and mis-behaviors. Maybe others may chime in on that.

And yes, I too have done the ++ in intellisense after the feature came out... and other silly things. Good to hear from you Olaf. You have been a veritable magician in intricate and delicate problems I faced over the years. And so have others...

I did move the Thread to "Helpful Tip". Thanks

(Concerning formatting on TT posts. Indentation does not seem take properly. Does it require spaces?)

Dennis
 
MikeLewis,

Thank you for the kind words. And here is what I get when I remove the project hook.

VFP invokes the "MODIFY FILE <file name>" command

Dennis
 
Hm, seems like there is some (up)settng causing that.

I always wondered, why some actions (like editing a class or changing a workarea in the datasession window) are echoed to the command window and others not.
In case of double clicking a docx/pdf or other file in the other files node, I don't get the MODIFY FILE command invoked, also not when clicking the Modify botton in the project manager.
Neither in Windows 7 Ultimate, nor 8.1 Pro nor 10 Home. Instead always Word or my PDF reader or whatever application gets started.

I know VFP's MRU (most recent used) list can behave different or be turned off by some group policy setting, so even a setting not directly in and of VFP may cause that.

On the other hand, if I manually write a MODIFY FILE "something\my word document.docx" in the command window and execute, the file is opened in the VFP editor, which in turn makes me understand why you would not want that behaviour, that's quite useless, it only makes sense with ascii files like txt.

I don't see what causes this. But it also isn't Windows 7 Ultimate, not alone.

Bye, Olaf.



 
Olaf,

I should have sent you this. This is what happens in the Command Window when I click on the files in the "Text Files" grouping .

MODIFY FILE d:\intel\requests.graphml AS 1252
MODIFY FILE "f:\a_i\documentation\notes on ai.docx" AS 1252
MODIFY FILE f:\a_i\documentation\las.rtf AS 1252
MODIFY FILE f:\a_i\bmps\3d\danny2.ufo AS 1252


Dennis
 
Well, you said so. AS 1252 always is coming from the default codepage you use. That's also written, if you modify a PRG with MODIFY COMMAND instead of MODIFY FILE. VFP also detects, when file names have spaces and delimits such file names with quotes, yes. Nothing unusual, what is unusualy is, that MODIFY FILE is invoked at all. It's not happening here, instead just a shellexecute without any hook doing that.

Bye, Olaf.
 
I don't want to burden you any longer with this. I got it working right and I am thrilled. For now it will be a mystery. Sooner or later I will figure it out. Maybe I will reinstall the VFP. I read up on how some folks recommend installing VFP then directly install SP2. I did it VFP>SP1>SP2. Maybe that is causing some issues. But I am happier than a pig in mud, now. I can sit inside VFP and rule over various file types to my heart's content!

Thanks,

Thanks Olaf.
 
Yes, let's simply summarize this way:

Under unknown circumstances of VFP/Windows settings and policies, maybe mostly in Win7 Ultimate (though not for me) VFP wrongly opens non VFP types you add in project manager "Other files" via MODIFY FILE, showing the binary gibberish of these files in VFPs text editor.

In this case your idea of a hook is easily fixing that.

Two last thoughts:
1. I wonder, if it would pay to work the other way around and only dodefault on VFP file types/extensions and ShellExecute anything else.
2. Though not related to this problem, Sergey Berezniker once showed at how to fix Foxpro file associations, when they are broken, in a way even better than VFP does by default. One of the features is double clicking a DBF in Windows Explorer does not cause a new VFP instance to start, so you can open several dbfs from outside of VFP in one datasession...

See it as a tip for getting something else to be better. I doubt VFP uses MODIFY FILE because the file extensions are registered for itself, because then also ShellExecute would not work. So there might be some setting only in some registry telling VFP what to do with other files and that's wrongly configured for you and others having that problem.

Bye, Olaf.
 
Olaf,

I scoured the registry yesterday morning to find some switch for this. But I gave up half way through. I got it working with Shell and I have other objectives which are more important. Very interesting link at Berezniker and it gives me some ideas. Thanks...


Dennis
 
Last not least, let me return a star to you, as what seemed unnecessary in the first place is a workaround for those needing it.
It was my feeling it's a helpful tip from the beginning, anyway.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top