Link to home
Start Free TrialLog in
Avatar of ericcnc
ericcnc

asked on

Getting the CView to respond to the SplitterWindow,Cview messageHandlers in SDI app

I have  made a splitter window in a SDI app, it works great except that it doesnt acknowledge the CView handlers (the button is disabled..grayed out) UNLESS you have picked in the CVIEW window, then the button lights up.

The reason for this is in the CMainFrame to create a SDI splitter I have to return TRUE and not let the function OnCreateClient() do the default action of CFrameWnd::OnCreateClient(lpcs, pContext);(see below)

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
      //deteled the splitter creation code (its standard stuff)

//by uncommenting this out then you create a view that allows active buttons
//but you will destroy your splitters
//      return CFrameWnd::OnCreateClient(lpcs, pContext);

      return TRUE;//do this so the splitter shows up in the SDI app, but button handlers to
                                  //CView are inactive unless you select the actual view
}

Is there a way to set this up so that even though you are in a sdi app with splitters, if I want to add handlers to the cview class they are enabled aoutomatically , similar to if you did call:
 return CFrameWnd::OnCreateClient(lpcs, pContext);
this will enable all buttons for a CView window, even if you didnt select in the window.

Avatar of waelothman
waelothman

I don't know what code you write but I think the following Code will solve your problem
Declare       CSplitterWnd m_Split; in main frame
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
      m_Split.CreateStatic(this,1,2);
                m_Split.CreateView(0,0RUNTIME_CLASS(CView2),CSize(0,0),pContext);
      m_Split.CreateView(0,1,pContext->m_pNewViewClass,CSize(0,0),pContext);
               m_Split.SetActivePane(0,1);
      return true;
}
where CView2 is the new view you did
make sure  if you use CFormView make sure you made the dialog CHILD
if any comment pleas let me know
Avatar of ericcnc

ASKER

The issue is that one of my panes is a form view, and the other is the CView, and from above, I'm not sure how you do what you say knowing this?


      // Top splitter window
      if (!m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CFormView),
            CSize(0, 205), pContext)) //CSize(0, 400)
      {
            m_wndSplitter.DestroyWindow();
            return -1;
      }

      // Bottom splitter window
      if (!m_wndSplitter.CreateView(1,0,RUNTIME_CLASS(CViNView),
            CSize(0, 0), pContext)) //CSize(0, 0)
      {
            m_wndSplitter.DestroyWindow();
            return -1;
      }
      

      m_wndSplitter.RecalcLayout();

first you may want to add  m_Split.SetActivePane(0,0); at the end of the function and trturn true
2nd don't user name class CFormView insted make new vie using insert -> class and choose parent calss as CFormView and give it the id of dialog view and then user its name insted of CFormView after including header file
Avatar of ericcnc

ASKER

I did the setactive pane, But If I click on the form view the button grays out.

****((((((I'm not sure what you are saying for the 2nd part)))
****((((((can you write me a example)))
I belive you are talking about the proper way to make a from view, of which I did.

((Try this make a sdi app, create a splitter view(two views) , then make a simple form view and place it into a one of two splitters, and the regular cview in the other. Then make a handler in the cview class , and make a button on the toolbar that calls this handler, you will notice that if you dont select the CView pane, it will not light up, but if you do select the cview pane it will....that is what I'm trying to solve....))



The code below is the actual code, the top pane is a formview, the botton is a cview, the form view works fine as well as the cview, but if I make a button function in the cview class the handler does not become active unless I select the cview pane.

      if (!m_wndSplitter.CreateStatic(this, 2, 1,WS_CHILD | WS_VISIBLE,AFX_IDW_PANE_FIRST ))
      {
            TRACE0("Failed to create splitter window\n");
            return FALSE;
      }



      // Top splitter window
      if (!m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CParamView),
            CSize(0, 205), pContext)) //CSize(0, 400)
      {
            m_wndSplitter.DestroyWindow();
            return -1;
      }

      // Bottom splitter window
      if (!m_wndSplitter.CreateView(1,0,RUNTIME_CLASS(CViNView),//RUNTIME_CLASS(CViNView)
            CSize(0, 0), pContext)) //CSize(0, 0)
      {
            m_wndSplitter.DestroyWindow();
            return -1;
      }
      

      m_wndSplitter.RecalcLayout();

      m_wndSplitter.SetActivePane(1,0);
      

      // Set pointers to the two splitter pane frame windows

      m_pFormView= (CFrameWnd*)m_wndSplitter.GetPane(0,0);
      ASSERT(m_pFormView);
      m_pDrawingView = (CFrameWnd*)m_wndSplitter.GetPane(1,0);
      ASSERT(m_pDrawingView);

//by uncommenting this out then you create a view that allows active buttons
//but you will destroy your splitters
//      CFrameWnd::OnCreateClient(lpcs, pContext);
//      return CFrameWnd::OnCreateClient(lpcs, pContext);

      return TRUE;

The form view is created crectly
ASKER CERTIFIED SOLUTION
Avatar of waelothman
waelothman

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial