Software Archive
Read-only legacy content
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
17060 Discussions

Slider and Edit box

davidgraham
Beginner
943 Views
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
0 Kudos
8 Replies
Intel_C_Intel
Employee
943 Views
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
0 Kudos
davidgraham
Beginner
943 Views
Thanks, but if forgot to say, I want to do it in a Win API project, the example is a simple dialog project.

David
0 Kudos
Intel_C_Intel
Employee
943 Views
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
0 Kudos
davidgraham
Beginner
943 Views
What message should I use to to say a change has been made to the slider/trackbar or edit box?

Thanks,

David
0 Kudos
Intel_C_Intel
Employee
943 Views
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
0 Kudos
davidgraham
Beginner
943 Views
  
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  
0 Kudos
Intel_C_Intel
Employee
943 Views
Hi David,

Shouldn't

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

be:

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

?

Leo
0 Kudos
davidgraham
Beginner
943 Views
Leo, Thanks, that was a silly mistake.
Merry Christmas to you & Steve.

David
0 Kudos
Reply