The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: dancho on June 02, 2006, 04:34:53 PM

Title: UpDown Control with real numbers increment or decrement
Post by: dancho on June 02, 2006, 04:34:53 PM
hi all

The problem is when I click an arrow up or down on my spin control I want to increment or decrement
a real number value,something like this:

0.25 is for one click so:

arrow up: 00.00--->00.25--->00.50--->00.75  etc

I know how to do it with integer values but with real one I have no idea...

thx for replies...



Title: Re: UpDown Control with real numbers increment or decrement
Post by: P1 on June 02, 2006, 05:48:42 PM
Post what you have done so far or make a demo of what you want to do.

Regards,  P1  :8)
Title: Re: UpDown Control with real numbers increment or decrement
Post by: dancho on June 03, 2006, 01:49:35 AM
invoke GetDlgItem,hWin,IDC_EDT1 
mov hEditb1,eax ;getting handle of editbox ( IDC_EDT1 )
invoke SendDlgItemMessage,hWin,IDC_UDN1,UDM_SETBUDDY,hEditb1,0 ; setting buddy of updown control ( IDC_UDN1 )

mov dx,1 ;min value
ror edx,16
mov dx,31 ;max value
invoke SendDlgItemMessage,hWin,IDC_UDN1,UDM_SETRANGE,0,edx ;range
 .
 .
 .

and then when I click arrow ( up or down ) I have increment or decrement of 1...
Title: Re: UpDown Control with real numbers increment or decrement
Post by: raymond on June 03, 2006, 03:21:01 AM
The automatic "buddy" with up/down controls only process sequential integers.
If you want to display other types of values (i.e. non-sequential, floats, etc.), you will have to avoid the "buddy", process the up/down control notification messages yourself, and then display yourself whatever you prefer in the edit control.

Raymond
Title: Re: UpDown Control with real numbers increment or decrement
Post by: dancho on June 03, 2006, 08:11:38 AM
@reymond

if I dont use UDM_SETBUDDY to assign a buddy window to an updown control they
will not look like single control ( spinner control ) ...
Title: Re: UpDown Control with real numbers increment or decrement
Post by: raymond on June 04, 2006, 02:15:58 AM
You can always position the EDIT and the UP/DOWN  controls in such a way that they would appear as a single control.

If you insist on using the UDM_SETBUDDY for that purpose, you will still have to process the UDN_DELTAPOS notification message and return TRUE to prevent Windows from making any changes to the EDIT control after you have made your own changes.

Raymond
Title: Re: UpDown Control with real numbers increment or decrement
Post by: dancho on June 04, 2006, 09:55:06 AM
@reymond

dont understand
How can I prevent or allow return values to be TRUE or FALSE ?
Title: Re: UpDown Control with real numbers increment or decrement
Post by: dancho on June 04, 2006, 12:21:29 PM
maybe something like this :
.
.
.elseif eax==WM_NOTIFY
mov eax,lParam
.if [eax].NMHDR.code==UDN_DELTAPOS
.
.         
.endif
.
Title: Re: UpDown Control with real numbers increment or decrement
Post by: raymond on June 05, 2006, 03:11:08 AM
.elseif eax==WM_NOTIFY
mov eax,lParam
.if [eax].NMHDR.code==UDN_DELTAPOS

;The lParam of the message is a pointer to an NM_UPDOWN structure
;Get the info and adjust the EDIT control as required
.....
.....
return TRUE    ;to prevent Windows from processing the same message

.endif

(Look at the description of the UDN_DELTAPOS message in the Win32 Programmer's Reference.)

Raymond
Title: Re: UpDown Control with real numbers increment or decrement
Post by: KSS on June 05, 2006, 07:25:10 AM
Dancho,
 The simple and right way is to create subclassed control for UpDownCtrl.
Read MSDN and you understand me (and windows too  :bg).
Title: Re: UpDown Control with real numbers increment or decrement
Post by: P1 on June 05, 2006, 01:50:32 PM
I done this in VB.  Multiply the integer part by .250 and you will have a resultant steps of a quarter increment.

Regards,  P1  :8)
Title: Re: UpDown Control with real numbers increment or decrement
Post by: dancho on June 05, 2006, 06:24:46 PM
thx all for yours time and replies...

