/ Forums / Advansys Formativ / Creating Solutions with Formativ / Clearing the mouse/keyboard buffer after displaying a form / Reply To: Clearing the mouse/keyboard buffer after displaying a form

#7714
Support 1
Participant

    Simon,

    Thank you for your enquiry.

    The problem you describe is a perennial issue for windowed user interfaces (UIs) which have background processes running half a second or longer. This is a “rule of thumb” time period: the amount of time it will take the average user to notice a pause in the responsiveness of the UI.

    We know of two UI design options to address this issue:

    • Display a “status” dialog for the duration of the background process. The dialog may, optionally, provide quality of service information (eg. a progress gauge or textual counter) and a way to cancel the process. A dialog like this is typically modeless, ie. other windows in the application are accessible at the same time. This means that the user could click on and make changes in another window, even if those changes are not noticeable until after the process completes.

      Your “Please Wait” form is an example of a modeless dialog because it is displayed using the command

        frmWait.Show

    • Display a modal dialog for the duration of the background process. When a modal dialog is active, an application will not permit mouse or keyboard input to be sent to any other window within the application. With a Formativ Form, this is done using the command
        frmWait.ShowModal

      The dialog need not be a dedicated status dialog. It could be one used to specify parameters for the process, in which case it may be necessary to disable certain controls for the duration of the process.

    For both options, window events must be processed with a frequency and regularity to keep the UI responsive. This is done using the command

      Utilities.DoEvents

    Obviously each option has advantages and disadvantages. The one to choose will depend on the specific circumstances of the process and/or UI involved. Below is a code sample demonstrating a simple implementation of the modal solution:

    '-------------------------------------------------------------------------------
    ' The code below assumes that a form MainForm is defined.  The form has the
    ' following controls:
    ' - A listview ListView, to display numbers counted by a background process.
    ' - A button bnConfig, to configure the solution.  This control is disabled when
    '   processing.
    ' - A button bnToggle whose caption is initially "Start", but changes to "Stop"
    '   when processing.  When the caption is "Stop", clicking the button cancels
    '   the process.  The subroutine bnToggleClick is the event handler for clicking
    '   this button.
    '
    ' Note the use of Utilities.DoEvents inside the tight loop of subroutine
    ' bnToggleClick.  Without this command it would not be possible to stop the
    ' process manually after it has started.
    
    dim gCount
    dim gIndex
    dim gIsProcessing
    
    Sub Main(Client, GWEvent)
    
      gIsProcessing = false
      gCount = 0
    
      MainForm.ShowModal
    
    End Sub
    
    
    Sub bnToggleClick(Sender)
    
      dim oItem
    
      with MainForm
        if gIsProcessing then
          gIsProcessing = false
          .bnConfig.Enabled = true
          .bnToggle.Caption = "Start"
        else
          gIsProcessing = true
          .bnToggle.Caption = "Stop"
          .bnConfig.Enabled = false
    
          gIndex = gCount + 1
          gCount = gCount + 1000
          do while (gIndex <= gCount) and gIsProcessing
            set oItem = .ListView.Items.Add
            oItem.Caption = "Item " & CStr(gIndex)
            gIndex = gIndex + 1
            Utilities.DoEvents
          loop
    
          ' Restore the UI if the user did not cancel the process.
          if gIsProcessing then
            call bnToggleClick(nothing)
          end if
        end if
      end with
    
    End Sub
    '-------------------------------------------------------------------------------
    

    I hope this helps.

    Regards,
    Advansys Support

    [This message was edited by Support 1 on August 21, 2006 at 08:40 PM.]