WideStudio Logo
WideStudio
Programming Guide
WideStudio Index
Table of contents


O diálogo do usuário



Como criar um simples diálogo de usuário

Vamos, a seguir, implementar um diálogo de usuário utilizando a classe WSCdialog.
O aplicativo, ao ser executado, gera o diálogo entitulado "title1" (figura abaixo). Nele, ao pressionarmos o botão "dialog!", produz o diálogo entitulado "title2", conforme observa-se na figura abaixo. O usuário deverá preencher o campo "sample1" no diálogo "title2" com uma string. Depois, selecionar uma opção em "sample2", por um dos botões de rádio. Finalmente, pressionar o botão "OK" , "NO" ou "CANCEL", produzindo o seguinte resultado no diálogo "title1":
  • No primeiro campo de texto, se pressionado o botão OK, surgirá "DIALOG OK", se pressionado o botão "NO", surgirá "DIALOG NO" e se por fim, se pressionado o botão "CANCEL", surgirá "DIALOG CANCEL".
  • O segundo campo de texto deverá apresentar a string inserida .
  • O terceiro campo de texto deverá apresentar a opção selecionada em "sample2".

  • [exemplo proposto do diálogo de usuário]

    Este exemplo está disponível em ws/samples/share/dialog/ (no diretório de instalação do WideStudio).

    Controlling to indicate the user dialog

    Pode-se obter este aplicativo pronto, bastando apenas compilar, no diretório de instalação do WideStudio em ws/samples/share/dialog/ .
    O diálogo é realizado tendo uma janela exclusiva para a entrada de dados e outra com o resultado das operações da primeira.
    The dialog is often used as exclusive window to do the input and indicating some informations. So there is a bad case when it is implemented as usual window. For example,when it requires that the same dialog is called from more than on event procedure,if the dialog is usual window, it becomes complicated that receiving of the input value from it. But it is easy to receive it when it is as dialog,not as usual window, because the pop-up method of dialog returns the end of input in order to receive the input value form it.

    The following picture shows the difference of the indicating and receiving the input data between the usual window and the dialog.



    [The difference of the usual window and the dialog]

    See the following program, At first, make a user dialog instance by dropping from the [Window] section of the object box dialog and put the following instances on it.


  • WSCvifield* newvifi_003

  • WSCradioGroup* newradi_006


  • [A sample of the user dialog]

    The next,implement the procedure when the button [OK],[NO],[CANCEL] is pushed, and put it the dialog with WSEV_ACTIVATE trigger. In this procedure, check the input values whether they are right and indicates an error dialog if they are wrong.

    #include <WScom.h>
    #include <WSCfunctionList.h>
    #include <WSCbase.h>
    //----------------------------------------------------------
    //Function for the event procedure
    //----------------------------------------------------------
    #include <WSCdialog.h>
    #include <WSCvifield.h>
    #include <WSCradioGroup.h>
    #include <WSCmessageDialog.h>
    extern WSCvifield* newvifi_003;
    extern WSCradioGroup* newradi_006;

    void dialogep(WSCbase* object){
    WSCdialog* dialog = (WSCdialog*)object->cast("WSCdialog");
    if (dialog == NULL){ //A
    return;
    }
    if (dialog->getStatus() != WS_DIALOG_OK){ //B
    object->setVisible(False);
    return;
    }

    WSCstring str;
    str = newvifi_003->getProperty(WSNlabelString);
    if (!strcmp((char*)str,"")){ //C
    WSCmessageDialog* msg = WSGIappMessageDialog();
    msg->setProperty(WSNdefaultPosition,True);
    msg->setProperty(WSNwidth,500);
    msg->setProperty(WSNlabelString,
    "Please input some string to the input field.");
    msg->popup(); //D
    return;
    }
    long val = newradi_006->getProperty(WSNvalue);
    if (val == 0){ //E
    WSCmessageDialog* msg = WSGIappMessageDialog();
    msg->setProperty(WSNdefaultPosition,True);
    msg->setProperty(WSNwidth,500);
    msg->setProperty(WSNlabelString,
    "Please select a item of the radio group.");
    msg->popup(); //F
    return;
    }
    object->setVisible(False); //E
    }
    static WSCfunctionRegister op("dialogep",(void*)dialogep);

    At first, get the class native pointer to access the original method of the WSCdialog class. and call the getStatus method to receive an information which button [OK],[NO],[CANCEL] is pushed. At A,exits the procedure if the instance is not WSCdialog class. At B,checks which the button is pushed. Puts the dialog out when the button is not [OK]. At C, checks the input of the instance: newvifi_003, and indicates an message dialog when its input is wrong at D and exits, At C, checks the input of the instance: newradi_006, and indicates an message dialog when its input is wrong at F and exits. Then puts the dialog out and the method popup() which is called to indicate this dialog and called this event procedure by pushing the buttons of dialog returns. It is important that to make the dialog disappeared, because if not,the method popup() will never return.

    The following program is an example to call the method popup() in order to indicate the dialog.



    [A sample window to indicate the user dialog]

    If the button [dialog!] is pushed, indicates the user dialog and receive the input values from the dialog, put them to the labels.

    The first label: The pushed button [OK],{NO],[CANCEL].

    The second label: The input of newvifi_003.

    The third label: The selection of newradi_006.

    #include <WScom.h>
    #include <WSCfunctionList.h>
    #include <WSCbase.h>
    //----------------------------------------------------------
    //Function for the event procedure
    //----------------------------------------------------------
    #include <WSCdialog.h>
    #include <WSCvifield.h>
    #include <WSCradioGroup.h>
    #include <WSCvlabel.h>
    extern WSCdialog* newdial_001;
    extern WSCvifield* newvifi_003;
    extern WSCradioGroup* newradi_006;
    extern WSCvlabel* newvlab_007;
    extern WSCvlabel* newvlab_010;
    extern WSCvlabel* newvlab_011;

    void btnep(WSCbase* object){
    long val = newdial_001->popup();
    if (val == WS_DIALOG_OK){
    newvlab_007->setProperty(WSNlabelString,"DIALOG OK!");
    }else
    if (val == WS_DIALOG_NO){
    newvlab_007->setProperty(WSNlabelString,"DIALOG NO!");
    }else
    if (val == WS_DIALOG_CANCEL){
    newvlab_007->setProperty(WSNlabelString,"DIALOG CANCEL!");
    }
    WSCstring tmp;
    tmp = newvifi_003->getProperty(WSNlabelString);
    WSCstring tmp2;
    tmp2 << "INPUT: " << tmp;
    newvlab_010->setProperty(WSNlabelString,tmp2);

    val = newradi_006->getProperty(WSNvalue);
    tmp2 = "SELECT: ";
    tmp2 << val;
    newvlab_011->setProperty(WSNlabelString,tmp2);
    }
    static WSCfunctionRegister op("btnep",(void*)btnep);


    Document Release 3.80 for WideStudio ver 3.80, Jan 2005


    WideStudio documents index | Table of contents

    Copyright(C) WideStudio Development Team, 1999-2005 Last modified: Jan 05, 2005