Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ListBox Control Pressing Enter Key Causes Exit 1

Status
Not open for further replies.

shetlandbob

Programmer
Mar 9, 2004
528
GB
Hi,

I've got a dialog based application with a list box control, and when I set focus, using mouse or tab and press enter into it then the program exits?? I did notice the same with an edit box but managed to fix that, however I've not managed to fix this one yet? Any ideas on how to fix it???

Thanks,

Bob
 
When you press enter, the normal behavior is to activate the default button in the dialog, which is usually the "OK" button that closes the dialog window.

Sometimes for edit controls, we want to change that behavior, so that we can press Enter to insert a new line into the edit control.

However, list box controls have no interest in the Enter key. You may as well let them use the default behavior because otherwise your users can't press OK with the keyboard.

If you really want to change this behavior for a list box, subclass the control (See MFC Technical Note TN014) and then add a WM_GETDLGCODE handler. Then return DLGC_WANTALLKEYS in the handler.

I REALLY hope that helps.
Will
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top