Slider and Edit box

Slider and Edit box

I have a slider and edit box side by side.
I want them to be related - like a buddy with a spin control.
As the user moves the slider I would like the value in the edit box to change and if a value is enterted in the edit box the slider is updated.

Can I do this?

Thanks,

David

9 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hi David,

Yes, you should be able to do that. The new ...DialogTemp sample does this with 2 edit boxes and a scroll bar. Using a slider instead of a scroll bar makes only a small difference in the code.

Regards,
Leo

Thanks, but if forgot to say, I want to do it in a Win API project, the example is a simple dialog project.

David

It should be doable, but I have no sample for using native Win32 APIs. I believe it is just a matter of when the value of one or the other control changes (which you determine by handling a message), you set the value of the other control to the new value. That's the way the TEMP example works (although the messages are automatically turned in "callbacks").

Leo

What message should I use to to say a change has been made to the slider/trackbar or edit box?

Thanks,

David

Hi David,

Take a look at the dialog procedure (DlgCommonProc) in DFLOGM.F90 for an example of how the typically interesting messages are handled. Controls typically send a "notification" message to their parent (e.g the dialog box) when something interesting happens. The most interesting messages are WM_COMMAND, WM_NOTIFY, and the 2 WM_?SCROLL messages. DlgCommonProc calls DlgWmCommand and DlgWmScroll to handle these. For example, in DlgWmCommand, the edit control notifications that are looked for are EN_CHANGE, EN_UPDATE, EN_SETFOCUS and EN_KILLFOCUS. A slider (called a "track Bar" in the Win32 docs) sends WM_?SCROLL messages.

To update a control's value, you send it a message. Use the TBM_SETPOS message for the slider, and the WM_SETTEXT message for the edit control.

I hope this helps,
Leo

  
So far, I have 1 out of 2!  
   
I have got the edit box to update when the slider/trackbar moves:  
  
integer*4 iret,hTB.hwnd  
logical*4 lret  
  
case (WM_HSCROLL)  
iret=SendMessage(hTB,TBM_GETPOS,0,0)    ! hTB handle of track bar  
! this gets the value iret from the trackbar  
lret=SetDlgItemInt(hwnd,IDC_EDIT,iret,.false.)  
! this displays the value iret in the Edit box   
  
I haven't been able to get the trackbar to move when a value is entered in the edit box - any ideas what I am doing wrong?  
  
integer*4 iMess,hwnd,iret  
logical*4 lOK  
  
CASE (IDC_EDIT)  
if (iMess==EN_CHANGE) then  
  iret=GetDlgItemInt(hwnd,GetDlgItem(hwnd,IDC_EDIT),loc(lOK),.false.)  
! this should get the value from the edit box in iret.  
! but iret is always 0, and lOK is always false - why is this ??   
  iret=SendMessage(hTBR,TBM_SETPOS,.true.,iret)  
! this should set the trackbar to the value iretl  
end if  
  
Thanks,  
  
David  

Hi David,

Shouldn't

iret=GetDlgItemInt(hwnd,GetDlgItem(hwnd,IDC_EDIT),loc(lOK),.false.)

be:

iret=GetDlgItemInt(hwnd,IDC_EDIT,loc(lOK),.false.)

?

Leo

Leo, Thanks, that was a silly mistake.
Merry Christmas to you & Steve.

David

Leave a Comment

Please sign in to add a comment. Not a member? Join today