Solved

Tab seem not to work in CFrameWnd

Posted on 1998-10-29
1
430 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 85
Looking for a specific application/software 2 91
matchUp  challenge 9 71
unix example issues 18 44
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now