How to subclass an edit control to catch the tab key

Hi, I have a bunch of edit controls on a dialog box that I would like users to be able to tab between. I understand the best way to do this is to subclass the edit control to somehow catch the tab key and handle it. Does anyone know how to do this? I've never had to subclass a control before.

Thanks.
[318 byte] By [dillydadally] at [2007-11-20 11:40:39]
# 1 Re: How to subclass an edit control to catch the tab key
Add style WS_TABSTOP when creating child EDIT controls, which will automatically let your controls switch foucs using tab key.

Q . Is dialog created from resources or you used CreateWindow??

regards
Ali Imran at 2007-11-9 13:32:56 >
# 2 Re: How to subclass an edit control to catch the tab key
The dialog is designed using using the built in editor in Visual Studio .NET. Then I use CreateDialog to actually bring it into my project. I also have set the tabstop property, but that seems to only let me tab to a text box and not tab off of the text box.
dillydadally at 2007-11-9 13:33:56 >
# 3 Re: How to subclass an edit control to catch the tab key
Smeone else using resource editor can help you better :), sorry I cannot be of much help. Besieds what kind of other controls your dialog has which do not accept tab focus, and did you add style WS_TABSTOP to all controls ?

regards
Ali Imran at 2007-11-9 13:34:54 >
# 4 Re: How to subclass an edit control to catch the tab key
I set the TabStop property to true for all the controls in the Resource editor. In another post I was directed to create a subclass of the edit control and handle the WM_KEYDOWN message. Everywhere I look online it tells me how to do this using MFC, which my project does not use. If anyone knows how to do this without MFC, I'd really appreciate it.
dillydadally at 2007-11-9 13:35:59 >
# 5 Re: How to subclass an edit control to catch the tab key
I set the TabStop property to true for all the controls in the Resource editor. In another post I was directed to create a subclass of the edit control and handle the WM_KEYDOWN message.Apparently that was a joke. :) Dialogs process Tab key special way (by moving focus to other control that has a WS_TABSTOP style), and this behavior is implemented by Windows. The only thing you need is to provide correct tab stop styles for your dialog controls.

It would be good to take a look at your project, if it's possible of course.
Igor Vartanov at 2007-11-9 13:36:57 >
# 6 Re: How to subclass an edit control to catch the tab key
I've been using the resource editor and setting the property of each of these text boxes to TabStop = true. This, however, doesn't seem to work to tab off of the text boxes - just onto the textboxes. How do I provide correct tab stop styles to change this behavior? Can I do it in the resource editor or do I have to do it in code? If in code, could you give me an example because I've always just used the resource editor and I'm not sure how to apply styles or properties in code to individual controls on a dialog box.

Thanks
dillydadally at 2007-11-9 13:37:56 >
# 7 Re: How to subclass an edit control to catch the tab key
It would be very helpful to have a slim dialog app project that reproduces your issue. Then it might be fixed by some of the gurus here, and you could see the way to fix the issue in your real application. :)
Igor Vartanov at 2007-11-9 13:38:59 >
# 8 Re: How to subclass an edit control to catch the tab key
Actually, I was about to do this when I found the problem! Thanks so much for your help and willingness though.

The problem was actually in my main message loop. I needed to call IsDialogBox() and handle it rather than letting the translate and dispatch message functions handle it. After that, the tabbing worked great!

Thanks again.
dillydadally at 2007-11-9 13:40:01 >