Tab seem not to work in CFrameWnd

I have a Windowsclass, which is derived from CFrameWnd.

In it's constructor I create 4 CEdit controls, and some Buttons. Everything works just fine, however, tab doesn't switch between the controls though the WS_Tabstop style is used while creating the controls.

Any ideas?
Who is Participating?

Improve company productivity with a Business Account.Sign Up

migelConnect With a Mentor Commented:
Only dialogs can switch between controls by Tab key.
If you need switch focus between control in the another windows, then you must emulate dialog.
Is CFrameWnd deriviation critical for your app?
If it`s true, then you must subclass all controls inside your window and manually switch focus when TAB(SHIFT+TAB) is pressed:
for example:

// subclassing all controls by one window proc.
extern "C" LRESULT SwitchWndProc(HWND hWnd, UINT uMsg, WPARAM, LPARAM);
ATOM propFn; // registered atom
// must be call after creation of the controls!
void DoSubclassing(HWND hParent)
HWND hChild = ::GetWindow(hParent, GW_CHILD)
FARPROC lpfnWndProc;
while (hChild)
 if ( GetProp(hwnd,(LPCSTR)propFn) == NULL )
    lpfnWndProc = (FARPROC)SetWindowLong((HWND) hwnd,
                               GWL_WNDPROC, (LONG)SwitchWndProc);
    SetProp(hwnd, (LPCSTR) aCtl3d, (HANDLE)(DWORD)lpfnWndProc);
 hChild = ::GetWindow(hChild, GW_HWNDNEXT);

LRESULT SwitchWndProc(HWND hWnd, UINT uMsg, WPARAM wPar, LPARAM lPar)
if (uMsg == WM_KEYDOWN && wPar == VK_TAB)
  BOOL bBack = ::GetKeyState(VK_SHIFT) < 0;
  hNext = ::GetWindow(hWnd, bBack ? GW_HWNDPREV: GW_HWNDNEXT);
  if (hNext)
     if (bBack)
       hNext = ::GetWindow(hWnd, GW_HWNDLAST);
       hNext = ::GetWindow(::GetParent(hWnd), GW_CHILD);
  while (hNext && hNext != hWnd)
     if (::GetWindowLong(hNext, GWL_STYLE)& WS_TABSTOP && 
         ::IsWindowVisible(hNext) && ::IsWindowEnabled(hNext))
         if (::SendMessage(hNext, WM_GETDLGCODE,0,0)&DLGC_HASSETSEL)
          ::SendMessage(hNext, EM_SETSEL, 0, MAKELPARAM(0,-1));
     hNext = ::GetWindow(hWnd, bBack ? GW_HWNDPREV: GW_HWNDNEXT);

  return 0;
return ::CallWindowProc(::GetProp(hWnd, (LPCSTR) propFn), hWnd, uMsg, wParam, lParam);

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.