BBC BASIC for Windows
« Automatically opening a TEXTEDIT.BBC file »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 11:43pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Automatically opening a TEXTEDIT.BBC file  (Read 706 times)
Danny72
New Member
Image


member is offline

Avatar




PM


Posts: 20
xx Automatically opening a TEXTEDIT.BBC file
« Thread started 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 menus:
AM$ = "AppendMenu"
SYS "CreatePopupMenu" TO H%
SYS AM$, H%, 0, 20, "&New"
SYS AM$, H%, 0, 21, "&Open"
SYS AM$, H%, 0, 22, "&Save"
SYS AM$, H%, 0, 23, "Save &As"
SYS AM$, H%, &800, 0, 0
SYS AM$, H%, 0, 24, "E&xit"
SYS "CreatePopupMenu" TO E%
SYS AM$, E%, 0, 30, "&Undo"
SYS AM$, E%, &800, 0, 0
SYS AM$, E%, 0, 31, "Cu&t"
SYS AM$, E%, 0, 32, "&Copy"
SYS AM$, E%, 0, 33, "&Paste"
SYS AM$, E%, 0, 34, "De&lete"
SYS AM$, E%, &800, 0, 0
SYS AM$, E%, 0, 35, "Select &All"
SYS "CreatePopupMenu" TO O%
SYS AM$, O%, 0, 40, "Set &Font"
SYS "CreateMenu" TO M%
SYS "SetMenu", @hwnd%, M%
SYS AM$, M%, 16, H%, "&File"
SYS AM$, M%, 16, E%, "&Edit"
SYS AM$, M%, 16, O%, "&Options"
SYS "DrawMenuBar", @hwnd%

REM. Create edit window:
Hedit% = FN_createwindow("EDIT", "", 0, 0, @vdu%!208, @vdu%!212, 0, &200044, 0)

REM. Create and initialise data structures for dialogue boxes:
DIM Fn% 255, Lf% 59
DIM fs{lStructSize%, hwndOwner%, hInstance%, lpstrFilter%, \
\ lpstrCustomFilter%, nMaxCustFilter%, nFilterIndex%, \
\ lpstrFile%, nMaxFile%, lpstrFileTitle%, \
\ nMaxFileTitle%, lpstrInitialDir%, lpstrTitle%, \
\ flags%, nFileOffset{l&,h&}, nFileExtension{l&,h&}, \
\ lpstrDefExt%, lCustData%, lpfnHook%, lpTemplateName%}
ff$ = "TXT files"+CHR$0+"*.TXT"+CHR$0+"All files"+CHR$0+"*.*"+CHR$0+CHR$0
ex$ = "txt"
fs.lStructSize% = DIM(fs{})
fs.hwndOwner% = @hwnd%
fs.lpstrFilter% = !^ff$
fs.lpstrDefExt% = !^ex$
fs.lpstrFile% = Fn%
fs.nMaxFile% = 256
fs.flags% = 6

DIM cf{lStructSize%, hwndOwner%, hdc%, lpLogFont%, \
\ iPointSize%, flags%, rgbColors%, lCustData%, \
\ lpfnHook%, lpTemplateName%, hInstance%, lpszStyle%, \
\ nFontType{l&,h&}, pad{l&,h&}, nSizeMin%, nSizeMax%}
cf.lStructSize% = DIM(cf{})
cf.hwndOwner% = @hwnd%
cf.lpLogFont% = Lf%
cf.flags% = 1

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

DEF PROCnew : LOCAL F%
?Fn% = 0 : PROCtitle
SYS "SendMessage", Hedit%, &C, 0, ^F%
ENDPROC

DEF PROCload : LOCAL F%, L%
SYS "GetOpenFileName", fs{} TO F%
IF F% PROCtitle ELSE ENDPROC
F% = OPENIN$$Fn%
IF F% THEN
L% = EXT#F% : CLOSE #F%
SYS "GlobalAlloc", 0, L%+1 TO F%
OSCLI "LOAD """+$$Fn%+""" "+STR$~F%+"+"+STR$~L%
F%?L% = 0
SYS "SendMessage", Hedit%, &C, 0, F% TO L%
SYS "GlobalFree", F%
IF L% = 0 ERROR 100, "File "+$$Fn%+" too big"
ELSE
ERROR 101, "Can't open file "+$$Fn%
ENDIF
ENDPROC

DEF FNsaveas : LOCAL F%, L%
SYS "GetSaveFileName", fs{} TO F%
IF F% PROCtitle ELSE = FALSE
DEF FNsave : LOCAL F%, L% : IF ?Fn% = 0 THEN = FNsaveas
SYS "SendMessage", Hedit%, &E, 0, 0 TO L%
SYS "GlobalAlloc", 0, L%+1 TO F%
SYS "SendMessage", Hedit%, &D, L%+1, F%
OSCLI "SAVE """+$$Fn%+""" "+STR$~F%+"+"+STR$~L%
SYS "GlobalFree", F%
= TRUE

DEF FNchanged : LOCAL R%
SYS "SendMessage", Hedit%, &B8, 0, 0 TO R%
IF R% = 0 THEN = TRUE
SYS "MessageBox", @hwnd%, "Save changes?", "TEXTEDIT", 35 TO R%
IF R% = 6 IF FNs PROCunchanged : = TRUE
IF R% = 7 PROCunchanged : = TRUE
= FALSE

DEF PROCtitle
SYS "SetWindowText", @hwnd%, "TEXTEDIT - "+$$Fn%
ENDPROC

DEF PROCunchanged
SYS "SendMessage", Hedit%, &B9, 0, 0
ENDPROC
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Automatically opening a TEXTEDIT.BBC file
« Reply #1 on: Sep 4th, 2010, 10:06pm »

on Sep 4th, 2010, 4:59pm, Danny72 wrote:
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.
« Last Edit: Sep 4th, 2010, 10:16pm by admin » User IP Logged

Danny72
New Member
Image


member is offline

Avatar




PM


Posts: 20
xx Re: Automatically opening a TEXTEDIT.BBC file
« Reply #2 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

User IP Logged

JonR
New Member
Image


member is offline

Avatar




PM


Posts: 24
xx Re: Automatically opening a TEXTEDIT.BBC file
« Reply #3 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.
« Last Edit: Sep 6th, 2010, 7:33pm by JonR » User IP Logged

Danny72
New Member
Image


member is offline

Avatar




PM


Posts: 20
xx Re: Automatically opening a TEXTEDIT.BBC file
« Reply #4 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
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Automatically opening a TEXTEDIT.BBC file
« Reply #5 on: Sep 7th, 2010, 5:38pm »

on Sep 7th, 2010, 2:56pm, Danny72 wrote:
Is it PRINT "'"@cmd$"'" just before the Main Loop

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.
User IP Logged

JonR
New Member
Image


member is offline

Avatar




PM


Posts: 24
xx Re: Automatically opening a TEXTEDIT.BBC file
« Reply #6 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.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls