Solved

Forcing focus in a splitter window

Posted on 1997-05-01
3
313 Views
Last Modified: 2013-11-20
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?
0
Comment
Question by:glee
  • 2
3 Comments
 

Accepted Solution

by:
jspeirs earned 100 total points
Comment Utility
here is what you need to do.  I had a similiar problem.

if you never want focus in the view on the left just handle the WM_MOUSEACTIVATE message for the view that you don't want focus sent to.  In your overridden OnMouseActivate function all you need to do is return MA_NOACTIVATE.  By returning MA_NOACTIVATE the CWnd object (which is your view) will not be activated and you are all set.  there are other return values that you can specify.  You can look up OnMouseActivate in online help to see more.  One problem I did have was that I didn't notice the WM_MOUSEACTIVATE message in class wizard but added it manually inside the class wizard //{{ message map comments and followed the syntax of the other messages and when I pulled up class wizard again it saw the message.  If you need more help let me know.
0
 

Author Comment

by:glee
Comment Utility
I would try returning  MA_NOACTIVATEANDEAT which discards the mouse event as well as the activate window.  I don't have my source in front of me so if that doesn't work, you could run through the list of views in the document template and check for your CEditView class and then set that to the active view.
Try this code in the OnMouseActivate function...

int
CTestView::OnMouseActivate(CWnd *pwnd,UINT hittest,UINT message){

      CYourDoc* pDoc = GetDocument();
      POSITION pos = pDoc->GetFirstViewPosition();
      while(pos != NULL){
            CYourEditView* pView = pDoc->GetNextView(pos);
            if(pView->IsKindOf(RUNTIME_CLASS(CEditView))){
                  pView->SetFocus();
            }
      }
      return MA_NOACTIVATEANDEAT;
}


if this doesn't work let me know.
0
 

Expert Comment

by:jspeirs
Comment Utility
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.
0

Featured Post

What Security Threats Are You Missing?

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
Macro to save highlighted rows as a separate file 5 38
Define unique primary key 9 81
Line meaning 9 75
changeXy challenge 13 56
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. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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: …

763 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

8 Experts available now in Live!

Get 1:1 Help Now