CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2012
    Location
    Toronto
    Posts
    3

    MFC/SDI - switching views - not refreshing

    Hello fellow gurus,

    I was hoping someone could help me out with something.

    I have an MFC/SDI application, and I am trying to switch between a single view(CView), and a 2x2 split view(CSplitterWnd).

    Everything is working except that after I change views, the window doesn't refresh until I move it or minimize it.


    http://msdn.microsoft.com/en-us/libr...(v=vs.80).aspx

    I am referencing the above page, which shows how to switch between two single views, but it doesn't cover what to do when one of the views is a splitter window =/

    I have tried the following code, as suggested by the article, but it doesn't seem to have any effect:

    UINT temp = ::GetWindowLong(pActiveView->m_hWnd, GWL_ID);
    ::SetWindowLong(pActiveView->m_hWnd, GWL_ID, ::GetWindowLong(pNewView->m_hWnd, GWL_ID));
    ::SetWindowLong(pNewView->m_hWnd, GWL_ID, temp);

    the article says that the above is mandatory, or else RecalcLayout won't work...but I don't understand the connection, and can't seem to make this work with the splitter window.

    Any help would be much appreciated

    Thanks

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: MFC/SDI - switching views - not refreshing

    Quote Originally Posted by MrNicolas View Post
    the article says that the above is mandatory, or else RecalcLayout won't work...
    No, it does not, at least for Win32.
    it seemed to be mandatory only for Win16 applications. You can see that the above code is only performed if _WIN32 is not defined:
    Code:
     #ifndef _WIN32.
    And BTW, I use view switching in a lot of my MDI projects without any problem and without these GetWindowLong/SetWindowLong.

    However RecalcLayout has to be called.
    Victor Nijegorodov

  3. #3
    Join Date
    Apr 2012
    Location
    Toronto
    Posts
    3

    Re: MFC/SDI - switching views - not refreshing

    Hi, thanks for the reply. I think you may have misread the page I linked. The entire block of code is as follows:

    Code:
    // Exchange view window IDs so RecalcLayout() works.
       #ifndef _WIN32
       UINT temp = ::GetWindowWord(pActiveView->m_hWnd, GWW_ID);
       ::SetWindowWord(pActiveView->m_hWnd, GWW_ID, ::GetWindowWord(pNewView->m_hWnd, GWW_ID));
       ::SetWindowWord(pNewView->m_hWnd, GWW_ID, temp);
       #else
       UINT temp = ::GetWindowLong(pActiveView->m_hWnd, GWL_ID);
       ::SetWindowLong(pActiveView->m_hWnd, GWL_ID, ::GetWindowLong(pNewView->m_hWnd, GWL_ID));
       ::SetWindowLong(pNewView->m_hWnd, GWL_ID, temp);
       #endif
    The ID swap thing they are doing is in deed done for both 16bit and 32bit windows, the only difference is that 16bit uses SetWindowWord instead of SetWindowLong.

    Either way, it still doesn't fix my problem =/ They do seem to be right about RecalcLayout not properly working though.

    Upon further inspection, I found that after the view switch, my CSplitterWnd was only receiving OnSize() once, with a cx and cy of 0. After trying every update and repaint function I could think of, on both the splitter window, and the main frame, the only way I was finally able to get the view to update, was by calling MoveWindow on the splitter, and assigning the values from the single view's window rectangle to it.

    This seems like a hack of a solution though...and I wouldn't mind knowing exactly what's going on here.

    Finally, my code is as follows:

    Code:
    bool MainWindow::CreateSingleView()
    {
    	CCreateContext ctx;
    	ctx.m_pNewViewClass = RUNTIME_CLASS(StateView);
    	ctx.m_pNewDocTemplate = NULL;
    	ctx.m_pLastView = NULL;
    	ctx.m_pCurrentFrame = NULL;
    	ctx.m_pCurrentDoc = GetActiveDocument();
    
    	singleView = (StateView*)this->CreateView(&ctx);
    
    	splitView->ShowWindow(SW_HIDE);
    	singleView->ShowWindow(SW_SHOW);
    
    	CRect cRect;
    	splitView->GetWindowRect(&cRect);
    	ScreenToClient(&cRect);
    	singleView->MoveWindow(cRect.left, cRect.top, cRect.Width(), cRect.Height());
    
    	SetActiveView((CView*)singleView);
    
    	delete splitView;
    	splitView = NULL;
    
    	return true;
    }
    
    bool MainWindow::CreateSplitterView()
    {
    	CCreateContext cc;
    	cc.m_pNewViewClass = RUNTIME_CLASS(StateView);
    	cc.m_pNewDocTemplate = 0;
    	cc.m_pLastView = 0;
    	cc.m_pCurrentFrame = 0;
    	cc.m_pCurrentDoc = GetActiveDocument();
    
    	splitView = new CAutoSplitterWnd;
    	splitView->EnableAutoSize(true);
    
    	if (!splitView->CreateStatic(this, 2, 2, WS_CHILD))
    		return false;
    	
    	if (!splitView->CreateView(0, 0, cc.m_pNewViewClass, CSize(200, 200), &cc))
    		return false;
    
    	if (!splitView->CreateView(0, 1, cc.m_pNewViewClass, CSize(200, 200), &cc))
    		return false;
    
    	if (!splitView->CreateView(1, 0, cc.m_pNewViewClass, CSize(200, 200), &cc))
    		return false;
    
    	if (!splitView->CreateView(1, 1, cc.m_pNewViewClass, CSize(200, 200), &cc))
    		return false;
    	
    	singleView->ShowWindow(SW_HIDE);
    	splitView->ShowWindow(SW_SHOW);
    
    	CRect cRect;
    	singleView->GetWindowRect(&cRect);
    	ScreenToClient(&cRect);
    	splitView->MoveWindow(cRect.left, cRect.top, cRect.Width(), cRect.Height());
    
    	SetActiveView((CView*)splitView->GetPane(0, 0));
    
    	delete singleView;
    	singleView = NULL;
    	
    	return true;
    }
    any insight would still be helpful.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: MFC/SDI - switching views - not refreshing

    Quote Originally Posted by MrNicolas View Post
    Hi, thanks for the reply. I think you may have misread the page I linked. The entire block of code is as follows:

    Code:
    // Exchange view window IDs so RecalcLayout() works.
       #ifndef _WIN32
       UINT temp = ::GetWindowWord(pActiveView->m_hWnd, GWW_ID);
       ::SetWindowWord(pActiveView->m_hWnd, GWW_ID, ::GetWindowWord(pNewView->m_hWnd, GWW_ID));
       ::SetWindowWord(pNewView->m_hWnd, GWW_ID, temp);
       #else
       UINT temp = ::GetWindowLong(pActiveView->m_hWnd, GWL_ID);
       ::SetWindowLong(pActiveView->m_hWnd, GWL_ID, ::GetWindowLong(pNewView->m_hWnd, GWL_ID));
       ::SetWindowLong(pNewView->m_hWnd, GWL_ID, temp);
       #endif
    You are right! Sorry.
    And the main difference between your switching and mine is I replace a view within the splitter (either replace one pane or just remove it)...
    Victor Nijegorodov

  5. #5
    Join Date
    Apr 2012
    Location
    Toronto
    Posts
    3

    Re: MFC/SDI - switching views - not refreshing

    ugh...........

    I remember now, that my original decision(quite a while ago) was to use the static splitter instead of the dynamic, because I didn't want the scrollbars or the split row/column buttons

    So needless to say, I have removed the code that switches out the entire splitter... lol

    I am now simply creating the splitter, disabling the scrollbars, and creating/deleting rows/columns manually instead.

    Thanks for the help =)

  6. #6
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: MFC/SDI - switching views - not refreshing

    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

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