-
[MFC] DDX/DDV and DoDataExchange between nested PropertySheets
Hello everyone!!!!
I have a nested propertysheets (on some propertypages I have another propertysheet with pages itself). I have also a XML file of general settings that I read in OnInitDialog()'s form event.
Some pages of this nested propertysheets have settings that depends from other pages and of general settings from xml file. Like if I activate a checkbox in a page I change in the xml file the related value from 0 to 1 and in the same time I enable the controls in another page.
I know there's a way to communicate between propertypages from the top (the dialog form) so it can share also xml file object maybe using DoDataExchange to reduce complexity.
But how I can do that?... I tried to read the help of MSDN but it's like messing me a bit so I'm here asking you...
Thanks to all.
Ciao
Luigi
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
Have a look at this discussion
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
Here's a similar concept of using a 'document' in a property sheet:
http://www.codeguru.com/forum/showth...=442853&page=2
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
Quote:
Originally Posted by
Arjay
Hello arjay,
I find your methodology interesting and also elegant.... document and view....
Just three little questions:
1) Since as dialog, I'm using a dialog resource where I add a menu, coding like this:
CPropSheet Sheet(_T("Main Sheet"));
would assume there's a m_pMainWnd variable to pass &Sheet. In this case I have m_hWnd since it's a dialog resource...how I can "put" the sheet on it?.
2) Are there attributes to tell the sheet I don't want those buttons at bottom (Ok, Cancel, Apply, ?)?
3) If I have nested sheets, shall I have maybe to pass to deeper views also the top sheet pointer?... I mean, if I have at top sheet this:
AddPage(&FirstTopTab_View);
in the OnInitDialog() of FirstTopTab_View when I code:
CSecondLevelSheet SecondLevelSheet(_T("Second Level Sheet"));
for the Page of that SecondLevelSheet I shall pass also the pointer of topsheet like:
AddPage(&SecondLevelFirstTab_View(Sheet));
so in the ctor of SecondLevelFirstTab_View I can have something like:
CSecondLevelFirstTab_View::CSecondLevelFirstTab_View(CPropSheet* mainsheet, CSecondLevelSheet* parentsheet);
right?... Or doesn't it need?
Thanks
ciao
Luigi
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
Quote:
Originally Posted by
npuleio
1) Since as dialog, I'm using a dialog resource where I add a menu, coding like this:
Code:
CPropSheet Sheet(_T("Main Sheet"));
would assume there's a m_pMainWnd variable to pass &Sheet. In this case I have m_hWnd since it's a dialog resource...how I can "put" the sheet on it?.
2) Are there attributes to tell the sheet I don't want those buttons at bottom (Ok, Cancel, Apply, ?)?
1) I don't see anything that looks like a "menu" in the "code snippet" you have posted. :confused:
2) These buttons have control IDs: IDOK, IDCANCEL, ID_APPLY_NOW. So you won't have any problem to hide the controls with those IDs.
Additional info you could find in:
HOWTO: How to Change Default Button on CPropertySheet
HOWTO: How to Hide the Apply Button in CPropertySheet
How To Create a Modeless CPropertySheet with Standard Buttons
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
Hello VictorN,
1) I mean I call the propertysheet from a CDialog window because on this CDialog I put a menu...and since the dialog isn't a CWinApp I can't do like this:
CPropSheet sheet( _T("This is a property sheet") );
m_pMainWnd = &sheet;
INT_PTR nResponse = sheet.DoModal();
because CDialog doesn't have m_pMainWnd....so I have to put the propertysheet in the "content" of CDialog otherwise it would appear as two separate windows...
2) doesn't exists any PSH_NOblahblah flag to hide IDOK, IDCANCEL and IDHELP like that PSH_NOAPPLYNOW?...
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
Quote:
Originally Posted by
npuleio
Hello VictorN,
1) I mean I call the propertysheet from a CDialog window because on this CDialog I put a menu...and since the dialog isn't a CWinApp I can't do like this:
CPropSheet sheet( _T("This is a property sheet") );
m_pMainWnd = &sheet;
INT_PTR nResponse = sheet.DoModal();
because CDialog doesn't have m_pMainWnd....so I have to put the propertysheet in the "content" of CDialog otherwise it would appear as two separate windows...
WEll, you don't need to (and you must not) assign your propertysheet pointer to m_pMainWnd if the propertysheet is NOT a main window. The Framework does use such an assignment for cleanup and only for the main App window.
On the other hand you could redesign you App using the propertysheet as the main window (instead of a child window of a "default" dialog) or you could place the propertysheet on the main dialog as the child modeless window.
Quote:
Originally Posted by
npuleio
2) doesn't exists any PSH_NOblahblah flag to hide IDOK, IDCANCEL and IDHELP like that PSH_NOAPPLYNOW?...
Hmm... Why do you need all these PSH_NO...? :confused:
What is wrong for you just to write:
Code:
GetDlgItem(IDOK)->ShowWindow(SW_HIDE);
GetDlgItem(IDCANCEL)->ShowWindow(SW_HIDE);
GetDlgItem(ID_APPLY_NOW)->ShowWindow(SW_HIDE);
Or you could use modeless propertysheet rather than the modal one - in this case all these button would be hidden by Framework.
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
The matter is in fact
GetDlgItem(IDOK)->ShowWindow(SW_HIDE);
doesn't work here probably because for a conflict using a propertysheet as modal and trying to use it as modeless..
I was thinking about modal propertysheet following Arjay's example to manage "pages" as document/views to pass informations between pages...
the point I don't know if Document/View methodology would be applied to modeless propertysheet/pages....
Having in fact modeless windows (presence of CDialog) makes me a bit confusing about Document/View idea...
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
Quote:
Originally Posted by
npuleio
The matter is in fact
GetDlgItem(IDOK)->ShowWindow(SW_HIDE);
doesn't work here probably because for a conflict using a propertysheet as modal and trying to use it as modeless...
1. Define "doesn't work".
2. Where are you calling this line from?
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
Hello VictorN,
since I was calling PropertySheet class from CDialog due to "insert inside" if I put GetDlgItem(IDOK)->ShowWindow(SW_HIDE); in the PropertySheet's ctor or also right after declared it returned a severe error that interrupted running.
At least now I'm trying to remove PropertySheet class and use instead a PropertySheet object (the modeless way) and actually I'm trying to set the OnWindowPosChanged correctly to resize the PropertySheet inside the client rect.
But if I do:
this->GetClientRect( &clientrect );
CTabCtrl* poControl = m_pPropertySheet->GetTabControl();
poControl->SetWindowPos(&CWnd::wndBottom, 0, 0,
clientrect.right - 10, clientrect.bottom - 15, SWP_NOMOVE | SWP_NOZORDER);
m_pPropertySheet->SetWindowPos(&CWnd::wndBottom, 0, 0,
clientrect.right - 10, clientrect.bottom - 15, SWP_NOMOVE | SWP_NOZORDER);
I can't see right and bottom borders... :-/
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
Quote:
Originally Posted by
npuleio
Hello VictorN,
since I was calling PropertySheet class from CDialog due to "insert inside" if I put GetDlgItem(IDOK)->ShowWindow(SW_HIDE); in the PropertySheet's ctor or also right after declared it returned a severe error that interrupted running.
You may not:
a) accessing modal PropertySheet class controls from the outside the PropertySheet class;
b) accessing PropertySheet class controls until there have been created (they are created during the CPropertySheet::OnInitDialog() call)
So what you should do is:
- implement (override) CPropertySheet::OnInitDialog() method
- somewhere after CPropertySheet::OnInitDialog() call place these line to hide OK, Cancel, Apply controls
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
Well....as I said now I am calling PropertySheet modelessly...
but still I have difficulties to resize correctly in the OnWindowPosChanged...
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
Quote:
Originally Posted by
npuleio
Well....as I said now I am calling PropertySheet modelessly...
Oh, yes, now I see it.
But since you wrote about it very unclear:
Quote:
Originally Posted by
npuleio
... At least now I'm trying to remove PropertySheet class and use instead a PropertySheet object (the modeless way) ...
(what does it mean "to remove PropertySheet class and use instead a PropertySheet object"?) so I just omited the rest of text...
What exactly are you trying to achieve with the sheet resizing and what do all these magic numbers (10, 15) mean?
Besides, please always use Code tags and indentations while posting code snippets.
About Code tags: http://www.codeguru.com/forum/misc.php?do=bbcode
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
In this case I have this:
Code:
class CMyDialogDlg : public CDialog
{
// Construction
public:
CMyDialogDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
enum { IDD = IDD_MFC_ANALYZER_GUI_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//bool m_bIsBasicConfEnabled;
// Implementation
private:
public:
CString foldervariable;
BOOL m_bIsInitialized;
protected:
HICON m_hIcon;
CPropertySheet* m_poPropSheet;
CPage_Config* pageConfig;
CPage_Profile* pageProfile;
CPage_Monitor* pageMonitor;
CPage_Trace* pageTrace;
CTabCtrl* poControl;
// Generated message map functions
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
void OnExit();
public:
afx_msg void OnWindowPosChanged(WINDOWPOS* lpwndpos);
afx_msg void OnSize(UINT nType, int cx, int cy);
};
CMyDialogDlg::CMyDialogDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDialogDlg::IDD, pParent)
, m_bIsInitialized(FALSE)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
BOOL CMyDialogDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
AfxInitRichEdit2();
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// Extra initialization here
m_poPropSheet = new CPropertySheet();
pageConfig = new CPage_Config( m_poPropSheet );
m_poPropSheet->AddPage(pageConfig);
DWORD dwStyle = WS_VISIBLE | WS_CHILD;
DWORD dwExStyle = WS_EX_LEFT|WS_EX_CONTROLPARENT;
if ( !m_poPropSheet->Create(this, dwStyle, dwExStyle) )
{
DestroyWindow();
return FALSE;
}
poControl = m_poPropSheet->GetTabControl();
m_bIsInitialized = true;
return TRUE; // return TRUE unless you set the focus to a control
}
void CMyDialogDlg::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
CDialog::OnWindowPosChanged(lpwndpos);
if( m_bIsInitialized )
{
m_poPropSheet->SetWindowPos( NULL, 0, 0,
lpwndpos->cx - 10, lpwndpos->cy - 25, SWP_NOMOVE|SWP_NOZORDER );
poControl->SetWindowPos( NULL, 0, 0,
lpwndpos->cx - 20, lpwndpos->cy - 35, SWP_NOMOVE|SWP_NOZORDER );
}
}
and I obtain the bottom goes out of the window as you can see the screenshot at this url:
http://img222.imageshack.us/img222/4...reenshotmt.jpg
So propertysheet's bottom is supposed to be inside the CDialog when it isn't...
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
You still haven't answer my questions:
Quote:
Originally Posted by
VictorN
What exactly are you trying to achieve with the sheet resizing and what do all these magic numbers (10, 15) mean?
Besides, your code has memory leaks (at least in the case of m_poPropSheet->Create(...) fails...
Quote:
Originally Posted by
npuleio
Code:
BOOL CMyDialogDlg::OnInitDialog()
{
CDialog::OnInitDialog();
...
// Extra initialization here
m_poPropSheet = new CPropertySheet();
pageConfig = new CPage_Config( m_poPropSheet );
m_poPropSheet->AddPage(pageConfig);
DWORD dwStyle = WS_VISIBLE | WS_CHILD;
DWORD dwExStyle = WS_EX_LEFT|WS_EX_CONTROLPARENT;
if ( !m_poPropSheet->Create(this, dwStyle, dwExStyle) )
{
DestroyWindow();
return FALSE;
}
...
return TRUE; // return TRUE unless you set the focus to a control
}
Why do you create this property sheet in the heap? :confused:
Just declare the CPropertySheet instance, NOT a pointer, then create it...
Code:
// in the header:
protected:
HICON m_hIcon;
CPropertySheet m_PropSheet;
// in the .cpp:
if ( !m_PropSheet.Create(this, dwStyle, dwExStyle) )
{
DestroyWindow();
return FALSE;
}
The same - for the property pages. :cool:
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
Hello Victor,
"What exactly are you trying to achieve with the sheet resizing and what do all these magic numbers (10, 15) mean?" <--- they are the space difference from the border of the CDialog where the width or the height has to be less than...
About this:
Code:
m_poPropSheet = new CPropertySheet();
I declared in .h the variable as you can see in the code pasted (there's a part which is the .h code), so it would be accessible in entire current document...
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
1. Why do you think that the "space difference from the border of the CDialog" will be exactly 10 and 15? :confused:
No, they are not!
2. And what prevents you to access propertysheet instance if you declare it as
Code:
CPropertySheet m_PropSheet;
Again: your code has memory leaks: you create objects with new but do not delete them! :thumbd:
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
In fact without using new and removing the *, it won't have a memory leak...tomorrow morning I'll fix it...
About the sizing propertysheet and tabcontrol of propertysheet itself how I could set correctly this SetWindowPos to have correct full right and bottom size?...
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
I would try to remove the SWP_NOMOVE flag and use different cx and cy values.
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
HI Arjay....
since I got difficulties applying document/view methodology on propertysheets and pages... so I would ask you if it's appliable also to modeless propertysheets that methodology for DDX/DDV DoDataExchange?....
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
Quote:
Originally Posted by
npuleio
HI Arjay....
since I got difficulties applying document/view methodology on propertysheets and pages... so I would ask you if it's appliable also to modeless propertysheets that methodology for DDX/DDV DoDataExchange?....
Yes.
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
HI Arjay and Victor
I removed the SWP_NOMOVE having this code:
Code:
void CMyDialogDlg::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
CDialog::OnWindowPosChanged(lpwndpos);
if( m_bIsInitialized )
{
m_poPropSheet->SetWindowPos( NULL, 0, 0,
lpwndpos->cx - 8, lpwndpos->cy - 80, SWP_NOZORDER );
poControl->SetWindowPos( NULL, 0, 0,
lpwndpos->cx - 8, lpwndpos->cy - 80, SWP_NOZORDER );
}
}
but I wonder what's this grey square that covers the bottom line of the tabcontrol as you can see here the screenshot:
http://img407.imageshack.us/img407/9...reenshotok.jpg
Maybe I have to add some resize code in the OnWindowPosChanged?...
Thanks
Luigi
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
Quote:
Originally Posted by
npuleio
Please, attach the screenshot rather than this link to your post (there is a button "Manage Attachments" to do it)
-
1 Attachment(s)
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
Quote:
Originally Posted by
VictorN
Please, attach the screenshot rather than this link to your post (there is a button "Manage Attachments" to do it)
OK here the screenshot:
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
Well, it looks like some child windows/controls are on the top...
But what did you expected as a result of your trial and error method with those magic numbers (1, 5, 8, 10, 15, 80,...)? :confused:
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
Hello Victor and Arjay,
I have to measure with those magic numbers (1, 5, 8, 10, 15, 80,...) because there's always a space to fit it...
Anyway if you have a good suggest to fit sheets and pages in their client area without making them disappearing, I'd like a little help...
Actually my code in OnWindowPosChanged is this:
Code:
m_poPropSheet->SetWindowPos( &CWnd::wndBottom, 0, 0,
lpwndpos->cx - 8, lpwndpos->cy - 65, SWP_NOZORDER );
poControl->SetWindowPos( &CWnd::wndBottom, 0, 0,
lpwndpos->cx - 8, lpwndpos->cy - 65, SWP_NOZORDER );
//All another pages will be repositioned than user change tab
//Get client area size
CRect oClientRect;
m_poPropSheet->GetClientRect( &oClientRect );
CPropertyPage* poPage = m_poPropSheet->GetActivePage();
if( poPage != NULL && poPage->m_hWnd != NULL )
{
//poPage->ModifyStyleEx(WS_BORDER, 1, SWP_DRAWFRAME);
poPage->SetWindowPos(&CWnd::wndBottom, oClientRect.left + 2, oClientRect.top + 25,
oClientRect.Width() - 5, oClientRect.Height() - 29, SWP_NOZORDER);
}
CWnd* pCtl = GetDlgItem(IDC_PROGRESSBAR);
CRect WndRect;
GetClientRect( &WndRect );
pCtl->SetWindowPos(&CWnd::wndBottom, WndRect.left, WndRect.bottom - 15,
WndRect.Width(), 15, SWP_NOZORDER);
and since I have nested pages and sheets for example the next level sheet disappear...wonder why... I tried also with NULL in the place of &CWnd::wndBotton... (the IDC_PROGRESSBAR is only at bottom in top level sheet, that causes that - 65 in the code otherwise it would be hided)
Thanks
Luigi
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
According to the sceenshot, it looks like another control is covering a portion of the sheet.
If you need more help with this, zip up a small sample project and post it here. Be sure to remove the debug and release folders and delete the .ncb file before you zip it.
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
Hello Victor and Arjay,
I have three nested levels of Propertysheets... I need to make active by code a page in another sheet which is in another page.... how I could do that?....
Thanks in advance.
Ciao
Luigi
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
Quote:
Originally Posted by
npuleio
Hello Victor and Arjay,
I have three nested levels of Propertysheets... I need to make active by code a page in another sheet which is in another page.... how I could do that?....
Thanks in advance.
Ciao
Luigi
You probably want to rethink your design. Using nested property sheets is discouraged. 3 levels of nesting would really be a poor user experience.
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
Hello Arjay,
in this case, unfortunately I need to have those three levels because they are options of options...something like: if I choose this option then I have to choose between three different sub-option families... I know it's discouraged but these are requisites..
So in this case, how I could call the active page to show that page from wherever I am?...
Thanks
Ciao
Luigi
-
Re: [MFC] DDX/DDV and DoDataExchange between nested PropertySheets
HI Arjay and everyone,
do you know if there's a way to handle the check box's cbutton state change event?...
I mean, I have an initial setting of a checkbox from a bool variable using a personalized DDX_ function, and for a certain check-box of 5 ones I'd need to set/unset some other bool variables which would enable/disable some subpages.... how I could do that?...
thanks
Ciao
Luigi