Q: How to get tab pages in a splitter view?
Stracka -- stracka@inet.dpt.com
Friday, April 05, 1996
WIN95 / VC4.0 / MFC4.0
Here's the scoop:
I've got a CFrameWnd derived main window. I've split it in two with a
static splitter. Both the left and right splitter panes are CView
derived views. I've got a tree control showing a hierarchy of devices
in the left hand pane. In the right hand pane, I'd LIKE to show
device info for the currently selected device using property sheet
style tab pages.
Problem is, the only way I can get a property sheet on my screen is
inside of a dialog box. Should I be trying to embed a dialog box in
the view for my right hand pane, or should I paste together a tab
control and some dialog templates on my own?
Either way, I could really use a push in the right direction. I'm
really hoping somebody tells me what a silly question this is, along
with its easy solution...
Mark Stracka
Distributed Processing Technologies
SteveN -- steven@primenet.com
Sunday, April 07, 1996
[Mini-digest: 2 responses]
> WIN95 / VC4.0 / MFC4.0
>
> Here's the scoop:
>
> I've got a CFrameWnd derived main window. I've split it in two with a
> static splitter. Both the left and right splitter panes are CView
> derived views. I've got a tree control showing a hierarchy of devices
> in the left hand pane. In the right hand pane, I'd LIKE to show
> device info for the currently selected device using property sheet
> style tab pages.
>
> Problem is, the only way I can get a property sheet on my screen is
> inside of a dialog box. Should I be trying to embed a dialog box in
> the view for my right hand pane, or should I paste together a tab
> control and some dialog templates on my own?
>
> Either way, I could really use a push in the right direction. I'm
> really hoping somebody tells me what a silly question this is, along
> with its easy solution...
>
> Mark Stracka
> Distributed Processing Technologies
>
Here's the *basic* steps you need to do that:
1) Create a new object derived from CPropertySheet
2) Create a new object derived from CView (I use Class Wiz for
the first two steps, it's really easy)
3) In MyView::OnInitialUpdate(), add:
m_Sheet = new MySheet("MySheet", this);
m_Page1 = new _Page1;
m_Page2 = new _Page2;
m_Sheet->AddPage(m_Page1);
m_Sheet->AddPage(m_Page2);
m_Sheet->Create(blah, blah, blah...
4) In MyView::OnSize() add:
RECT rect;
GetClientRect(&rect);
if(m_Sheet != NULL)
m_Sheet->MoveWindow(&rect,TRUE);
5) In MyView::OnDestroy() add:
delete m_Page1;
delete m_Page2;
delete m_Sheet;
6) In CMainFrame::OnCreateClient() add:
m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(MyView), CSize(0, 0), pContext);
...which, of course, creates a property page view
("CPropertySheetView"?!?) with all the tabs resized to fit the right
side of your CFrameWnd splitter.
Also, you'll need to add the right stuff to your header
files, etc. Additionally, you'll need to implement a
CMainFrame::ReplaceSplitterView() if you want different property
sheets to appear based on user input. I have this if you need it - I
think I hacked it from a tech note somewhere. It basically plays with
GetActiveDocument(), GetActiveView(), and CreateView().
Don't forget to do the dialog templates as usual for a property
sheet. There's some special setting for those, too (Child, thin
border, no system menu). If I'm being too vague (not on purpose)
email me for clarification.
Hope this helps.
-Steve
///////////////////////////////////////////////////////
// steven@primenet.com
// http://www.primenet.com/~steven/
// Vista Software Tucson, AZ
-----From: Chet Murphy
Mark,
I'm doing something similar. However, I'm using DialogBars rather than
a splitter window. I use a DialogBar for my tree view which is
separated from my main window and another DiralogBar with a splitter
bar. In your case you could use two dialog bars with an optional
splitter bar in between.
BTW: The splitter bar is not a standard MFC class. My splitter bar has
the following interface:
class CSplitterBar : public CControlBar
{
DECLARE_DYNAMIC(CSplitterBar)
// Construction
public:
CSplitterBar();
BOOL Create(CMainFrame* pParentWnd, CControlBar* barToSize, BOOL vertical, UINT id);
// Attributes
public:
// Operations
public:
virtual CSize CalcFixedLayout(BOOL bStretch, BOOL bHorz);
virtual CSize CalcDynamicLayout(int nLength, DWORD dwMode);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSplitterBar)
public:
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CSplitterBar();
virtual void OnUpdateCmdUI(class CFrameWnd *,int);
void SetSplitCursor();
BOOL HitTest(CPoint pt);
CControlBar* GetClientToResize() { return m_BarToSize;}
BOOL IsVertical() {return m_VerticalSeparator;}
// Generated message map functions
protected:
CMainFrame* m_MainFrame;
BOOL m_VerticalSeparator;
CControlBar* m_BarToSize;
//{{AFX_MSG(CSplitterBar)
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
afx_msg void OnMouseMove(UINT nFlags, CPoint pt);
afx_msg void OnPaint();
afx_msg void OnLButtonDown(UINT nFlags, CPoint pt);
afx_msg void OnLButtonUp(UINT nFlags, CPoint pt);
afx_msg void OnCancelMode();
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnWindowPosChanging(LPWINDOWPOS);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
To make the splitter bar work I also had to add the following methods to my main frame
window:
void StartTracking(CSplitterBar* splitterBar);
void StopTracking();
void OnInvertTracker(const CRect& rect);
--Chet Murphy
ModelWorks Software
cmurphy@modelworks.com
http://www.modelworks.com/express
David W. Gillett -- DGILLETT@expertedge.com
Monday, April 08, 1996
[Mini-digest: 2 responses]
> I've got a CFrameWnd derived main window. I've split it in two with a
> static splitter. Both the left and right splitter panes are CView
> derived views. I've got a tree control showing a hierarchy of devices
> in the left hand pane. In the right hand pane, I'd LIKE to show
> device info for the currently selected device using property sheet
> style tab pages.
>
> Problem is, the only way I can get a property sheet on my screen is
> inside of a dialog box. Should I be trying to embed a dialog box in
> the view for my right hand pane, or should I paste together a tab
> control and some dialog templates on my own?
My inclination is to use a CDialogView for the right pane, and
subclass CPropertySheet to make a (modeless) child of the view. Your
CPropertyPage objects can also be data members of the view, so your
view can easily link controls on the pages to data in the document.
[The derived class from CPropertyPage is so you can override its
styles. You want to remove the border and caption, and add at least
DS_CONTROL and maybe WS_EX_CONTROLPARENT. Both the CDialogView and
the CPropertySheet derivative should be resized to fit the splitter;
you might want to enforce the initial size of the CPropertySheet as a
minimum....]
Dave
-----From: John Moulder
I understand what you would like to achieve; it seems a reasonable requirement.
Putting together your own tabs controls and pseudo property sheet pages
seems like hard work, and too much like a property sheet - why reinvent the
wheel?
How about using a modeless dialog box / property sheet? Since its modelss,
you can switch to the list window and back to the property sheet at will,
but you retain the precooked functionality of the property sheet.
Hope this helps.
John
| Вернуться в корень Архива
|