WideStudio Logo
WideStudio
Programming Guide
WideStudio Index
Table of contents


Exemplo para procedimento de eventos de WSCvifield



Executando algum procedimento de eventos por retorno do código da tecla

Apresentamos a seguir um exemplo, que mostra a execução de um procedimento com o nome "InputFixed" (entrada fixada).
//A sample of WSEV_KEY_HOOK trigger.
#include "WSDkeyboard.h"
void cbop(WSCbase* object){
(A)Get the pressed key.
long key = WSGIappKeyboard()->getKey();
(B)If the key is return..
if (key == WSK_Return){
//Execute the procedure which name is "InputFixed".
object->execProcedure("InputFixed");
}
}

Este procedimento algumas vêzes é usado para executar algum procedimento no final da digitação de uma tecla no teclado.

Limpando a última entrada no início da última entrada

O procedimento limpa a string da primeira entrada do teclado quando o campo de entrada é apontada ou clicado pelo mouse, conforme segue:
#include <WSDkeyboard.h>
//To contain the last focused input field.
static WSCbase* _focus_if = NULL;
//(1)A sub-procedure with WSEV_FOCUS_CH
static void _focus_on_(WSCbase* object){
  //(A) Examine whether the instance is focused.
  if (_focus_if != object && object->getFocus() != False){ 
    //(B)It need to clear the string!
    //Set the clear flag True.
    object->setUserData("CLEAR TIMING",(void*)1);
    //(C)store that the last focused one is.
    _focus_if = object;
  }
}
//(2)A sub-procedure with WSEV_MOUSE_PRESS
static void _btn_press_(WSCbase* object){
  //(D) if clicked by the mouse pointer,
  // it needs to clear the string!
  //  Set the clear flag True.
  object->setUserData("CLEAR TIMING",(void*)1);
  object->setProperty(WSNcursorPos,0);
  //(E)store that the last focused one is.
  _focus_if = object;
}
//(3)A sub-procedure with WSEV_KEY_PRESS
static void _key_hook_(WSCbase* object){
  //(F) See the clear flag to clear the last input string.
  long fl =(long)object->getUserData("CLEAR TIMING");
  if (fl == 1){
    long key = WSGIappKeyboard()->getKey();
    //(G) Clear the string,if the key is not cursor key.
    if (key != WSK_Tab &&
        key != WSK_Up &&
        key != WSK_Down &&
        key != WSK_Left &&
        key != WSK_Right ){
      //(H)Clear...
      object->setProperty(WSNlabelString,"");
    }else{
      return;
    }
  }
  //(I)Set the clear flag False.
  object->setUserData("CLEAR TIMING",(void*)0);
}

//The main-procedure.
//(4)Set the input field instance with WSEV_INITIALIZE trigger.
void ifdclr(WSCbase* object){
  //Setup the sub-procedure(1) with WSEV_FOCUS_CH
  WSCprocedure* ac1 = new WSCprocedure("ac1",WSEV_FOCUS_CH);
  ac1->setFunction(_focus_ch_,"_focus_ch_");
  object->addProcedure(ac1);

  //Setup the sub-procedure(2) with WSEV_MOUSE_PRESS
  WSCprocedure* ac2 = new WSCprocedure("ac2",WSEV_MOUSE_PRESS);
  ac2->setFunction(_btn_press_,"_btn_press_");
  object->addProcedure(ac2);

  //Setup the sub-procedure(3) with WSEV_KEY_PRESS
  WSCprocedure* ac3 = new WSCprocedure("ac3",WSEV_KEY_HOOK);
  ac3->setFunction(_key_hook_,"_key_hook_");
  object->addProcedure(ac3);
}

  

No procedimento focus_ch event, para verificar se a instância é apontada, utiliza uma variável estática que armazena o último valor da instância apontada.

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