Tab navigation problem
-
I create modelles dialog box as child inside a window (not using MFC) tab navigation between controls does not work :wtf: is there some way to implement it ? Thanks.
I had the problem with a modeless dialog owned by an ActiveX main window. Using MFC, I solved this by implementing in the PreTranslateMessage method of the Main Window the following code:
if((pMsg->message == WM_KEYDOWN) && (::IsWindow(pMsg->hwnd))){ HWND hMsgWnd = pMsg->hwnd; HWND hParent = ::GetParent(hMsgWnd); // Specific for modeless dialogs if(hParent){ if((pMsg->wParam == VK_TAB) || (pMsg->wParam == VK_RETURN)){ if(CWnd::FromHandle(hMsgWnd)->PreTranslateMessage(pMsg)) return TRUE; else if(pMsg->wParam == VK_TAB){ // Activate next or previous tabbed control, according to Shift value BOOL bShift = HIBYTE(GetKeyState(VK_SHIFT)); HWND hNewWnd = ::GetNextDlgTabItem(hParent, hMsgWnd, bShift); if(hNewWnd){ TCHAR szClass[10]; HWND hFirstWnd = hNewWnd; BOOL bBreak = FALSE; // if it's a static, do it again while(::GetClassName(hNewWnd, szClass, 10) && (lstrcmpi(szClass, _T("STATIC")) == 0)){ HWND hOldWnd = hNewWnd; hNewWnd = ::GetNextDlgTabItem(hParent, hNewWnd, bShift); if(hNewWnd == hOldWnd){ hNewWnd = NULL; break; } if(bBreak){ hNewWnd = NULL; break; } bBreak = (hNewWnd == hFirstWnd); } if(hNewWnd){ ::SetFocus(hNewWnd); return TRUE; } } }else{ if(pMsg->wParam == VK_RETURN){ TCHAR szClass[10]; if(::GetClassName(hMsgWnd, szClass, 10) && (lstrcmpi(szClass, _T("BUTTON")) == 0)){ ::SendMessage(hParent, WM_COMMAND, ::GetDlgCtrlID(hMsgWnd), (LPARAM)hMsgWnd); return TRUE; } } } return CWnd::FromHandle(hParent)->PreTranslateMessage(pMsg); } if(CWnd::FromHandle(hParent)->PreTranslateMessage(pMsg)) return TRUE; } }
We do not inherit the Earth from our ancestors, we borrow it from our children - Antoine de Saint-Exupéry (1900-1944)
-
I had the problem with a modeless dialog owned by an ActiveX main window. Using MFC, I solved this by implementing in the PreTranslateMessage method of the Main Window the following code:
if((pMsg->message == WM_KEYDOWN) && (::IsWindow(pMsg->hwnd))){ HWND hMsgWnd = pMsg->hwnd; HWND hParent = ::GetParent(hMsgWnd); // Specific for modeless dialogs if(hParent){ if((pMsg->wParam == VK_TAB) || (pMsg->wParam == VK_RETURN)){ if(CWnd::FromHandle(hMsgWnd)->PreTranslateMessage(pMsg)) return TRUE; else if(pMsg->wParam == VK_TAB){ // Activate next or previous tabbed control, according to Shift value BOOL bShift = HIBYTE(GetKeyState(VK_SHIFT)); HWND hNewWnd = ::GetNextDlgTabItem(hParent, hMsgWnd, bShift); if(hNewWnd){ TCHAR szClass[10]; HWND hFirstWnd = hNewWnd; BOOL bBreak = FALSE; // if it's a static, do it again while(::GetClassName(hNewWnd, szClass, 10) && (lstrcmpi(szClass, _T("STATIC")) == 0)){ HWND hOldWnd = hNewWnd; hNewWnd = ::GetNextDlgTabItem(hParent, hNewWnd, bShift); if(hNewWnd == hOldWnd){ hNewWnd = NULL; break; } if(bBreak){ hNewWnd = NULL; break; } bBreak = (hNewWnd == hFirstWnd); } if(hNewWnd){ ::SetFocus(hNewWnd); return TRUE; } } }else{ if(pMsg->wParam == VK_RETURN){ TCHAR szClass[10]; if(::GetClassName(hMsgWnd, szClass, 10) && (lstrcmpi(szClass, _T("BUTTON")) == 0)){ ::SendMessage(hParent, WM_COMMAND, ::GetDlgCtrlID(hMsgWnd), (LPARAM)hMsgWnd); return TRUE; } } } return CWnd::FromHandle(hParent)->PreTranslateMessage(pMsg); } if(CWnd::FromHandle(hParent)->PreTranslateMessage(pMsg)) return TRUE; } }
We do not inherit the Earth from our ancestors, we borrow it from our children - Antoine de Saint-Exupéry (1900-1944)