LabWindows/CVI has a built-in visual programming utility called CodeBuilder which automatically builds a shell program for you based on your GUI. In this section of the tutorial, you will use CodeBuilder to generate a source program for you. Once you create your program with CodeBuilder, you simply customize the source code to complete your application.
CodeBuilder uses the Callback Functions that you assign to each of your GUI controls to build a program.
Click on the Code menu to display the CodeBuilder options.
!
BEGIN_TEXT
!
CodeBuilder
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEMOGUI2.AVI
0
2
2175
3570
5505
2385
0
0
0
0
BEGIN_TEXT
Before you generate any source code, let's define the events which the program will recognize. With LabWindows/CVI, you can build event-driven programs -- which means your programs can respond to left mouse-clicks, right mouse-clicks, double-clicks, keypresses, and so on.
Choose Preferences and select Default Control Events to define an event list.
!
BEGIN_TEXT
!
Setting Control Events
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEMOGUI2.AVI
0
6
2025
5760
3600
2835
0
0
0
0
BEGIN_TEXT
Let's assume that your program must be able to respond to left-clicks, right-clicks, and keypresses from the end-user. Click on these options from the list at the left.
Click next to EVENT_LEFT_CLICK,
EVENT_RIGHT_CLICK, and EVENT_KEYPRESS to complete your event list.
!
BEGIN_TEXT
!
Selecting Default Events
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEMOGUI2.AVI
0
12
3165
4995
4410
1860
0
0
0
0
BEGIN_TEXT
When CodeBuilder generates your program, it sets up a case structure for responding to these different events.
Click on OK to accept the event list.
!
BEGIN_TEXT
!
Selecting Default Events
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEMOGUI2.AVI
0
14
1440
3840
4935
1575
0
0
0
0
BEGIN_TEXT
Now you can use CodeBuilder to write your program.
Click on the Code menu to display the CodeBuilder options again.
!
BEGIN_TEXT
!
Generating the Program Shell
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEMOGUI2.AVI
0
16
2400
4215
4320
1335
0
0
0
0
BEGIN_TEXT
Select Generate and choose All Code... to create a program shell based on your GUI.
!
BEGIN_TEXT
!
Generate All Code...
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEMOGUI2.AVI
0
20
2115
5010
4500
4140
0
0
0
0
BEGIN_TEXT
Before the program is generated, you must specify a few generation options. From the top half of this dialog box, you can select which panels should display at program startup. For this program, there is only one panel, so you don't have to set anything.
From the bottom half of the dialog box, you can specify which callback function should end program execution. Your GUI has a Quit button with a callback function named QuitProgram. CodeBuilder will automatically place program shutdown code into the QuitProgram function for you.
Place a checkmark next to the QuitProgram function.
!
BEGIN_TEXT
!
Setting CodeBuilder Options
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
ARR_R1B.BMP
ARR_R1_.BMP
301
62
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEMOGUI2.AVI
0
22
3945
4590
4020
1425
0
0
0
0
BEGIN_TEXT
Click on the OK button to generate a program shell.
!
BEGIN_TEXT
!
Setting CodeBuilder Options
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEMOGUI2.AVI
0
24
330
2310
6180
2595
0
0
0
0
BEGIN_TEXT
CodeBuilder automatically generated a main program and two callback functions, AcquireData and QuitProgram. The main program simply loads and displays the GUI panel that you created. The RunUserInterface() function launches the event capture and response engine in LabWindows/CVI -- each button-click or keypress now will be directed to the appropriate callback function.
Click on the arrow to get a closer look at the callback function source code.
!
BEGIN_TEXT
!
Reviewing the Generated Source Code
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
ARR_R1B.BMP
ARR_R1_.BMP
234
22
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
-1
0
0
0
0
3
3
-1
3
0
0
DEMOGUI2.AVI
0
25
195
2070
6600
2175
0
0
0
0
BEGIN_TEXT
The QuitProgram function has entries for responding to the four different events that you specified in the CodeBuilder dialog boxes. Because you selected QuitProgram as the function that ends program execution, CodeBuilder placed the QuitUserInterface() function within the QuitProgram source code. This function ends program execution.
Click the arrow to continue.
!
BEGIN_TEXT
!
The QuitProgram Function
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
-1
0
0
0
0
3
3
-1
3
0
0
DEMOGUI2.AVI
0
26
2400
5955
3510
2040
0
0
0
0
BEGIN_TEXT
You can test the code created by CodeBuilder by running the program.
Click on the Run Project icon to compile and run the program.
!
BEGIN_TEXT
!
Running the Program
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
ARR_D1R.BMP
ARR_D1_.BMP
68
305
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEMOGUI2.AVI
0
28
4350
4560
4845
1845
0
0
0
0
BEGIN_TEXT
Nothing happens when you click on the Acquire Data button, because you have not added any code to the AcquireData callback function yet.
Try clicking on the Acquire Data button.
!
BEGIN_TEXT
!
The Acquire Button
0
0
0
0
255
255
255
255
0
0
0
0
0
0
255
255
255
0
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
8
~~
~~
0
0
0
0
0
3
3
0
3
0
-1
DEMOGUI2.AVI
0
30
4380
4005
4890
1845
0
0
0
0
BEGIN_TEXT
However, the Quit button is operational, because CodeBuilder added the QuitUserInterface() function to the QuitProgram callback function for you.