BBC BASIC for Windows
General >> General Board >> Automatically opening a TEXTEDIT.BBC file http://bb4w.conforums.com/index.cgi?board=general&action=display&num=1283619549 Automatically opening a TEXTEDIT.BBC file
Post by Danny72 on Sep 4th, 2010, 4:59pm
Hello
Could someone let me know how one could (from another bbc4w program) automatically open a .txt file in the TEXTEDIT program.
e.g. for textedit to start-up and to open a file called test.txt
And also, Can the TEXTEDIT be automatically opened to a certain width e.g. 350 pixels?
Many thanks,
Danny
REM. A simple text editor in BBC BASIC for Windows, 19-Aug-2007, 02-Dec-2009 INSTALL @lib$+"WINLIB5"
REM. Set up 'interrupts': Menu% = 0 ON CLOSE IF FNchanged PROCexit ELSE RETURN ON MOVE PROCmove(@msg%, @wparam%, @lparam%) : RETURN ON SYS Menu% = @wparam% : RETURN ON ERROR SYS "MessageBox", @hwnd%, REPORT$, 0, 48
REM. Main loop: REPEAT K% = 0 : SWAP K%, Menu% CASE K% OF WHEN 20: IF FNchanged PROCnew WHEN 21: IF FNchanged PROCload WHEN 22: IF FNsave PROCunchanged WHEN 23: IF FNsaveas PROCunchanged WHEN 24: IF FNchanged PROCexit WHEN 30: SYS "SendMessage", Hedit%, &C7, 0, 0 WHEN 31: SYS "SendMessage", Hedit%, &300, 0, 0 WHEN 32: SYS "SendMessage", Hedit%, &301, 0, 0 WHEN 33: SYS "SendMessage", Hedit%, &302, 0, 0 WHEN 34: SYS "SendMessage", Hedit%, &303, 0, 0 WHEN 35: SYS "SendMessage", Hedit%, &B1, 0, -1 WHEN 40: PROCfont ENDCASE PROC_setfocus(Hedit%) WAIT 1 UNTIL FALSE END
DEF PROCexit PROC_closewindow(Hedit%) QUIT
DEF PROCmove(M%, W%, L%) IF M%=5 SYS "MoveWindow", Hedit%, 0, 0, L% AND &FFFF, L% >> 16, 1 ENDPROC
DEF PROCfont : LOCAL F%, R% SYS "ChooseFont", cf{} TO R% IF R% THEN SYS "SendMessage", Hedit%, &31, 0, 0 TO F% IF F% SYS "DeleteObject", F% SYS "CreateFontIndirect", cf.lpLogFont% TO F% SYS "SendMessage", Hedit%, &30, F%, 1 ENDIF ENDPROC
Could someone let me know how one could (from another bbc4w program) automatically open a .txt file in the TEXTEDIT program.
One method is to modify the TEXTEDIT program so that just before entry to the 'main loop' it checks the contents of the @cmd$ system variable. If it finds a path/filename there, it could automatically open that file instead of waiting for the user to open one himself.
With that modification (and assuming TEXTEDIT is then compiled to an executable) another program could run it using something like:
Code:
OSCLI "RUN TEXTEDIT "+file$
Where file$ is the path/name of the text file you want to open.
Quote:
And also, Can the TEXTEDIT be automatically opened to a certain width e.g. 350 pixels?
When you compile it, set the Initial window width and Initial window height to your preferred values (probably you will also want to select the Client radiobutton). Alternatively, achieve the same effect by adding this compiler directive, or similar, to the TEXTEDIT program:
Code:
REM!Window 350,300,client
Richard.
Re: Automatically opening a TEXTEDIT.BBC file
Post by Danny72 on Sep 6th, 2010, 6:38pm
Thanks for the reply.
I am however stumped as to what code to use so that "it checks the contents of the @cmd$ system variable". Could you perhaps let me know exactly what line/s would be required, I assume just before the REM. Main loop:
ON SYS Menu% = @wparam% : RETURN ON ERROR SYS "MessageBox", @hwnd%, REPORT$, 0, 48
REM. Main loop: REPEAT
Re: Automatically opening a TEXTEDIT.BBC file
Post by JonR on Sep 6th, 2010, 7:33pm
To demonstrate the concept of what @cmd$ contains compile the following program which displays the value of @cmd$ in quotes:
Code:
REM Display the value of @cmd$ in quotes
PRINT "'"@cmd$"'"
END
Run the program with and without passing a filename in the command line:
Code:
MyProg.exe
and Code:
MyProg.exe MyFile.txt
Though I presume that this was the first thing you did.
You should notice something about the value of @cmd$ and that should suggest what you should do. You're right that you should do it before the main loop.
Experiment with code based on the appropriate PROC in the code you listed (you wrote it right) to get what you need.
Re: Automatically opening a TEXTEDIT.BBC file
Post by Danny72 on Sep 7th, 2010, 2:56pm
Thanks for the message.
I'm really struggling to understand what it is that I should literally put into the TEXTEDIT program. I have tried experimenting with the information given but cannot get anywhere.
Is it
PRINT "'"@cmd$"'"
just before the Main Loop
thanks
Re: Automatically opening a TEXTEDIT.BBC file
Post by admin on Sep 7th, 2010, 5:38pm
At that point in the TEXTEDIT program the 'output window' is completely covered by the edit control. Therefore a PRINT statement inserted into the program, for debugging purposes, won't have a visible effect (it will be hidden behind the edit control)!
If you want to add a debugging line to your program I would suggest using a Message Box; that will display in front of the edit control so you will be able to see it:
Code:
SYS "MessageBox", Hedit%, @cmd$, "Debug", 0
What this will show you is that @cmd$ contains the command-line parameter(s), if any, passed to your compiled program.
The main alteration that you will need to make to the TEXTEDIT program is to split PROCload into two parts: the part that prompts the user to select a file (which you want to bypass) and the part that actually loads the file (which you want to keep). Hopefully you can see how to do that.
Richard. Re: Automatically opening a TEXTEDIT.BBC file
Post by JonR on Sep 7th, 2010, 5:49pm
When you compiled the test program and ran it passing a filename to the program what did you see?
Unfortunately adding the PRINT statement to TEXTEDIT.BBC program might not be useful as the printed text will likely be coevered by the edit control. You want to set the window title to the file name and load the file without opening the open file dialog box. Everything you need can be adapted from the appropriate procedure(s) in the code.
I'd prefer if possible not to give you the exact solution to this problem, I'd rather you wrote the code.