:U
Title: Re: UpDown Control with real numbers increment or decrement
Post by: dancho on June 07, 2006, 03:30:37 PM
well it seems that I cant get it right , or I miss something again ...

elseif eax==WM_NOTIFY
      mov edx,lParam
      mov eax,[edx].NMHDR.hwndFrom
      .if eax==hUpd9;handle of UpDown control
         .if [edx].NMHDR.code==UDN_DELTAPOS
             mov eax,lParam
             mov [eax].NM_UPDOWN.iPos,0
             mov [eax].NM_UPDOWN.iDelta,3
             return TRUE
         .endif
      .endif

program is working , but ( there is always atleast one but ) if I click up or down arrow numbers always going up to max number in range
like there is no down arrow at all...
so from 0 to 3,6,9,12 etc...max number
any help will be appriciate
Title: Re: UpDown Control with real numbers increment or decrement
Post by: raymond on June 08, 2006, 02:53:47 AM
Quoteif I click up or down arrow numbers always going up to max number in range
like there is no down arrow at all...

Obviously. With the mov [eax].NM_UPDOWN.iDelta,3, you are telling it to increase the number by 3 all the time regardless of the UP or DOWN arrow having been clicked. The message is telling you that the information is located in the iDelta component. Check whether it is negative or positive before overwriting it.

Raymond
Title: Re: UpDown Control with real numbers increment or decrement
Post by: dancho on June 08, 2006, 06:47:35 AM
@reymond
thx , it is working now ...

QuoteThe iDelta member of the structure is a signed integer that contains the proposed change in position. If the user has clicked on the up button, this is a positive value. If the user has clicked on the down button, this is a negative value.

It seems that I didnt understand this explanation,I thought that up or down button gives + or - sign to the iDelta no matter what sign previuse iDelta was...
Title: Re: UpDown Control with real numbers increment or decrement
Post by: dancho on June 10, 2006, 06:20:57 AM
.elseif eax==WM_NOTIFY
        mov edx,lParam
        mov eax,[edx].NMHDR.hwndFrom
        .if eax==hUpd9;handle of UpDown control
         .if [edx].NMHDR.code==UDN_DELTAPOS
             mov edx,lParam
             mov eax,[edx].NM_UPDOWN.iDelta
             .if eax==1
                invoke SendDlgItemMessage,hWin,IDC_EDT12,WM_GETTEXT,sizeof ipos_buff_9,addr ipos_buff_9
                invoke FpuAtoFL,addr ipos_buff_9,addr ipos_real9,DEST_MEM ; decimal string to real
                invoke FpuAdd,addr ipos_real9,addr icdc,addr ipos_sum9,SRC1_REAL or SRC2_REAL or DEST_MEM ; adding 0.250
                invoke FpuFLtoA,addr ipos_sum9,2,addr outpos_buff_9,SRC1_REAL or SRC2_DIMM ; writing back to decimal string
                .elseif eax==-1
                  invoke SendDlgItemMessage,hWin,IDC_EDT12,WM_GETTEXT,sizeof ipos_buff_9,addr ipos_buff_9
                    invoke FpuAtoFL,addr ipos_buff_9,addr ipos_real9,DEST_MEM
                    invoke FpuSub,addr ipos_real9,addr icdc,addr ipos_sum9,SRC1_REAL or SRC2_REAL or DEST_MEM
                    invoke FpuFLtoA,addr ipos_sum9,2,addr outpos_buff_9,SRC1_REAL or SRC2_DIMM
              .endif
             return TRUE
         .endif
        .endif

.elseif eax==WM_VSCROLL
invoke SendDlgItemMessage,hWin,IDC_EDT12,WM_SETTEXT,0,addr outpos_buff_9


