Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
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.

Setting focus to item in list box

davidgraham
Beginner
666 Views

I have a dialog box with two radio buttons and a list box.

If button one is selected the list box shows one lot of data, if button two is selected the list box shows another lot of data. In both cases the first item in the list box is selected using iret=SendMessage(hListBox,LB_SETCURSEL,0,0).

If I press the down arrow I expect the second item in the list to be selected but instead the other radio button is selected and the contents of the list box change (as the radio button had focus).

I thought I could set focus to the list box using iret=SetFocus(IDC_LISTBOX), but it doesn't work (it returns 0).

The only way I can get it to work is to pick the fist item in the list box with the cursor then press the down arrow.

Can you suggest how I can do this.

Thanks,

David

0 Kudos
3 Replies
GVautier
New Contributor III
666 Views

Hello

SetFocus sets the focus to a window designed by its handle. You must retrieve the window handle of the control using DlgGetItem function.

iret=SetFocus(DlgGetItem(hdlg,IDC_LISTBOX));

should work

0 Kudos
anthonyrichards
New Contributor III
666 Views

You can get the index of the presently selected item by using

item=SendDlgItemMessage(dlg%hWnd,IDC_LISTBOX, LB_GETCURSEL, 0,0)

Then you can select the next item using

iret=SendDlgItemMessage(dlg%hWnd,IDC_LISTBOX, LB_SETCURSEL, MAKEWPARAM(item+1,0),0)

0 Kudos
davidgraham
Beginner
666 Views

Thanks, I should have realised I'd forgoten the DlgGetItem()

David

0 Kudos
Reply