glee
asked on
Forcing focus in a splitter window
I have a two-pane static splitter window. The first pane (left side) contains a CView derived window and the second pane (right side) contains a CEditView derived window. I never want the first pane to get focus. I want to force focus to the second pane when the user clicks on any part of the window (title bar, border, left pane, right pane). I am handling the WM_SETFOCUS message in the left pane and am calling SetActiveView with the right pane as the parameter. This seems to activate the view because the buttons attached to the right view (CEditView derived) activate. But, the edit control does not display a cursor under certain conditions and you cannot enter text in the edit control unless you click directly on the control.
How do I force the edit control to "wake up"? Also, on occasion I can click on the left pane and it get's focus, so WM_SETFOCUS does not appear to be getting called. Should I be handling a different message? Or using OnActivate?
How do I force the edit control to "wake up"? Also, on occasion I can click on the left pane and it get's focus, so WM_SETFOCUS does not appear to be getting called. Should I be handling a different message? Or using OnActivate?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Store the handle to the two panes in CMainFrame object immediately after the creation of the splitter panes.
Override the member function OnActivate for the two pane-views and CMainFrame. If the handle of the window getting focus equals that of the pane which you do not want to get focus, then force focus to the other pane, using SetFocus.
As "jspeirs" suggested, you also need to handle OnMouseActivate on the panel which you do not want to get focus.
Override the member function OnActivate for the two pane-views and CMainFrame. If the handle of the window getting focus equals that of the pane which you do not want to get focus, then force focus to the other pane, using SetFocus.
As "jspeirs" suggested, you also need to handle OnMouseActivate on the panel which you do not want to get focus.
ASKER
Try this code in the OnMouseActivate function...
int
CTestView::OnMouseActivate
CYourDoc* pDoc = GetDocument();
POSITION pos = pDoc->GetFirstViewPosition
while(pos != NULL){
CYourEditView* pView = pDoc->GetNextView(pos);
if(pView->IsKindOf(RUNTIME
pView->SetFocus();
}
}
return MA_NOACTIVATEANDEAT;
}
if this doesn't work let me know.