|
A
PC Interface for Hand-Held Devices
by Kock Kin Ko
Start
Creating GUI and Menu PC
Interface Software CVI Windows Programming
Basics Working Together
Plotting Performance Graphs How
Serial Com Operates Big Endian Data
Becomes Little Sources
CVI WINDOWS PROGRAMMING BASICS
Based on the GUI main panel in file car05.uir,
the main program framework is automatically generated and saved into
car05.c. Listing 1 shows the
main program framework. You can see the C main function main()
and the menu callback functions of the File menu (i.e., Save(),
Open(), Analysis(), Print_panel(), and Exit()).
To maintain program modularity, Com menu
callback functions SetUp(), ReqData(), and Closecom()
are moved to another file, com05.c. Note that what automatically
generated were the frame structures of these menu callback functions.
CVI does provide codes for main() and Exit() (the former
starts the Windows program by executing RunUserInterface()
and the latter quits the program by executing QuitUserInterface(0)).
Before proceeding further, its
necessary to introduce some of the basic CVI functions (shown in Listing
2). GetCtrlVal() gets the data content of the textbox and
loads that data into a buffer szBuffer. panelMain indicates
that the textbox is an object on the main panel. The SetCtrlAttribute()
sets the LED color to red. The LED has a constant ID: COMON.
This LED has a label name Com Link SetUp, not shown in the
function.
Its not absolutely necessary to
memorize the case-sensitive function names, the Constant IDs, or the
parameters. You can just call up their function panels from the user
interface library and click to select Constant IDs TEXTBOX
or COMON, or click to select attribute parameter ATTR_OFF_COLOR
and its value VAL_RED.
You do need to define a system variable
szBuffer to hold the textbox data. A more complicated function
is FileSelectPopUp(), which enables users to look for a directory
and create a file. In its function panel, just click on "SAVE
button" and option "allow user change directory." Next,
key in file type "*.car" and the title message of the file
dialogue panel "Enter name of file to save" and then declare
a system variable szFileName to hold file name and its directory.
As an example of how to fill up a callback
function, consider saving a file using the File menu callback function
Save(). First, FileSelectPopUp() enables you to create a file.
Next, the file is opened for "write" by pFile().
Then GetCtrlVal() copies the content of the textbox into a
buffer. Finally, fwrite() writes the buffer data into the file
and fclose() closes the file.
PREVIOUS
NEXT
Circuit Cellar provides up-to-date information
for engineers. Visit www.circuitcellar.com
for more information and additional articles.
For subscription information, call (860) 875-2199, subscribe@circuitcellar.com
or subscribe
online. ęCircuit Cellar, the Magazine for Computer Applications.
Posted with permission.
|