Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Tab seem not to work in CFrameWnd

Posted on 1998-10-29
1
Medium Priority
?
454 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 160 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

971 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