extreme001
extreme001

Reputation: 363

How to focus or select an item?

What is the correct way to select a button in WinAPI so that the button or item has input focus indicated by the dotted lines? If I just set focus, it is not selected. An example: I select an item index in a combobox via CB_SETSEL; how to select the complete item (dotted line, blue background)?

Upvotes: 0

Views: 194

Answers (2)

Jeff D.
Jeff D.

Reputation: 328

The 'blue background' indicates the cell or list item is selected. The 'dotted line' indicates that the cell or list item has the focus. These are two different things that require two different method calls or messages. In the style you are using, you have to send the CB_SETCURSEL message also.

http://www.jasinskionline.com/windowsapi/ref/c/cb_setcursel.html

Upvotes: 0

Jonathan Potter
Jonathan Potter

Reputation: 37192

In a dialog, you should use the DM_SETDEFID message to make a push button the default. Simply calling SetFocus will give focus to a button (the "dotted lines") but won't make it the default button (the one that's actioned by pressing the Return key). For example,

SendMessage(hwndDlg, DM_SETDEFID, IDC_BUTTON, 0);

For other types of controls, SetFocus is all you need, e.g:

SetFocus(GetDlgItem(hwndDlg, IDC_COMBO));

Upvotes: 1

Related Questions