BBC BASIC for Windows
« Up/down control: defining step size »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:26pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Up/down control: defining step size  (Read 791 times)
g3nrw
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 74
xx Up/down control: defining step size
« Thread started on: Jun 25th, 2014, 11:04pm »

I have defined an up/down control with a max value of 100, thusly:

SYS "SendDlgItemMessage", !dlg%, id%, UDM_SETRANGE, 0, 100

I now want to limit the permissible values to steps of 5, namely:
0, 5, 10, 15 etc up to 100.

How do I do this?

--
Ian


User IP Logged

rtr
Guest
xx Re: Up/down control: defining step size
« Reply #1 on: Jun 26th, 2014, 1:19pm »

on Jun 25th, 2014, 11:04pm, g3nrw wrote:
How do I do this?

I believe this can only be achieved (reliably) in assembler code, since it involves subclassing the UDN_DELTAPOS notification (sent in the form of a WM_NOTIFY message, which are so numerous that attempting to use SUBCLASS.BBC often fails):

http://msdn.microsoft.com/en-us/library/windows/desktop/bb759903.aspx

So this is a non-trivial exercise, especially if you are not experienced in writing and debugging BB4W assembler.

Richard.
User IP Logged

DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: Up/down control: defining step size
« Reply #2 on: Jun 27th, 2014, 08:33am »

Hi Ian,

I hesitate to offer a simple solution to what Richard says is a difficult problem, but I think I understand why he wants to do it his way, and why that is difficult. It's offered in case it is useful.

This solution works for me in a very simple testbed (see below)(nearly all this code is copied straight out of the manual.):

detect the change in the editbox, and then change the value to the next multiple of 5. Note that this is not elegant, since it allows the change to occur (and I think be displayed), so you may see it flicker (or worse) as it has to change twice. Intercepting the "I'm going to change it" message from the up-down control would clearly be better, but it sounds like it would also be harder!

As I've set it up, it will move up if the next value is 5n+1 or 5n+2, and down if it's 5n-1 or 5n-2: this is an attempt to cover the possibility that it could move more than once, but that seems unlikely if it depends on user input.

Note that the change will result in another message that the textbox has changed, so you need to be careful about reentrance and infinite loops!

Hope that's useful.

D

Code:
      ES_NUMBER = 8192
      INSTALL @lib$+"WINLIB2"
      dlg% = FN_newdialog("test1",100,100,100,100,8,200)

      PROC_editbox(dlg%,"50",101,10,10,50,10,ES_NUMBER)
      PROC_dlgctrl(dlg%,"",102,0,0,0,0,&50000096,"msctls_updown32")

      PROC_showdialog(dlg%)
      UDM_SETRANGE = 1125
      SYS "SendDlgItemMessage", !dlg%, 102, UDM_SETRANGE, 0, (0 << 16) + 100
      SYS "SetDlgItemText", !dlg%, 101, "40"

      ON ERROR  PROC_closedialog(dlg%):PRINT REPORT$:END
      ON CLOSE  PROC_closedialog(dlg%):QUIT

      ON SYS PROCDoSys(@wparam%,@lparam%)

      REPEAT
        WAIT 1
      UNTIL FALSE
      PROC_closedialog(dlg%)
      END
      :
      DEFPROCDoSys(w%,l%)
      LOCAL n%,t%
      CASE (w% AND &FF) OF
        WHEN 101:
          n%=VAL(FNgetdlgtext(dlg%, 101))
          t%=n% MOD 5
          IF t%<>0 THEN
            IF t%<3 THEN n%+=5-t% ELSE n%-=t%
            SYS "SetDlgItemText", !dlg%, 101, STR$(n%)
          ENDIF
      ENDCASE
      ENDPROC

      :
      DEF FNgetdlgtext(dlg%, id%)
      LOCAL text%
      DIM text% LOCAL 255
      SYS "GetDlgItemText", !dlg%, id%, text%, 255
      = $$text%
 
User IP Logged

rtr
Guest
xx Re: Up/down control: defining step size
« Reply #3 on: Jun 27th, 2014, 11:11am »

on Jun 27th, 2014, 08:33am, DDRM wrote:
so you may see it flicker (or worse)

That is exactly why I didn't recommend it. What (I think) you've failed to take into account is that the degree of - and therefore the acceptability of - the flicker will be very variable between PCs (depending on speed and type of graphics adaptor, what background services are being run etc). You may find that it is entirely acceptable on the PC on which the code is being developed, but totally unacceptable on another PC. As a software developer I encounter this all the time.

So it perhaps can be a valid approach when the program will only ever be run on one PC, but not in an application that will be distributed more widely.

As you were (kindly) prepared to create a ready-to-run solution for the OP, why didn't you do it 'properly' using assembler code to intercept the UDN_DELTAPOS message? I know you are more than capable of it!

Richard.

User IP Logged

g3nrw
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 74
xx Re: Up/down control: defining step size
« Reply #4 on: Jul 12th, 2014, 9:31pm »

Richard

Belated thanks for your examples. Just the job.

--
Ian
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls