Solved

Splitter Wnd in a Dialog Box

Posted on 1997-06-25
8
970 Views
Last Modified: 2013-11-19
I am trying to create a splitter window in side a dialog box. If somebody has ever done please guide me with any working examples.My splitter will have three panes and dialog box will have sizing capabilities. "Splitter INSIDE Dialog"
0
Comment
Question by:abhijit062597
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 1

Expert Comment

by:alechko
Comment Utility
do you want to place a dialog box into one of the spliters windows or make a splitter on the dialog box ???

0
 

Author Comment

by:abhijit062597
Comment Utility
Edited text of question
0
 
LVL 4

Expert Comment

by:mbhakta
Comment Utility
Splitter windows have been specifically designed for the CView based classes. There has been no effort from Microsoft to convert it for any CDialog or CPropertyPage classes. The documentation strongly states its use only with reference to views.

However, though it is difficult for me to talk about your user interface without looking at it . Here are two issues to think about  -
- Do you really want a splitter window. Can't you substitute it with property pages or tab controls ?
- Is it possible for you to make your dialog box into a CFormview based class and display it as a view ?



0
 
LVL 1

Expert Comment

by:MarkusLoibl
Comment Utility
I have some code that can help you, but it is not all so easy. You have to override a CSplitterWnd-class in order to solve your problem. Then, you have a splitter in a dialog, but WITHOUT a document (Perhaps you can get you doc with some Afx...-functions, but I haven't tried).
If you want the code, reject the answer but increase the points (I think about 150).
But for 30 pts, mbhakta's answer is excellent...

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 4

Expert Comment

by:mbhakta
Comment Utility
I think MarkusLoibl should ask for more points. I recommend he should be given 150 points and a A grade for the source code. That makes it 600 points.
0
 

Author Comment

by:abhijit062597
Comment Utility
Adjusted points to 150
0
 
LVL 1

Expert Comment

by:MarkusLoibl
Comment Utility
If you want my answer, you first have to reject mbhakta's answer...
0
 
LVL 1

Accepted Solution

by:
MarkusLoibl earned 150 total points
Comment Utility
1. Use your own Splitter-Class, derived from CSplitterWnd
2. Use this class in your About-box.
3. Use the WM_MOUSEACTIVATE-handler OnMouseActivate() and add some lines.
   You can do this in all your view-classes, or do it in your own
   base-view-class from which you derive your other viewe classes.

I used the following code, and it seems to work:

1.
---------

class CMySplitterWnd : public CSplitterWnd
{
public:
CMySplitterWnd();
virtual ~CMySplitterWnd();
DECLARE_DYNCREATE(CMySplitterWnd)

void SetActivePane(int row, int col, CWnd* pWnd);

//{{AFX_VIRTUAL(CMySplitterWnd)
protected:
//}}AFX_VIRTUAL

//{{AFX_MSG(CMySplitterWnd)
afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()

};


IMPLEMENT_DYNCREATE(CMySplitterWnd, CSplitterWnd)

CMySplitterWnd::CMySplitterWnd()
: CSplitterWnd()
{
}

CMySplitterWnd::~CMySplitterWnd()
{
}

BEGIN_MESSAGE_MAP(CMySplitterWnd, CSplitterWnd)
//{{AFX_MSG_MAP(CMySplitterWnd)
ON_WM_MOUSEACTIVATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()


int CMySplitterWnd::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
{
DWORD pos;
CPoint posMouse;
int r, rows,
c, cols;
CWnd *pPane;
CRect wndRect;

pos = GetMessagePos();
posMouse = CPoint( LOWORD(pos), HIWORD(pos) ); // in Scrten coordinates
rows = GetRowCount();
cols = GetColumnCount();

for( r=0 ; r<rows ; r++ )
{
for( c=0 ; c<rows ; c++ )
{
pPane = GetPane(r, c);
pPane->GetWindowRect(&wndRect); // also in screen
// is Mouse-Position inside pane?
if( (wndRect.left<=posMouse.x) && (posMouse.x<=wndRect.right) &&
(wndRect.top<=posMouse.y) && (posMouse.y<=wndRect.bottom) )
{
// correct pane !
SetActivePane(r, c, NULL);
return MA_NOACTIVATE;
}
}
}

return CSplitterWnd::OnMouseActivate(pDesktopWnd, nHitTest, message);
}

void CMySplitterWnd::SetActivePane(int row, int col, CWnd* pWnd)
{
// set the focus to the pane
CWnd* pPane = pWnd == NULL ? GetPane(row, col) : pWnd;
pPane->SetFocus();
}


2.
---------
- in the definition of CAboutDlg

CMySplitterWnd *m_pSplitter; // instead of CMySplitterWnd

- in CAboutDlg::CAboutDlg()
m_pSplitter = NULL;

- in CAboutDlg::~CAboutDlg()
delete m_pSplitter;

- and in OnInitDialog():

CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();

m_pSplitter = new CMySplitterWnd();

m_pSplitter->CreateStatic(this, 1, 2, WS_CHILD | WS_VISIBLE ); //, &context, WS_CHILD | WS_VISIBLE |WS_HSCROLL | WS_VSCROLL | SPLS_DYNAMIC_SPLIT);
m_pSplitter->CreateView(0, 0, RUNTIME_CLASS(CView1),CSize(50, 50), NULL );
m_pSplitter->CreateView(0, 1, RUNTIME_CLASS(CViewTree1),CSize(50, 50), NULL );

m_pSplitter->MoveWindow(1, 1, 100, 100);
m_pSplitter->ShowWindow(SW_SHOW);

return TRUE;
}

