Windows has radically changed the way users interact with software. Armed with a mouse, users are no longer forced to input information in a predetermined sequence, but can now take control of the interface, clicking through forms, buttons, and input fields in any order and at any time. The immense popularity of Windows applications gives some indication of just how important this control is to users.
Business Basic developers can follow this popular trend and give their users additional control over the Windows environment by adding clipboard functionality to their Visual PRO/5® applications. The clipboard, an electronic scratch-pad controlled by the user, gives users the ability to copy data at will between arbitrary unrelated programs.
In Visual PRO/5 1.0, BASIS introduced three conrols--EDIT, TXEDIT, and LISTEDIT--that support the Windows clipboard's cut-and-paste functions using the standard keystrokes <CTRL-X> for Cut, <CTRL-C> for Copy, and <CTRL-V> for Paste. This functionality can also be made available to the user through a menu system by defining menu items with three reserved menu IDs: 32027 for Cut, 32028 for Copy, and 32029 for Paste.
Visual PRO/5 2.0 supports the simple clipboard interface from version 1.0, but it also expands on it with the addition of the following verbs and functions:
Using these new verbs and functions, developers can offer users the ability to cut, copy, and paste in more sophisticated ways from within a Visual PRO/5 program. Users can then exchange data between a Visual PRO/5 application and other Windows programs, such as Microsoft Word or Microsoft Access.
To ensure that a user can copy data from a Visual PRO/5 application to the program of his or her choice, the developer should write data to the clipboard in as many formats as possible. By providing a variety of formats, an application reading the clipboard will be more likely to find a format it understands. For example, Microsoft Excel writes data to the clipboard in several spreadsheet and graphics formats, as well as Rich Text Format (RTF) and plain text. This wide variety of formats makes it possible for Excel data to be easily copied and pasted to a simple text editor or to a more sophisticated word processor. Each program would select the best available format for that particular program. For instance, Windows Notepad would select plain text format from the clipboard while Word would select RTF.
There are sixteen formats with fixed format numbers, and Windows also preregisters several other formats, like RTF and Comma Separated Values (CSV). Developers can retrieve the format numbers for preregistered formats, or register their own customized formats, with the CLIPREGFORMAT() function, but other Windows-based programs won't know about customized formats defined by developers. These formats will only be useful for exchanging data within a single application. Here are the most common formats:
Out of the 16 standard formats defined in the Windows, a typical Visual PRO/5 program will probably use only CF_TEXT (1), CF_DIB (8), and possibly CF_WAVE (12). Most of the other formats are only of interest to C/C++ programs.
The following is an example using the CSV format to encode tabular
information in a form that can be easily pasted to a spreadsheet
program like Excel. This example program reads the sample data file
clip$=$$ cdfile=unt open (cdfile)"datagrid.dat" loop: read (1,end=endloop)cd$,title$,artist$,label$,time$,type$, +genre$,bin$,etc$ clip$=clip$+cd$+","+title$+","+artist$+","+label$+"," +time$+","+type$+","+genre$+","+bin$+"," +str(num(etc$(1,10)))+","+str(num(etc$(11,10)))+"," +str(num(etc$(21,10)))+","+str(num(etc$(31,10)))+$0d0a$ goto loop endloop: csv=clipregformat("CSV") cliplock clipfromstr csv,clip$ clipunlock print "You can now paste the clipboard to Microsoft Excel." end
Run this program, then load Excel and select Paste from the Edit menu. The data will be copied, nicely formatted, into Excel.
These new clipboard verbs can also be used to read data from the clipboard to an application. The following code reads CSV-formatted data from the clipboard into a string variable:
csv=clipregformat("CSV") cliplock csv$=cliptostr(csv) clipunlock
The CLIPTOSTR() function returns a raw block of binary data that
must be converted if it is to be interpreted as a text format like RTF
or CSV. The text portion of the string will be null-terminated, so all
data past the first
When you print
000001,Mississippi Blues,John Hurt & The Ramblers, Blind Pig,07256,AAD,Blues,N123,12,55,5.99,12.99 000006,Urban Blues,Various Artists,Alligator,05659 ,AAD,Blues,N127,10,89,4.56,10.98
...several records omitted...
000091,Lay It Down,Cowboy Junkies,Geffen,05114,DDD ,Rock,YU10,13,3,6.22,14.78 000096,The Gold Medal Collection,Harry Chapin,Elek tra,14013,AAD,Rock,AA8,32,2,7.78,22.48
With Visual PRO/5 2.0, developers gain a new set of verbs and functions that allows for a richer integration between Visual PRO/5 applications and the Windows clipboard. Applications that take advantage of these new verbs will give their users greater control over the Windows environment and enable them to work more effectively. The result is enhanced user appeal and functionality for any Visual PRO/5 application.
Jim Douglas, a fourteen-year Business Basic veteran, is
working with BASIS on its future product strategy, Volcano
. For additional information on the popular RTF format, see the RTF
specifications at ftp://ftp.microsoft.com/softlib/mslfiles/gc0165.exe. This
file expands to a Word document, GC0165 update.doc.
Copyright 1999, BASIS International Ltd. All rights reserved.