like I said program is working , values in spinner control are going up or down by 0.250 , but  :dazzled:
the problem is when I add second spin control(same code like this) and new line for that control in WM_VSCROLL , like this

.elseif eax==WM_VSCROLL

invoke SendDlgItemMessage,hWin,IDC_EDT12,WM_SETTEXT,0,addr outpos_buff_9
invoke SendDlgItemMessage,hWin,IDC_EDT13,WM_SETTEXT,0,addr outpos_buff_10

when user click up or down arrow on one control ,
other control is automaticly empty...
I know thats because other control buff is empty ( there wasnt any clicking yet),
my question is how I can control that...


btw both controls getting their default values like this:
.if eax==WM_INITDIALOG
invoke SendDlgItemMessage,hWin,IDC_EDT12,WM_SETTEXT,0,addr df_spin12
invoke SendDlgItemMessage,hWin,IDC_EDT13,WM_SETTEXT,0,addr df_spin13

thx


Title: Re: UpDown Control with real numbers increment or decrement
Post by: raymond on June 11, 2006, 03:01:11 AM
Quotelike I said program is working , values in spinner control are going up or down by 0.250

Glad to hear that. (Also nice to see some use for the Fpulib.)

Quotemy question is how I can control that...

That is quasi-impossible to answer without seeing most of the code you used. Zip it up, including the resource file, and I will have a look at it.

Raymond
Title: Re: UpDown Control with real numbers increment or decrement
Post by: dancho on June 12, 2006, 10:05:32 AM
I find FpuLib very very helpful...

:U

this is download link for small program that shows exactly what is the problem,
btw I put all RadAsm project in it ( 8kb )...

Your Download-Link: http://rapidshare.de/files/22851628/SpinControl.7z.html
Title: Re: UpDown Control with real numbers increment or decrement
Post by: raymond on June 13, 2006, 02:35:39 AM
Please, what must I use to access the information inside that .7z file????? :dazzled: :dazzled: :dazzled:

Raymond
Title: Re: UpDown Control with real numbers increment or decrement
Post by: Tedd on June 13, 2006, 03:22:28 AM
www.7-zip.org (http://www.7-zip.org)
Title: Re: UpDown Control with real numbers increment or decrement
Post by: dancho on June 13, 2006, 09:06:05 AM
I just notice some strange behavior of spin control in this program,
when you click up or down arrow ( I mean no clicking but one click and keep it press ) values want go
for their max or min but only for 3.75 points ( + or - , depends if you click up or down ) and it will
stop...
I dont see any limitations in program that can cause that ...!

@raymond
sry...
I'm using 7-Zip for a long time and I thought that newest versions of WinRar and WinZip
can open *.7z file...
If you have trouble with it I will post link with *.rar or *.zip file...
thx
Title: Re: UpDown Control with real numbers increment or decrement
Post by: raymond on June 13, 2006, 07:52:46 PM
Tedd:
Thanks for the link.

dancho:
Quotewhen user click up or down arrow on one control ,
other control is automaticly empty...
I know thats because other control buff is empty ( there wasnt any clicking yet),
my question is how I can control that...

Initialize your outpos_buff buffers with the default values when processing the WM_INITDIALOG message.

QuoteI just notice some strange behavior of spin control in this program,
when you click up or down arrow ( I mean no clicking but one click and keep it press ) values want go
for their max or min but only for 3.75 points ( + or - , depends if you click up or down ) and it will
stop...
I dont see any limitations in program that can cause that ...!

Instead of checking if EAX=1 or -1, try checking if EAX is positive or negative instead.

test eax,eax
.if !SIGN?     ;if positive
   ....
.else          ;if negative
   ....
.endif


I would also suggest you increase the size of the edit boxes so that the entire number can be displayed.

Raymond
Title: Re: UpDown Control with real numbers increment or decrement
Post by: dancho on June 13, 2006, 09:06:19 PM
@raymond
thy very much....

:U