Creating a Pushbutton

Pushbuttons can be created either using the Designer or in code.

Designer: You can use the Designer to create a pushbutton field. If you do not use the Designer to generate your main program, you will need to remember to #include vv_push.h.

Code: To create a pushbutton in code, follow the steps outlined below:

Step 1: Include the header file vv_push.h.

Include the pushbutton header file vv_push.h in all modules that use pushbuttons and in your main() module before vv_main.h.

Step 2: (Optional) Place a box around the pushbutton.

If you want a box around your pushbutton, define the box first by calling the function bg_boxdef(). See Chapter 15, "Changing the Appearance of Data Forms," for more information on the function bg_boxdef().

Step 3: Define the pushbutton field using pb_def().

Pushbuttons are defined using the special pushbutton definition function, pb_def():

MFIELDPTR pb_def(rb, cb, boxp, txtp, act_func, dfmp)

int rb;            /* Row to put pushbutton on                     */

int cb;            /* Column to start pushbutton on                 */

BG_BOXPTR boxp;        /* Box to place around pushbutton                 */

UCHAR *txtp;        /* Text to place in button                     */

PFI act_func;        /* Pointer to function to call when button is pushed     */

DFORMPTR dfmp;        /* Pointer to form to put pushbutton on             */

where act_func is a pointer to the function you want to execute when the button is pushed. This function is called a pushbutton action function; see Chapter 31, "Writing User Functions," for more information on how to write a pushbutton action function.

The following code fragment illustrates Steps 2 and 3:

MFIELDPTR pbutn1;

BG_BOXPTR boxp;



boxp = bg_boxdef(1, 1, 3, 8, LNORMAL, BDR_SLNP, dfmp);

pbutn1 = pb_def(2, 3, boxp, "Save", save_data, dfmp);


Home Contents Previous Next