Solved

Splitter Wnd in a Dialog Box

Posted on 1997-06-25
8
996 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
ID: 1302302
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
ID: 1302303
Edited text of question
0
 
LVL 4

Expert Comment

by:mbhakta
ID: 1302304
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:MarkusLoibl
ID: 1302305
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
 
LVL 4

Expert Comment

by:mbhakta
ID: 1302306
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
ID: 1302307
Adjusted points to 150
0
 
LVL 1

Expert Comment

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

Accepted Solution

by:
MarkusLoibl earned 150 total points
ID: 1302309
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

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
repeatSeparator  java  challenge 13 58
substring method in java 1 136
method notes when mouse over in eclipse 5 90
NotAlone Challenge 20 88
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.

749 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