3.
---------
I give you the both view-classes:

class CView1 : public CView
{
protected:
CView1();
virtual ~CView1();
DECLARE_DYNCREATE(CView1)

//{{AFX_VIRTUAL(CView1)
protected:
virtual void OnDraw(CDC* pDC);
//}}AFX_VIRTUAL

//{{AFX_MSG(CView1)
afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
class CViewTree1 : public CTreeView
{
protected:
CViewTree1();
virtual ~CViewTree1();
DECLARE_DYNCREATE(CViewTree1)


//{{AFX_VIRTUAL(CViewTree1)
protected:
//}}AFX_VIRTUAL

protected:
//{{AFX_MSG(CViewTree1)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
IMPLEMENT_DYNCREATE(CView1, CView)

CView1::CView1() {}
CView1::~CView1() {}

BEGIN_MESSAGE_MAP(CView1, CView)
//{{AFX_MSG_MAP(CView1)
ON_WM_MOUSEMOVE()
ON_WM_MOUSEACTIVATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CView1::OnDraw(CDC* pDC)
{
CPoint pointCursor;
char text[100];
GetCursorPos( &pointCursor );
sprintf(text, "Mouse=%3d, %3d ", pointCursor.x, pointCursor.y);
pDC->TextOut(5, 15, text, strlen(text));
}

int CView1::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
{
// also possible: if( ! pDesktopWnd->IsKindOf(RUNTIME_CLASS(CFrameWnd)))
if( pDesktopWnd->IsKindOf(RUNTIME_CLASS(CDialog)))
return CWnd::OnMouseActivate(pDesktopWnd, nHitTest, message);
else return CView::OnMouseActivate(pDesktopWnd, nHitTest, message);
}

void CView1::OnMouseMove(UINT nFlags, CPoint point)
{
Invalidate();
}




IMPLEMENT_DYNCREATE(CViewTree1, CTreeView)

CViewTree1::CViewTree1() {}
CViewTree1::~CViewTree1() {}

BEGIN_MESSAGE_MAP(CViewTree1, CTreeView)
//{{AFX_MSG_MAP(CViewTree1)
ON_WM_CREATE()
ON_WM_MOUSEACTIVATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

int CViewTree1::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CTreeView::OnCreate(lpCreateStruct) == -1)
return -1;

return 0;
}

int CViewTree1::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
{
// also possible: if( ! pDesktopWnd->IsKindOf(RUNTIME_CLASS(CFrameWnd)))
if( pDesktopWnd->IsKindOf(RUNTIME_CLASS(CDialog)))
return CWnd::OnMouseActivate(pDesktopWnd, nHitTest, message);
else return CTreeView::OnMouseActivate(pDesktopWnd, nHitTest, message);
}
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 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

9 Experts available now in Live!

Get 1:1 Help Now