User Tools

Site Tools


opening_20a_20file_20by_20dropping_20or_20clicking

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
opening_20a_20file_20by_20dropping_20or_20clicking [2018/03/31 13:19] – external edit 127.0.0.1opening_20a_20file_20by_20dropping_20or_20clicking [2024/01/05 00:22] (current) – external edit 127.0.0.1
Line 1: Line 1:
 =====Opening a file by dropping or clicking===== =====Opening a file by dropping or clicking=====
  
-//by Richard Russell, October 2007//\\ \\  In Windows, some common ways of opening a file (for example a **document** or **image** file) are as follows:\\ +//by Richard Russell, October 2007//\\ \\  In Windows, some common ways of opening a file (for example a **document** or **image** file) are as follows:
  
   * **Drag-and-drop** the file onto the icon of the application you want to open it.   * **Drag-and-drop** the file onto the icon of the application you want to open it.
Line 7: Line 7:
   * **Right-click** on the file's icon and select **Send To** from the menu.   * **Right-click** on the file's icon and select **Send To** from the menu.
   * **Double-click** on the file's icon (it will be opened by the default viewer for that file type).   * **Double-click** on the file's icon (it will be opened by the default viewer for that file type).
-\\  You may want your own BBC BASIC program to be able to open a file in one of these ways. That is easily achieved because in each case what happens is that the selected application is executed with the //path and name to the selected file// in the command line. So all you need to do in your program is extract the contents of the **@cmd$** system variable and use that as the path/name of the file to be opened.\\ \\  There is just one minor complication. If the path or name of the file contains spaces, Windows encloses the entire **@cmd$** string in quotation marks ("). Your program must remove those before the the path/filename is suitable for use.\\ \\  Here is a very simple program which displays a BMP file:\\ \\ + 
 +You may want your own BBC BASIC program to be able to open a file in one of these ways. That is easily achieved because in each case what happens is that the selected application is executed with the //path and name to the selected file// in the command line. So all you need to do in your program is extract the contents of the **@cmd$** system variable and use that as the path/name of the file to be opened.\\ \\  There is just one minor complication. If the path or name of the file contains spaces, Windows encloses the entire **@cmd$** string in quotation marks ("). Your program must remove those before the the path/filename is suitable for use.\\ \\  Here is a very simple program which displays a BMP file: 
 + 
 +<code bb4w>
         bmpfile$ = @cmd$         bmpfile$ = @cmd$
         IF ASC(bmpfile$)=34 bmpfile$=EVAL(bmpfile$)         IF ASC(bmpfile$)=34 bmpfile$=EVAL(bmpfile$)
         OSCLI "DISPLAY """+bmpfile$+""""         OSCLI "DISPLAY """+bmpfile$+""""
-The first line copies the contents of **@cmd$** (since you must not attempt to modify the contents of that variable). The second line examines the path/filename and if it is enclosed in quotation marks they are stripped off. The third line displays the image; note the addition of quotation marks. It may seem strange to strip off the quotes and then put them back again, but that ensures that the contents of **bmpfile$** are in a suitable form whenever a valid path/filename is needed (for example in an **OPENIN** function).\\ \\  Of course this only works when you have 'compiled' your program to a standalone executable, since only then can your program be executed by Windows in this way. When testing your program in the Interactive Development Environment **@cmd$** will contain an empty string. You may therefore wish to add to your program so that in these circumstances it requests the filename, for example:\\ \\ +</code> 
 + 
 +The first line copies the contents of **@cmd$** (since you must not attempt to modify the contents of that variable). The second line examines the path/filename and if it is enclosed in quotation marks they are stripped off. The third line displays the image; note the addition of quotation marks. It may seem strange to strip off the quotes and then put them back again, but that ensures that the contents of **bmpfile$** are in a suitable form whenever a valid path/filename is needed (for example in an **OPENIN** function).\\ \\  Of course this only works when you have 'compiled' your program to a standalone executable, since only then can your program be executed by Windows in this way. When testing your program in the Interactive Development Environment **@cmd$** will contain an empty string. You may therefore wish to add to your program so that in these circumstances it requests the filename, for example: 
 + 
 +<code bb4w>
         bmpfile$ = @cmd$         bmpfile$ = @cmd$
         IF ASC(bmpfile$)=34 bmpfile$=EVAL(bmpfile$)         IF ASC(bmpfile$)=34 bmpfile$=EVAL(bmpfile$)
         IF bmpfile$ = "" THEN bmpfile$ = FNrequestfile         IF bmpfile$ = "" THEN bmpfile$ = FNrequestfile
         OSCLI "DISPLAY """+bmpfile$+""""         OSCLI "DISPLAY """+bmpfile$+""""
 +</code>
 +
 Here **FNrequestfile** is assumed to prompt the user to enter (or select) a filename, perhaps by means of an [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin5.html#input|INPUT]] statement or by using the Windows [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwine.html#opensave|GetOpenFileName]] dialogue.\\ \\  To add your compiled application to the **Send To** list you need to place a shortcut there as follows:\\  Here **FNrequestfile** is assumed to prompt the user to enter (or select) a filename, perhaps by means of an [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin5.html#input|INPUT]] statement or by using the Windows [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwine.html#opensave|GetOpenFileName]] dialogue.\\ \\  To add your compiled application to the **Send To** list you need to place a shortcut there as follows:\\ 
  
Line 24: Line 33:
   * Right-drag your application into the SendTo folder, and select 'Create shortcut here'.   * Right-drag your application into the SendTo folder, and select 'Create shortcut here'.
   * Select File... New and then click Shortcut.   * Select File... New and then click Shortcut.
-\\  To make your application the default viewer for a specific file type you will need to edit the file **associations**. You can do that as follows:\\ + 
 +To make your application the default viewer for a specific file type you will need to edit the file **associations**. You can do that as follows:\\ 
  
   - Open **My Computer** or **Windows Explorer**.   - Open **My Computer** or **Windows Explorer**.
opening_20a_20file_20by_20dropping_20or_20clicking.1522502371.txt.gz · Last modified: 2024/01/05 00:17 (external edit)