Solved

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

Posted on 2003-11-02
6
383 Views
Last Modified: 2010-04-17
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.

0
Comment
Question by:ericcnc
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:waelothman
ID: 9704108
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
0
 

Author Comment

by:ericcnc
ID: 9707663
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();

0
 
LVL 5

Expert Comment

by:waelothman
ID: 9708413
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
0
 

Author Comment

by:ericcnc
ID: 9711426
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
0
 
LVL 5

Accepted Solution

by:
waelothman earned 250 total points
ID: 9711612
oh sorry you was talking about the duisable in the toolbar i thought you talk about the form elemts
yes i agree with you in that but the only way to solve this problem is to handel the toolbar message in the main frame not in the view it self and the let this function to call any function you want in the view as

((CViNView*)m_Split.GetPane(0,1))->DoMyFunction();

when the function handel in the main frame it will be independant on active view so the toolbar button will be always on
i hope ypu understand me
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This is about my first experience with programming Arduino.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

706 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

17 Experts available now in Live!

Get 1:1 Help Now