Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SYS(1500) Help
Message
From
08/01/2008 22:04:49
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01280185
Message ID:
01280444
Views:
16
Hi Sergey,

Thanks for this new sample.

In this new version, you are proposing that we could obtain the PRG info directly using _EdOpenFil.

I'm choosing to keep the first version, because I want to obtain the HTML formatted version of the PRG. Opening the file directly, we can't get the HTML version, only plain text.

I think that the result obtained is the same we could have doing this:
_ClipText = FILETOSTR(lcFile)
To better understand the different results, you can run this modified sample, if you are interested:

In the 1st, the output is PlainText, and in the 2nd (original), we get an HTML formatted version, the same we have in our VFP editor.

Thanks again !
LOCAL lcFile
lcFile = GETFILE("prg")

* Open the VFP Editor
* MODIFY COMMAND (lcFile) NOWAIT NOEDIT


#DEFINE FO_READONLY	0

LOCAL ARRAY laEnv [25]
LOCAL lnHandle, lnResult
SET LIBRARY TO LOCFILE("FoxTools.fll") ADDITIVE
* Open the VFP Editor
lnHandle = _EdOpenFil(lcFile, FO_READONLY)
lnResult = _EdGetEnv( lnHandle, @laEnv )
* [ 2 ]  File Size

* Select ALL
_EdSelect(lnHandle, 0, laEnv[2])

* Copy to clipboard
IF NOT _EdCopy(lnHandle)
	MESSAGEBOX("Couldn't Copy ")
	RETURN .F.
ENDIF	

= _Wclose(lnHandle)



LOCAL loIE as "InternetExplorer.Application"
loIE = CREATEOBJECT("InternetExplorer.Application")
#DEFINE READYSTATE_COMPLETE      4
#DEFINE MAX_TIME                30
#DEFINE OLECMDID_PASTE          13
#DEFINE OLECMDEXECOPT_DODEFAULT  0

local lcInnerHTML && HTML of the webpage
local lnStarted && Seconds when started loading
local lnWaiting && Seconds waiting for the document to load
local lcRetVal && Return Value

lnStarted = SECONDS()

loIE.navigate("about:blank")

* Wait till page totally loaded
DO WHILE loIE.Readystate <> READYSTATE_COMPLETE or lnWaiting >= MAX_TIME
   lnWaiting = SECONDS() - lnStarted
ENDDO

* Make the page editable
loIE.Document.Body.contentEditable = .T.

* Paste Clipboard content
loIE.ExecWB(OLECMDID_PASTE, OLECMDEXECOPT_DODEFAULT)

* Retrieve the HTML
lcInnerHTML = loIE.Document.Body.InnerHTML

* Save to HTM file
LOCAL lcDestFile, lcCommand
lcDestFile = FORCEEXT(lcFile, "htm")
STRTOFILE(lcInnerHTML, lcDestFile)

lcCommand = "RUN /N Explorer.Exe " + lcDestFile
&lcCommand

RETURN
Then, run the original version, and compare the different outputs:
LOCAL lcFile
lcFile = GETFILE("prg")

* Open the VFP Editor
MODIFY COMMAND (lcFile) NOWAIT NOEDIT


* Select all and Copy to Clipboard
* by Sergey Berezniker
LOCAL ARRAY laEnv [25]
LOCAL lnHandle, lnResult
SET LIBRARY TO FoxTools ADDITIVE
* Get the whandle for the current window
lnHandle = _WonTop()
lnResult = _EdGetEnv( lnHandle, @laEnv )
* [ 2 ]  File Size
* [ 17 ] SelStart
* [ 18 ] SelEnd

* Select ALL
_EdSelect(lnHandle, 0, laEnv[2]-1)

* Copy to clipboard
IF NOT _EdCopy(lnHandle)
	MESSAGEBOX("Couldn't Copy ")
	RETURN .F.
ENDIF	


* Close the PRG
RELEASE WINDOWS (JUSTFNAME(lcFile))
= _Wclose(lnHandle)


LOCAL loIE as "InternetExplorer.Application"
loIE = CREATEOBJECT("InternetExplorer.Application") 
#DEFINE READYSTATE_COMPLETE      4 
#DEFINE MAX_TIME                30 
#DEFINE OLECMDID_PASTE          13
#DEFINE OLECMDEXECOPT_DODEFAULT  0

local lcInnerHTML && HTML of the webpage 
local lnStarted && Seconds when started loading 
local lnWaiting && Seconds waiting for the document to load 
local lcRetVal && Return Value 

lnStarted = SECONDS() 

loIE.navigate("about:blank") 

* Wait till page totally loaded
DO WHILE loIE.Readystate <> READYSTATE_COMPLETE or lnWaiting >= MAX_TIME 
   lnWaiting = SECONDS() - lnStarted 
ENDDO 

* Make the page editable
loIE.Document.Body.contentEditable = .T.

* Paste Clipboard content
loIE.ExecWB(OLECMDID_PASTE, OLECMDEXECOPT_DODEFAULT)

* Retrieve the HTML
lcInnerHTML = loIE.Document.Body.InnerHTML

* Save to HTM file
LOCAL lcDestFile, lcCommand
lcDestFile = FORCEEXT(lcFile, "htm")
STRTOFILE(lcInnerHTML, lcDestFile)

lcCommand = "RUN /N Explorer.Exe " + lcDestFile
&lcCommand

RETURN
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform