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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ShellExecute Notepad to Open Text Files For Read Only 1

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
US
I'm opening some text reports using notepad (the default for these files) which works fine, but I would like to open them as read only. I assume it has something to do with the Parameters but I can't find any information on them.
Code:
LOCAL cFullFileName

cFullFileName = "Old Reports\" + ALLTRIM(This.Value) + ".LST"

If Not Thisform.ShellExecute
	DECLARE INTEGER ShellExecute ;
		IN SHELL32.DLL ;
		INTEGER nWinHandle,;
		STRING cOperation,; 
		STRING cFullFileName,;
		STRING cParameters,;
		STRING cDirectory,;
		INTEGER nShowWindow
	Thisform.ShellExecute = .T.
Endif

* Open File Using Default File Association
If File(cFullFileName)
	Try
		ShellExecute(0, "open", cFullFileName, "", "", 1)
	ENDTRY
Else
	Do Form MessageForm with 'Notice', ;
		'File doest not exist.', ;
		(gButtonOK), (gIconExclaim), (gDefaultButton1st)
ENDIF


Auguy
Sylvania/Toledo Ohio
 
Notepad has no protected mode in which you could display texts readonly.

Either you use FILETOSTR() and display texts in an Readonly Editbox, or you do MODIFY FILE filename.txt NOEDIT, which opens VFPs internal editor in read only mode.

Bye, Olaf.
 
Based on some web searches it looks like you cannot do what you want in Notepad.

From one of the search 'finds'
There is but a limited set of command line options:

/A <filename> open file as ansi
/W <filename> open file as unicode
/P <filename> print filename
/PT <filename> <printername> <driverdll> <port> print filename to designated printer

I'd recommend looking into another approach.
1. Copy original file into a Temp File (its properties could be set ReadOnly or not). Open the Temp File into Notepad. Then any changes would be 'trashed' when the Temp File is programatically Erased.
2. Change the File Properties of the original file to ReadOnly before opening into Notepad.
3. Use Notepad++ instead of Notepad because it has a -ro parameter
4. Other approaches?

Good Luck,
JRB-Bldr
 
Thanks to both of you. I have used the edit box before but these text files are reports and have some very long lines that I don't want to wrap because the data is in columns. I guess I will just mark the files as read only as there are only a few of them and they should not change over time as they are historical reports.

Auguy
Sylvania/Toledo Ohio
 
If you were interested in using a Notepad alternative, there are a number of free file viewers (not Editors) out on the web.

One that looks interesting (although I have not used it myself) is a free one called:
FreeFileViewer ( )

Good Luck,
JRB-Bldr
 
Thanks, I will check it out

Auguy
Sylvania/Toledo Ohio
 
You could also use ALINES and show the file in a 1 column grid. Anchor it and you even can introduce line highlighting and more.

Bye, Olaf.
 
Thanks Olaf. I would probably use that method but these text reports have rows almost 400 characters wide. Believe ir or not but they are a dump of all fields out of an old PC-File database and I wanted to make sure I got all of the data for conversion. Hmmm, maybe I could use a grid and have the one column be a memo field that was filled using alines with one record per line.

Auguy
Sylvania/Toledo Ohio
 
>Hmmm, maybe I could use a grid and have the one column be a memo field that was filled using alines with one record per line.

Very good thought, that would also be my answer to that 400 char wide lines problem. You have to test whether this means the text of the single line would still be wrapped in the editbox per row in the grid, but even if it would wrap, you could set the rowheight to only show the first editbox line. The rest is anchoring the grid and resizing the single column via Grid.Resize Event.

Bye, Olaf.
 
Soemthing along these lines:

Code:
**************************************************
*-- Form:         form1 (f:\privat\textviewer.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   06/13/13 06:05:00 PM
*
DEFINE CLASS form1 AS form


	Top = 0
	Left = 0
	Height = 369
	Width = 482
	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"


	ADD OBJECT grid1 AS grid WITH ;
		ColumnCount = 1, ;
		Anchor = 15, ;
		DeleteMark = .F., ;
		GridLines = 0, ;
		Height = 348, ;
		HighlightRow = .F., ;
		HighlightRowLineWidth = 0, ;
		Left = 12, ;
		Panel = 1, ;
		RecordMark = .F., ;
		RowHeight = 24, ;
		ScrollBars = 3, ;
		Top = 12, ;
		Width = 456, ;
		Name = "Grid1", ;
		Column1.FontName = "Courier New", ;
		Column1.Width = 426, ;
		Column1.Sparse = .F., ;
		Column1.Name = "Column1"


	ADD OBJECT form1.grid1.column1.header1 AS header WITH ;
		Caption = "Header1", ;
		Name = "Header1"


	ADD OBJECT form1.grid1.column1.edit1 AS editbox WITH ;
		FontName = "Courier New", ;
		BorderStyle = 0, ;
		Height = 53, ;
		Left = 227, ;
		Top = 35, ;
		Width = 100, ;
		Name = "Edit1"


	PROCEDURE Load
		TEXT TO lcText noshow
Insert some lengthy (wide) text here.
Insert some lengthy (wide) text here.
Insert some lengthy (wide) text here.
        ENDTEXT

		CREATE CURSOR curText (mMemoLine M) 

		FOR lnLine = 1 TO ALINES(laText,lcText)
		    INSERT INTO curText Values (laText[lnLine])
		ENDFOR 
	ENDPROC


	PROCEDURE grid1.Init
		this.column1.Width = 4000
	ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************
I bet it won't work, but it gives you the idea. The problem with a single column grid is, the horizontal scrollbar won't let you scroll, even if you set the column width wider than the grid is. I have no idea how to overcome this problem.

Bye, Olaf.
 
I wonder if adding a dummy column to the left of the edit box in the grid would make the scroll bar show up? I will test if I get some time. Thanks.

Auguy
Sylvania/Toledo Ohio
 
I did that - somehow yes, but you only scroll full columns.
The solution seems to be, to not only make the column wide, but also make the grid wider than the form and use form scrollbars.

It's easy to define the grid height to show all rows as you know the row number, but to determine the full text width you have to use Form.TEXTWIDTH() of the longest line, in Proportional fonts this does not need to be the line with the most characters in it, though. So you could determine the maximum ThisForm.TEXTWIDTH(laText[lnLine])) value, while filling the cursor.

Bye, Olaf.

 
You can't guarantee the user will get NotePad or any alternative you may ship. It the user has associated .lst files with something else, that's what you'll get.

Craig Berntson
MCSD, Visual C# MVP,
 
If using Shellexecute() the criticism is correct, you always get what is associated with a file extension. But you can also start editors directly with parameters and just need one supporting that and supporting read only mode. But we also already arrived at the suggestion to use a grid for display the file.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top