adinput.c

This example shows how Advanced Dialogs can be used to get input from the user.

A dialog is created as usual and an InputBox is added to it. After the user accepted the dialog, the input string is displayed using a MessageBox.

/*
        Advanved Dialogs v1.0.7 - Example program
        Copyright (C) 2005-2008 Jonas Gehring

        Advanced Dialogs is free software; you can redistribute it and/or modify
        it under the terms of the GNU Lesser General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.

        Advanced Dialogs is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU Lesser General Public License for more details.

        You should have received a copy of the GNU Lesser General Public License
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


// C Source File
// Created 14.03.2005; 22:27:21


#include <tigcclib.h>                                   // Include all standard header files

#include <extgraph.h>                                   // Include ExtGraph v2.00beta5 by TI-Chess Team
#include <AdvDialogs.h>                                 // Powered by Advanced Dialogs v1.0.7


// Main Function
void _main(void)
{
        LCD_BUFFER *screen;
        ADVDIALOG *dialog;
        char name[20];  // Name input
        char msg[35];
        
        // Allocate space for the LCD buffer
        if (((screen = malloc(sizeof(LCD_BUFFER))) == NULL))
        {
                return;
        }
        
        LCD_save(screen);                                               // Save LCD contents

        if (!GrayOn())                                                  // Turn on grayscale graphics
        {
                free(screen);
                return;
        }
                
        memcpy(GrayGetPlane(LIGHT_PLANE), screen, sizeof(LCD_BUFFER));
        memcpy(GrayGetPlane(DARK_PLANE), screen, sizeof(LCD_BUFFER));
        
        // Reset input
        name[0] = 0;

        // Create dialog
        dialog = AdvDlgNew(140, 55, "Advanced Dialogs", TRUE);
        
        // Add elements
        AdvDlgAddText(dialog, 0, 0, "Please enter your name", TXT_STANDARD, COLOR_BLACK);
        AdvDlgAddInputBox(dialog, 0, 1, "Your name:", name, 19, INPUT_STR, COLOR_BLACK);
        AdvDlgAddText(dialog, 0, 3, "(press [ESC] to quit)", TXT_STANDARD, COLOR_WHITE);
        
        // Add Buttons
        AdvDlgAddButton(dialog, 0, B_ESC);
        AdvDlgAddButton(dialog, 1, B_OK);

        // Execute Dialog
        if (AdvDlgDo(dialog, DUMMY_HANDLER))
        {
                ClearKbdQueue();
                
                sprintf(msg, "Welcome %s!", name);
                
                AdvDlgMessageBox("Advanced Dialogs", msg, COLOR_BLACK, B_OK, DUMMY_HANDLER);            // Show MessageBox
        }
        
        // Free the dialog
        AdvDlgFree(dialog);
        
        // Restore contents
        ClearGrayScreen();
        GrayOff();
        LCD_restore(screen);
        free(screen);   
        ST_helpMsg("http://www.boolsoft.org");
}


Generated on Wed Nov 5 09:46:56 2008 for Advanced Dialogs by  doxygen 1.5.7.1