• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1048
  • Last Modified:

Splitter Wnd in a Dialog Box

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
abhijit062597
Asked:
abhijit062597
  • 3
  • 2
  • 2
  • +1
1 Solution
 
alechkoCommented:
do you want to place a dialog box into one of the spliters windows or make a splitter on the dialog box ???

0
 
abhijit062597Author Commented:
Edited text of question
0
 
mbhaktaCommented:
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
MarkusLoiblCommented:
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
 
mbhaktaCommented:
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
 
abhijit062597Author Commented:
Adjusted points to 150
0
 
MarkusLoiblCommented:
If you want my answer, you first have to reject mbhakta's answer...
0
 
MarkusLoiblCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now