bb.donnay-software.com

Donnay Software Web Forums
It is currently Sat Aug 17, 2019 1:35 pm

All times are UTC - 7 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Sat Mar 09, 2019 5:04 am 
Offline
User avatar

Joined: Tue Jul 28, 2015 5:15 am
Posts: 93
So now you have express++, you added the dialogs and it starts to look good. It´s time to play with buttons.

Basically, instead of using a loop with k = LASTKEY() you need to add the event management system. In other words, you need to monitor the keys used on the keyboard, but also all the action done with a mouse. You still can catch the LASTKEY() and do whatever you use to do with it, but, a PushButton will also execute a function just like a set key.

Here is some code to show you an example.


Code:
// In the example, pushbuttons are created that
// output text in an XbpCrt window.
// How do I destroy all the buttons when I click on A ?

   #include "Appevent.ch"

   PROCEDURE Main
   
      PRIVATE nEvent, mp1, mp2, oXbp
     
      aPushButtons := {}
     
      CLS
     
      sCreatePushButtons()

      // Event loop = Program navigation
      nEvent := 0
      DO WHILE nEvent <> xbeP_Close
     
         nEvent := AppEvent( @mp1, @mp2, @oXbp )
         @ 05, 22 SAY PadR( Var2Char( nEvent ), 10 )
         
         // Catch the key after a GUI event
         IF VALTYPE(mp1) = "N" .AND. mp1 < 1000 .AND. mp1 <> 0
            k = mp1
            mp1 = 0
            @ 10, 22 SAY PadR( Var2Char( k ), 10 )
            k = 0
         ELSE
            oXbp:HandleEvent( nEvent, mp1, mp2 )
            k = LASTKEY() // TO GET THE FUNCTIONS
            @ 10, 22 SAY PadR( Var2Char( k ), 10 )
            k = 0
         ENDIF
         
      ENDDO
     
      ? "Quitting"
      inkey(1)
   RETURN
   
   FUNCTION BA()

      sDestroyPushButtons()   

      mGET = SPACE(30)
      @ 10, 12 SAY "BA        "
      @ 12, 12 GET mGET
      SET CURSOR ON
      READ
      SET CURSOR OFF
     
      CLEAR SCREEN

      sCreatePushButtons()
     
   RETURN .T.

   FUNCTION BB()
      @ 10, 12 SAY "BB        "
   RETURN .T.

   FUNCTION BC()
      @ 10, 12 SAY "BC        "
   RETURN .T.

   FUNCTION sCreatePushButtons()
 
      // Create first pushbutton
      oXbp := XbpPushButton():new( , , {50,20}, {100,40} )
      oXbp:caption := "A"
      oXbp:create()
      oXbp:activate := {|| BA() }
      AADD(aPushButtons,oXbp)

      // Create second pushbutton
      oXbp := XbpPushButton():new( , , {200,20}, {100,40} )
      oXbp:caption := "B"
      oXbp:create()
      oXbp:activate := {|| BB() }
      AADD(aPushButtons,oXbp)

      // Create last pushbutton
      oXbp := XbpPushButton():new( , , {350,20}, {100,40} )
      oXbp:caption := "C"
      oXbp:create()
      oXbp:activate := {|| BC() }
      AADD(aPushButtons,oXbp)

   RETURN .T.
   
   FUNCTION sDestroyPushButtons()
   
      FOR i := 1 TO LEN(aPushButtons)
         aPushButtons[i]:DESTROY()
      NEXT
      aPushButtons := {}

   RETURN .T.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group