CPropertySheet in as a control
Dan Edwards -- dedwards@silvercrk.com
Sunday, October 13, 1996
Environment: VC 4.2b, Win95, WinNT
Is there any way to use CPropertySheet/CPropertyPage on a CFormView? Right
now I am useing a CTabCtrl and basically redoing all that CProperty* does.
Why? Is there a way to get it on a dialog????? I've searched and searched
and can't believe I haven't found anything on it.
Thanks
Dan
Svetlana Guljajeva -- svetlana@assert.ee
Monday, October 14, 1996
[Mini-digest: 6 responses]
> Environment: VC 4.2b, Win95, WinNT
>
>Is there any way to use CPropertySheet/CPropertyPage on a CFormView? Right
>now I am useing a CTabCtrl and basically redoing all that CProperty* does.
>Why? Is there a way to get it on a dialog????? I've searched and searched
>and can't believe I haven't found anything on it.
>
>Thanks
>Dan
Create your own class,derived from CPropertySheet and write your own Create
function ( or override the existing one).I usually do the following way:
class CMySheet:public CPropertySheet
{
...
BOOL Create(CWnd * pParentWnd , int x,int y);
...
}
Actually I does nothing here,but this from of Create funtion is much more
convinient to call.And besides,you can add some functionality to your class.
BOOL CMySheet::Create(CWnd* pParentWnd,int x,int y)
{
BOOL bOK =
CPropertySheet::Create(pParentWnd,WS_SYSMENU|WS_CHILD|WS_VISIBLE,0);
return bOK;
}
And here I use my sheet:
{
...
//m_pMySheet is a member variable
m_pMySheet = new CMySheet("",this);
CPropertyPage * pPage = new CPropertyPage(IDD_MY_PAGE);
CPropertyPage * pPage2 = new CPropertyPage(IDD_MY_PAGE2);
m_pMySheet->AddPage(pPage);
m_pMySheet->AddPage(pPage2);
m_pMySheet->Create(this,100,100);
...
}
IDD_* are ID of resourse(dialog) templates for pages.
Hope this helps you!
Regards,
Svetlana Guljajeva
**svetlana@assert.ee**
-----From: Andi Giri
Embedding a CPropertySheet object in a CView derived object has been
dealt with in the book,Visual C++ 4 MasterClass, by WROX Press. The
authors have derived a CPropSheetExtended class from CPropertySheet,
derived CPropSheetGeneral from that, and have a pointer
(m_pPSExample1View) to an object of that type as a member of the
CFormView-derived class (CPropSheetView). The OnCreate() and
OnInitialUpdate() handlers of CPropSheetView have been overridden.
Embedding in a dialog is also dealt with. has been dealt with in the
book,Visual C++ 4 MasterClass, by WROX Press. The authors have a
CDialogExtension class derived from CDialog, where they embed a property
page.
Some code follows:
View.h:
View.cpp:-
int CPropSheetView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
TRACE("[%s - %d] - CPropSheetView::OnCreate().....\n", __FILE__,
__LINE__);
if (CFormView::OnCreate(lpCreateStruct) == -1)
return -1;
// Create the modeless property sheet. You should add the
// property pages before creating the property sheet
ASSERT(m_pPSExample1View);
m_pPSExample1View->AddPage(&m_ViewGeneralPage);
m_pPSExample1View->AddPage(&m_ViewDebugPage);
m_pPSExample1View->AddPage(&m_ViewCplusPage);
if (!m_pPSExample1View->Create(this, WS_SYSMENU | WS_CHILD |
WS_VISIBLE, 0))
{
return -1;
}
m_pPSExample1View->SetImageList(IDB_TVBMPIMG, 16, 1, RGB(255,0,0));
CRect rectSheet, rectWindow;
m_pPSExample1View->GetWindowRect(rectSheet);
rectWindow = rectSheet;
CalcWindowRect(rectWindow);
// Adjust the positions of the frame and property sheet
SetWindowPos(NULL, rectWindow.left,rectWindow.top, rectWindow.Width()
+ 10,
rectWindow.Height(), SWP_NOZORDER | SWP_NOACTIVATE);
m_pPSExample1View->SetWindowPos(NULL, 0, 0 ,rectSheet.Width(),
rectSheet.Height(), SWP_NOZORDER | SWP_NOACTIVATE);
return 0;
}
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
void CPropSheetView::OnInitialUpdate()
{
TRACE("[%s - %d] - CPropSheetView::OnInitialUpdate().....\n",
__FILE__, __LINE__);
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit(FALSE);
ResizeParentToFit(TRUE);
}
-----From: "Shrikanth Swaminathan"
it is very simple really, try the following...
hope it helps ...
sshri@csi-gmbh.de
class CTabsView : public CFormView
{
protected: // create from serialization only
CFUNDWSheet* m_pSheet;
CTabsView();
DECLARE_DYNCREATE(CTabsView)
public:
//{{AFX_DATA(CTabsView)
// enum{ IDD = IDD_CSIW_FORM };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTabsView)
public:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// SHR virtual void OnPrint(CDC* pDC, CPrintInfo*);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CTabsView();
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CTabsView)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnDestroy();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//----------------------------------------------------------------------
int CTabsView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CCsiTabsView::OnCreate(lpCreateStruct) == -1)
return -1;
m_pSheet = new CFUNDWSheet(this);
if (!m_pSheet->Create(this, WS_CHILD | WS_VISIBLE, 0))
{
delete m_pSheet;
m_pSheet = NULL;
return -1;
}
m_pSheet->SetWindowPos(NULL, 0, 0, NULL, NULL,
SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_SHOWWINDOW );
return 0;
}
//----------------------------------------------------------------------
void CTabsView::OnDestroy()
{
if (m_pSheet != NULL)
{
m_pSheet->DestroyWindow();
}
CCsiTabsView::OnDestroy();
return;
}
//----------------------------------------------------------------------
-----From: ted r lowe
In view.h:
CPropertySheet *m_pSheet;
In view's oninitialupdate function:
CRect pgr( 0, 0, 200, 200 );
m_pSheet = new CSheet( pgr );
// do addpage() for each property page
m_pSheet->Create( this, WS_SYSMENU|WS_CHILD|WS_VISIBLE, 0 );
Good luck!
---
ted r lowe - trl@tdata.com - Teledata Solutions, Inc.
-----From: Chris Scott
If you want to use a tab control on a dialog/formview, check out the web
site listed in my signature and go to the "Visual C++" section. Here I
supply classes (originally posted to CompuServe by Jeremy Glick, but since
modified) that make it fairly painless to setup tabs in a dialog. The
class used for the Pages is derived from CPropertyPage and can be used on a
Tab Control or on a CPropertySheet.
I am assuming you have a good understanding of MFC. I am also assuming that
you are using VC++ 4.x - otherwise, ignore this post.
--
- Chris Scott
- http://ourworld.compuserve.com/homepages/lurker
-----From: Doug Reese
My project does this. Here are some code snippets:
In my CFormView derived class:
Add members for your derived CPropertySheet object (CClientSheet) and your
CPropertyPage derived objects (CPage...). Memory allocated in
CClientView::CClientView().
class CClientView : public CScrollView
{
protected:
CClientView();
DECLARE_DYNCREATE(CClientView)
public:
CClientSheet* m_pClientSheet;
CPagePersonal* m_pPagePersonal;
CPageAddress* m_pPageAddress;
...
};
Add pages to sheet in OnInitialUpdate() and create the property sheet:
void CClientView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
// add pages to property sheet
m_pClientSheet->AddPage(m_pPagePersonal);
m_pClientSheet->AddPage(m_pPageAddress);
// create sheet and put in upper left corner of window
m_pClientSheet->Create(this, WS_SYSMENU | WS_VISIBLE | WS_CHILD, NULL);
m_pClientSheet->GetClientRect(&rect);
m_pClientSheet->MoveWindow(rect, TRUE);
// size frame to dialog size
m_pClientSheet->GetWindowRect(&rect);
SetScrollSizes(MM_TEXT, rect.Size());
ResizeParentToFit(FALSE);
}
This creates a modeless property sheet, so you need to increase the height
of your CPropertySheet derived class (mine is CClientSheet) and add the
buttons yourself:
BOOL CClientSheet::OnInitDialog()
{
CPropertySheet::OnInitDialog();
// get window coordinates (relative to screen)
CRect rect;
GetWindowRect(&rect);
// increase height by 30
rect.bottom += 30;
// resize property sheet
MoveWindow(rect);
// convert to client coordinates
ScreenToClient(rect);
rect.SetRect(0, 0, rect.Width(), rect.Height());
CreateButtons(rect);
return TRUE;
}
Helper function to create the buttons (m_btnSave and other buttons are of
type CButton):
void CClientSheet::CreateButtons(CRect& rect)
{
// get font size being used by dialog
CFont* pfont = GetFont();
LOGFONT lf;
pfont->GetLogFont(&lf);
if (lf.lfWeight != 400)
{
m_dlgFont = new CFont;
pfont = m_dlgFont;
if (!pfont->CreateFontIndirect(&lf))
{
AfxMessageBox("Could not create font needed for buttons");
}
}
// if font weight == 700, running under Win 3.1
// need to make buttons a little wider to accomadate
// bold fonts
int btnwidth = lf.lfWeight == 700 ? 90 : 80;
int btnheight = 25;
int inbetween = 5;
CRect btnrect;
// calc position of add button
btnrect.left = rect.left + 2 * inbetween;
btnrect.right = btnrect.left + btnwidth;
btnrect.bottom = rect.bottom - 5;
btnrect.top = btnrect.bottom - btnheight;
// create add button
m_btnAdd.Create("&Add", WS_CHILD | WS_VISIBLE | WS_TABSTOP,
btnrect, this, IDC_ADDBUTTON);
// set button fonts to same font as property sheet
m_btnSave.SetFont(pfont, FALSE);
[additional buttons left out - change left and right values of btnrect and
call Create for each one...]
}
I also didn't want the window to be resizable minimizable or maximizable, so
in my CFrameWnd derived class (mine is actually derived from CMDIChildWnd):
BOOL CClientFrame::PreCreateWindow(CREATESTRUCT& cs)
{
// modify style of window frame
cs.style &= ~WS_MAXIMIZEBOX; // no maximize button
cs.style &= ~WS_MINIMIZEBOX; // no minimize button
cs.style &= ~WS_THICKFRAME; // not resizable
cs.style &= ~(LONG)FWS_ADDTOTITLE; // allow changes to window title
return CMDIChildWnd::PreCreateWindow(cs);
}
That should do it, I hope I haven't left something out. There may be a
better way of accomplishing this, but the above works in my app. I'd be
open to suggestions/improvements.
Doug
------------------------------------------------------------------
Doug Reese
dreese@cts.com
Day gig: http://www.viewplan.com/
Night gig: http://www.users.cts.com/crash/d/dreese/rplayground.htm
(caffeine donations accepted)
Luke Stephens -- luker@tfs.net
Monday, October 14, 1996
[Mini-digest: 2 responses]
Check out the SnapVw example on the VC CD-ROM.
It's located on msdev\samples\mfc\general. I think it's what
you're looking for.
Luke Stephens
----------
> From: Dan Edwards
> To: mfc-l@netcom.com
> Subject: CPropertySheet in as a control
> Date: Sunday, October 13, 1996 10:16 PM
>
>
>
> Environment: VC 4.2b, Win95, WinNT
>
> Is there any way to use CPropertySheet/CPropertyPage on a CFormView?
Right
> now I am useing a CTabCtrl and basically redoing all that CProperty*
does.
> Why? Is there a way to get it on a dialog????? I've searched and searched
> and can't believe I haven't found anything on it.
>
> Thanks
> Dan
>
>
-----From: Rogas
I got this problem two weeks ago and I got help from Bruce Miller
(thanks!). I had to put CPropertySheet on a CDialog. Here's the code:
CNiveauChargementDialog::CNiveauChargementDialog(CWnd* pParent *=NULL*/)
: CDialog(CNiveauChargementDialog::IDD, pParent)
{
m_PSheet = new CNiveauChargementPSheet("Sheet", this);
}
CNiveauChargementDialog::~CNiveauChargementDialog()
{
delete m_PSheet;
}
BOOL CNiveauChargementDialog::OnInitDialog()
{
CDialog::OnInitDialog();
m_PSheet->AddPage(&m_Vent);
m_PSheet->AddPage(&m_Autres);
CRect rectPSheet;
m_PSheet->Create(this, WS_CHILD | WS_VISIBLE );
m_PSheet->GetClientRect(&rectPSheet);
m_PSheet->MoveWindow(7,
24,
rectPSheet.right,
rectPSheet.bottom,
FALSE);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a
control
// EXCEPTION: OCX Property Pages should return
FALSE
}
REMEMBER to put in CPropertySheet::OnInitDialog the following:
BOOL CNiveauChargementPSheet::OnInitDialog()
{
ModifyStyleEx (0, WS_EX_CONTROLPARENT);
return CPropertySheet::OnInitDialog();
}
in other case it won't work.
Rogas
| Вернуться в корень Архива
|