Using a CPropertySheet derived class as a view.
Neil A. Van Note -- vannote@netaxs.com
Tuesday, July 30, 1996
Environment: VC++ 4.2, WIn95/NT
Hello All,
I may have missed this, I have looked in the normal places for the info,
So forgive me if I am asking a stupid question.
I am trying to use a basic CPropertySheet/CProperyPage's class as a
CFormView
Without Success..., Is it possible? If so, is there an example out there
that I can go by?
Thanks,
Neil A. Van Note
vannote@netaxs.com
Mike Blaszczak -- mikeblas@nwlink.com
Sunday, August 04, 1996
[Mini-digest: 6 responses]
At 10:16 PM 7/30/96 -0400, you wrote:
>Environment: VC++ 4.2, WIn95/NT
>I may have missed this, I have looked in the normal places for the info,
What is your set of "normal places"?
>I am trying to use a basic CPropertySheet/CProperyPage's class as a
>CFormView
>Without Success..., Is it possible? If so, is there an example out there
>that I can go by?
There's an example right on the CD (which most people would call a "normal
place" to look for information). The sample is called SNAPVW. It puts
a property sheet in the client area of a view and then snaps and fixes
the size of the view to be appropriate for the sheet.
.B ekiM
http://www.nwlink.com/~mikeblas/
These words are my own. I do not speak on behalf of Microsoft.
-----From: "Gary Capps"
This isn't hard, but you'll need to take a somewhat different approach.
First, your CPropertySheet view should be derived from CScrollView, not
CFormView. In it, you need to declare a CPropertySheet *m_ptrSheet data
member. Set it to NULL in the ctor and delete it in the dtor. Now in it's
OnInitialUpdate() method, do this...
void CPropertySheetView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
if ( m_ptrSheet == NULL )
{
m_ptrSheet = new CPropertySheet( "PropSheet", this );
/////////////////
// add your property pages to m_ptrSheet here!
/////////////////
if ( m_ptrSheet->Create( this, WS_SYSMENU|WS_CHILD|WS_VISIBLE, 0 ))
{
CRect rectSheet;
m_ptrSheet->GetWindowRect( rectSheet );
ScreenToClient( rectSheet );
m_ptrSheet->MoveWindow( 0, 0, rectSheet.Width(),
rectSheet.Height() );
SetScrollSizes( MM_TEXT, CSize( rectSheet.Width(),
rectSheet.Height() ));
ResizeToFit();
}
}
}
You'll neet two other methods -- ResizeToFit() which can be used to size
the frame to fit exactly around the form. It looks like this...
void CPropertySheetView::ResizeToFit()
{
if ( m_ptrSheet && ::IsWindow( m_ptrSheet->GetSafeHwnd() ))
{
// adjust for toolbars et. al...
GetParentFrame()->RecalcLayout();
ResizeParentToFit( FALSE );
ResizeParentToFit( TRUE );
}
}
.....and the last one is OnErageBkGnd() which we override to prevent white
bands if the frame gets sized larger than the form....
BOOL CPropertySheetView::OnEraseBkgnd(CDC* pDC)
{
CRect rectClient;
GetClientRect( rectClient );
CBrush greyBrush, *poldBrush;
greyBrush.CreateSolidBrush( ::GetSysColor( COLOR_3DFACE ));
poldBrush = pDC->SelectObject( &greyBrush );
pDC->PatBlt( 0, 0, rectClient.Width(), rectClient.Height(), PATCOPY
);
pDC->SelectObject( poldBrush );
return TRUE;
}
That's it! Not bad, huh?
---
gc
Norman, Oklahoma
-----From: "Neil A. Van Note"
Never mind I found it in the new snapvw sample on the 4.2
Disk. Thanks...
Cheers,
Neil A. Van Note
vannote@netaxs.com
-----From: Erik Kuipers
Maybe you can look at the sample SNAPVW which is shipped with Visual C++
4.2. It is found under books on-line 'Samples\General MFC\SNAPVW'.
Greetings Erik
-----From: John Moulder
This question keeps on coming up...
Make the property sheet a modeless child window of the CView object. I do
this and it works fine.
I have developed an MDI property sheet. This is a modeless property sheet
that is a child window of a CView derived class in an MDI child window. The
window hierarchy is:
MDI child window
|
+ - AfxFrameOrView window (the view)
|
+ - Modeless Property sheet
|
+ - Tab control (to switch between pages)
| - Property page
| |
| + control(s) in each page
|
+ - Property page(s)...
class CMDIPropertySheetView : public CView
{
protected:
// property sheet
CMyPropertySheet m_PropSheet;
// pages for property sheet
CMyPageOne m_Page1;
CMyPageTwo m_Page2;
CMyPageThree m_Page3;
// etc
}
In my CPropertySheet derived class I reimplemented the RecalcLayout() to
resize the view owning the sheet to be just big enough to enclose the sheet.
The property sheet window is placed in the client area of the view window.
The reimplemented RecalcLayout() is called from the CPropertySheet::OnCreate().
I found that I had to reimplement the original CPropertySheet::OnCreate() to
do various things specific to my implementation.
When the CView window changes size (remember it is an MDI child window) I
resize the property sheet to fit the MDI child window (View).
My environment is windows 3.1, MSVC 1.5x, MFC 2.??, MFC CPropertySheet (16 bit).
Hope this helps.
-----From: Pete Chestna
I accomplished this by creating my own CScrollView derived class and then
created a modeless CPropertySheet. You just need to set the scroll sizes
properly.
BOOL BaseView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD
dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext*
pContext)
{
if (CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd,
nID, pContext))
{
RECT rectPropSheet;
CSize sizePropSheet;
m_pDoc = (EditorDoc *)pContext->m_pCurrentDoc;
// Set the background color to light gray
::SetClassLong(m_hWnd, GCL_HBRBACKGROUND,
(DWORD)::GetStockObject(LTGRAY_BRUSH));
m_pPropertySheet = CreatePropertySheet();
if (!m_pPropertySheet)
return FALSE;
m_pPropertySheet->Create(this, WS_VISIBLE | WS_CHILD, 0);
// Set the window position to the origin of the view but don't size it
m_pPropertySheet->SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
// The property sheet automatically sizes for the largest property page
// Get the size of the property sheet to set the scroll sizes
m_pPropertySheet->GetClientRect(&rectPropSheet);
// Determine the size of the property sheet
sizePropSheet.cx = rectPropSheet.right - rectPropSheet.left;
sizePropSheet.cy = rectPropSheet.bottom - rectPropSheet.top;
// Set the scroll sizes for the view
SetScrollSizes(MM_TEXT, sizePropSheet);
}
else
return FALSE;
return TRUE;
}
Pete
---
"To you -- is it movement or is it action? Peter J. Chestna
It is contact or just reaction? HighGround Systems
And you -- revolution or just resistance? PChestna@highground.com
Is it living, or just existence?" - RUSH (508) 263-5588 x.125
| Вернуться в корень Архива
|