Tabstop question

Started by Mark Strickland, September 27, 2005, 02:35:52 PM

Previous topic - Next topic

Mark Strickland

I think a proper SENDMESSAGE can turn on/off the TABSTOP flag for a control on a form.  Does anybody have an example of this code?

I have simulated turing on/off TABSTOPS with program code by setting focus where you want it in the EN_SETFOCUS and EN_KILLFOCUS events but sometimes this is very tedious and can lead to undesirable side effects.


I just /LOVE IT/HATE IT/GET CRAZY/DON'T UNDERSTAND IT/ (pick one) when I do Windows programming.    :wink:

Thanks

Roger Garstang


Mark Strickland

So others can benefit here is the code I used to set/clear TabStops and set/clear ReadOnly.

The only issue is the way the KILLFOCUS event works.  If you do this on the field in the KILLFOCUS event of the field one tab stop before the field you are changing it does not take place (for that field change event) since the tab stop has already been determined when KILLFOCUS on the current field is fired.  In that case you need to add a FF_SETFOCUS but remember the EN_SETFOCUS event code on the field you are forcing focus to will NOT fire on a forced FF_SETFOCUS.  The next time through the tabs with normal field navigation it will work.

Ahhhh ---- Windows.


   'Turn on TabStop and set ReadOnly off
   SENDMESSAGE hWndControl, %EM_SETREADONLY, %false, 0
   SETWINDOWLONG hWndControl, %GWL_STYLE, _
               GETWINDOWLONG(hWndControl, %GWL_STYLE) OR %ws_tabstop
   

   'Turn off TabStop and set ReadOnly on
   SENDMESSAGE hWndControl, %EM_SETREADONLY, %true, 0
   SETWINDOWLONG hWndControl, %GWL_STYLE, _
               GETWINDOWLONG(hWndControl, %GWL_STYLE) AND (NOT %ws_tabstop)



Sub your hWndControl handles for the target control.

The use of the GetWindowLong function preserves all of the other style bits.  You could use this to set other bits on/off also.

Thanks to Roger for the intial help.

Enjoy.