Having the view know it is in focus

This is a discussion on Having the view know it is in focus within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I have a MDI program with child windows of different views. I need each view to know when it ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    205

    Having the view know it is in focus

    Hi,
    I have a MDI program with child windows of different views. I need each view to know when it is in focus. I have tried to overload the OnActivateView() function in my View class to no avail:

    Code:
    void CG3::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) 
    {
    	 
    	if(m_oldActive != NULL) {
    		if(*m_oldActive != *pActivateView) {
    	
    			theG3->setSerial(m_serial);
    		}
    	}
    	
    	// Set old view equal to new view
    	m_oldActive = pActivateView;
    	theG3->setSerial(m_serial);
                   CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
    
    }
    Can anybody figure out why it is not working. Thanks
    Amish

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,264
    What's not working? Is the OnActivateView() function not getting called?

    Code:
    if(*m_oldActive != *pActivateView)
    You should just compare pointer values here.

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    205
    It is being called constantly but pActivateView and pDeactiveView are always equal. Does this only work when the main windows are switched, i.e. between my program and internet explorer or Would it work when the child windows are swapped as well. Thank you for any reply,
    Amish

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,264
    It should work when child windows are swapped. pActivateView and pDeactiveView will be the same when you switch from a different program, to your own program (or vice versa). When you switch from one child window to another, pActivateView and pDeactiveView should be different.

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    205
    Quote Originally Posted by bithub
    It should work when child windows are swapped. pActivateView and pDeactiveView will be the same when you switch from a different program, to your own program (or vice versa). When you switch from one child window to another, pActivateView and pDeactiveView should be different.
    That's what I read on MSDN but it just does not do what it is supposed to when you switch child windows. I finally overloaded the OnWindowPosChanged() function and it seems to work for that. Thanks anyways
    Amish

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Changing focus in an MFC Application
    By rangalo in forum Windows Programming
    Replies: 2
    Last Post: 06-20-2005, 07:21 AM
  2. Tree View control not appearing
    By Garfield in forum Windows Programming
    Replies: 1
    Last Post: 03-07-2004, 01:47 PM
  3. Focus & Always-On-Top :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 06-13-2002, 06:44 PM
  4. Set View Position in CEditView :: MFC
    By kuphryn in forum Windows Programming
    Replies: 1
    Last Post: 05-21-2002, 10:27 PM
  5. Determining Active View :: MFC
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 04-25-2002, 08:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21