Solved

Tab seem not to work in CFrameWnd

Posted on 1998-10-29
1
442 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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 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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

710 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