CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    Join Date
    Aug 2011
    Posts
    38

    Angry [MFC MDI] How to activate a view programmatically and safely ?

    I've developing MFC-MDI applications and this application has tabbed document style.
    I want to activate each view programmatically and using CMainFrame::SetActiveView method like below.

    void CMyView::OnShowWindow( BOOL bShow ... )
    {
    CView::OnShowWindow( bShow, ... );

    CMainFrame *mf = (CMainFrame*)AfxGetMainWnd();
    mf->SetActiveView(this);
    }

    This code makes a view active programatically but has a critical problem that the application pops up the error about the activation of the context when I close a document.

    How can I solve this problem?

  2. #2
    Join Date
    Jul 2002
    Posts
    2,543

    Re: [MFC MDI] How to activate a view programmatically and safely ?

    Maybe you need to do this only when bShow=TRUE.

  3. #3
    Join Date
    Aug 2011
    Posts
    38

    Re: [MFC MDI] How to activate a view programmatically and safely ?

    Sorry I did it, but I'd forgot to write in the avobe code.

  4. #4
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: [MFC MDI] How to activate a view programmatically and safely ?

    Quote Originally Posted by lightshield View Post
    I've developing MFC-MDI applications and this application has tabbed document style.
    I want to activate each view programmatically and using CMainFrame::SetActiveView method like below.
    I don't understand. When do you want to activate a view?
    What kind of behavior are you trying to implement?
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: [MFC MDI] How to activate a view programmatically and safely ?

    Quote Originally Posted by lightshield View Post
    This code makes a view active programatically but has a critical problem that the application pops up the error about the activation of the context when I close a document.

    How can I solve this problem?
    Have you tried stepping into the mfc source code and finding out where the error has occurred? Often times, the MFC source code will have comments where the assertion occurs that helps you track down the problem.

  6. #6
    Join Date
    Jun 2006
    Location
    Chile
    Posts
    13

    Re: [MFC MDI] How to activate a view programmatically and safely ?

    What comments are they ?

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: [MFC MDI] How to activate a view programmatically and safely ?

    You didn't tell us the error and you didn't show all your code. Not much we can do at this point. I'm not really sure why you're doing it from OnShowWindow either.

  8. #8
    Join Date
    Aug 2011
    Posts
    38

    Re: [MFC MDI] How to activate a view programmatically and safely ?

    This tab's problem can be discussed abstractly.

    MDI style application has the tabbed document style.
    If one tab clicked then associated view will be activated and other views will be deactivated.
    I want to implement this behavior programmatically but I've not found solutions yet.

    Please give me gurus power.

  9. #9
    Join Date
    Aug 2011
    Posts
    38

    Re: [MFC MDI] How to activate a view programmatically and safely ?

    I think that the MFC has not had obvious method to implement this behavior programmatically because of nothing of requirements for this purpose.

    I'd implemented desired behavior by an other agenda. But if programmatic methods for this purpose exists, I want to know these.

    So please try to answer this problem. Thanks all.

  10. #10
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: [MFC MDI] How to activate a view programmatically and safely ?

    Did you even look at MSDN? If you had, you probably would have found

    CMDIFrameWnd::MDIActivate

  11. #11
    Join Date
    Aug 2011
    Posts
    38

    Re: [MFC MDI] How to activate a view programmatically and safely ?

    Yes, I had
    But MDIActivate didn't work with tabbed document style. I had used CMDIFrameWnd::SetActiveView alternatively and this makes the objective view active but an exception occurs when I close arbitrary documents.

  12. #12
    Join Date
    Aug 2011
    Posts
    38

    Re: [MFC MDI] How to activate a view programmatically and safely ?

    I say this situation other words, MDIActivate and SetActiveView functions didn't emulate 'click on a tab' behavior.

  13. #13
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: [MFC MDI] How to activate a view programmatically and safely ?

    Quote Originally Posted by lightshield View Post
    I say this situation other words, MDIActivate and SetActiveView functions didn't emulate 'click on a tab' behavior.
    Did you pass a view pointer or a MDI child pointer. I believe it wants a CChildFrame pointer rather than a view.

  14. #14
    Join Date
    Aug 2011
    Posts
    38

    Re: [MFC MDI] How to activate a view programmatically and safely ?

    Yes, I did.
    I'd tried some way using CView* or CChildFrame* with CMDIFrameWnd::SetActiveView, but I can't solve an exception. But, therefor, this method can activate the desired view.

  15. #15
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: [MFC MDI] How to activate a view programmatically and safely ?

    Quote Originally Posted by lightshield View Post
    Yes, I did.
    I'd tried some way using CView* or CChildFrame* with CMDIFrameWnd::SetActiveView, but I can't solve an exception. But, therefor, this method can activate the desired view.
    I'm having trouble following what you're saying here. What exception?

    Can you show the code you tried.

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured