BBC BASIC for Windows
Programming >> User Interface >> Reassigning buttons
http://bb4w.conforums.com/index.cgi?board=ui&action=display&num=1465115458

Reassigning buttons
Post by Joe68 on Jun 5th, 2016, 08:30am

Hi All.

The attached program snippet simply sets up some buttons (using WINLIB5), and checks which button has been pressed.
When I try to reassign the buttons, i.e. when button 5 'CHANGE' is pressed, the new labels appear correctly but as soon as the mouse pointer touches buttons 1-4 they revert to their original values.

Code:
      INSTALL @lib$+"WINLIB5"

      x=50:w=100:h=30

      REM create buttons
      b=FN_button("Alice",  x,100,w,h,1,0)
      b=FN_button("Bob",    x,150,w,h,2,0)
      b=FN_button("Charlie",x,200,w,h,3,0)
      b=FN_button("Diane",  x,250,w,h,4,0)
      b=FN_button("CHANGE", x,300,w,h,5,0)


      REM activate Windows system
      Click%=-1
      ON SYS Click%=@wparam%:RETURN

      REM main loop
      REPEAT
        SYS "Sleep",10
        click%=-1
        SWAP click%,Click%
        IF click%<>-1 PROCChecks(click%)
      UNTIL FALSE
      END


      DEFPROCChecks(k)
      PRINT TAB(0,1)"Button ";STR$k;" selected"
      PRINT TAB(0,2)h%
      REM if 'CHANGE' is selected then...
      IF k=5 THEN
        REM ...reassign buttons
        b=FN_button("Jack", x,100,w,h,1,0)
        b=FN_button("Karen",x,150,w,h,2,0)
        b=FN_button("Lucy", x,200,w,h,3,0)
        b=FN_button("Mark", x,250,w,h,4,0)
      ENDIF
      ENDPROC
 


Can anyone tell me how to ensure the reassigned buttons retain their new values?

Thanks.
Joe.
Re: Reassigning buttons
Post by Zaphod on Jun 5th, 2016, 12:41pm

The problem is that what you are doing is actually defining new buttons that are overlaying the original ones, not just changing the names of the original buttons.

It is more likely that you intended to do this:
Code:
      INSTALL @lib$+"WINLIB5"

      WM_SETTEXT = &C

      x=50:w=100:h=30

      REM create buttons
      b1=FN_button("Alice",  x,100,w,h,1,0)
      b2=FN_button("Bob",    x,150,w,h,2,0)
      b3=FN_button("Charlie",x,200,w,h,3,0)
      b4=FN_button("Diane",  x,250,w,h,4,0)
      b5=FN_button("CHANGE", x,300,w,h,5,0)


      REM activate Windows system
      Click%=-1
      ON SYS Click%=@wparam%:RETURN

      REM main loop
      REPEAT
        SYS "Sleep",10
        click%=-1
        SWAP click%,Click%
        IF click%<>-1 PROCChecks(click%)
      UNTIL FALSE
      END


      DEFPROCChecks(k)
      PRINT TAB(0,1)"Button ";STR$k;" selected"
      REM  PRINT TAB(0,2)h%
      REM if 'CHANGE' is selected then...
      IF k=5 THEN
        REM ...reassign buttons
        SYS"SendMessage",b1,WM_SETTEXT,0,"Jack"
        SYS"SendMessage",b2,WM_SETTEXT,0,"Karen"
        SYS"SendMessage",b3,WM_SETTEXT,0,"Lucy"
        SYS"SendMessage",b4,WM_SETTEXT,0,"Mark"
      ENDIF
      ENDPROC
 

Re: Reassigning buttons
Post by Joe68 on Jun 8th, 2016, 10:18am

Thank you Zaphod.

Your answer works perfectly!

If you don't mind my asking, where can I find similar information about BB4W's call messages to Windows?
Re: Reassigning buttons
Post by Zaphod on Jun 8th, 2016, 12:43pm

That is a difficult question.
Read lots of code and the manual!
Unfortunately some tutorials on this that were on the old BB4W Yahoo site recently became unavailable as the site was shut down.
This is the best way to access the Win32 API information.
http://www.oxygenbasic.org/o2zips/Win32.chm
Re: Reassigning buttons
Post by DDRM on Jun 9th, 2016, 08:55am

Hi Both,

Yes, I like that help file too.

MSDN is good, but it does take a while to learn your way around it. After a while you get a feel for how the code examples they show there are going to map into BB4W SYS calls.

It's also worth having a look on the wiki (linked as "BBC BASIC for Windows Programmers' Reference" in the box above) - there's a lot of stuff there.

If there are specific examples you want to know about, do post - there may be someone who's already done it, which will save you a lot of work, and it may teach the rest of us something useful, too!

Best wishes,

D