Solved

Tab seem not to work in CFrameWnd

Posted on 1998-10-29
1
437 Views
Last Modified: 2013-11-20
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?
0
Comment
Question by:busse
1 Comment
 
LVL 12

Accepted Solution

by:
migel earned 40 total points
ID: 1324005
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);
     else
       hNext = ::GetWindow(::GetParent(hWnd), GW_CHILD);
   }
  while (hNext && hNext != hWnd)
    {
     if (::GetWindowLong(hNext, GWL_STYLE)& WS_TABSTOP && 
         ::IsWindowVisible(hNext) && ::IsWindowEnabled(hNext))
       {
         ::SetFocus(hNext);
         if (::SendMessage(hNext, WM_GETDLGCODE,0,0)&DLGC_HASSETSEL)
          ::SendMessage(hNext, EM_SETSEL, 0, MAKELPARAM(0,-1));
         break;
       }
     hNext = ::GetWindow(hWnd, bBack ? GW_HWNDPREV: GW_HWNDNEXT);
    }

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


0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question