-
Function to Draw Controls from a different dialog box template
I have a section in a FormView in which I draw different groups of controls depending on the situation. I have to programaticlly adjust each control
I was thinking of leveraging the resource graphical editor to position the controls.
I need a function that would take a dialog template file and just draw the controls. I will add the programing code manually.
Any suggestions?
-
Re: Function to Draw Controls from a different dialog box template
How many different groups of controls do you have?
-
Re: Function to Draw Controls from a different dialog box template
-
Re: Function to Draw Controls from a different dialog box template
Use a property sheet control set to wizard mode.
Set the property sheet to a child style and make it a child of your dialog. Create a CPropertyPage for each group of controls, when you need to change groups, just set the active page in the property sheet.
The advantage with this approach is you can use the dialog editor to lay out the groups of controls.
-
Re: Function to Draw Controls from a different dialog box template
Quote:
Originally Posted by
Arjay
Use a property sheet control set to wizard mode.
Set the property sheet to a child style and make it a child of your dialog. Create a CPropertyPage for each group of controls, when you need to change groups, just set the active page in the property sheet.
The advantage with this approach is you can use the dialog editor to lay out the groups of controls.
Don't I want to use a TabCtrl??
-
Re: Function to Draw Controls from a different dialog box template
Quote:
Originally Posted by
ADSOFT
Don't I want to use a TabCtrl??
If you want to do it the hard way, then sure.
-
Re: Function to Draw Controls from a different dialog box template
Quote:
Originally Posted by
ADSOFT
Don't I want to use a TabCtrl??
You know better what you want. :)
Well, for the actual problem, the Arjay's solution is better...
-
Re: Function to Draw Controls from a different dialog box template
-
Re: Function to Draw Controls from a different dialog box template
Yep I'm using MFC.
btw, do you have an example of what you are talking about. I couldn't find anything on property sheet wizards ..... etc.
-
Re: Function to Draw Controls from a different dialog box template
Quote:
Originally Posted by
ADSOFT
Yep I'm using MFC.
btw, do you have an example of what you are talking about. I couldn't find anything on property sheet wizards ..... etc.
Help me understand here - I'm confused that you can't find anything. What search terms are you trying in google and msdn?
-
Re: Function to Draw Controls from a different dialog box template
Quote:
Originally Posted by
Arjay
Help me understand here - I'm confused that you can't find anything. What search terms are you trying in google and msdn?
Ok I have the following:
Code:
::CPropertySheet nameSheet( "Hobby List");
CNamePage pgName;
CHobbyPage pgHobby;
nameSheet.AddPage(&pgName);
nameSheet.AddPage(&pgHobby);
nameSheet.DoModal();
I'm using VS6, I don't see a Property Sheet Control. Do I have to import it from the Gallery?
Also, how do I set the position on where I want it to be placed in my dialog/formview.
-
Re: Function to Draw Controls from a different dialog box template
As mentioned in my first post, set the style of the property sheet to child.
Then inside the parent dialog use CreateWindow to create the sheet (and DestroyWindow).
Btw, does the dialog hold any other controls besides what is contained within the 'group' of controls?
-
Re: Function to Draw Controls from a different dialog box template
I'm not sure if you are talking about CPropertySheet or CPropertyPage.
There is no way I can see of as setting CPropertySheet to wizard mode as there is no control for it.
Still don't see how you position the the PropertyPage. ... all I get is a popup centered on the screen.
-
Re: Function to Draw Controls from a different dialog box template
Please, search MSDN for something like using cpropertysheet cpropertypage... :cool:
-
Re: Function to Draw Controls from a different dialog box template
It's not very clear what exactly you want to accomplish, so please clarfy the points below:
- you want a property sheet which is is in wizard mode or not?
- you want a property sheet which is child or is owned by a (form) view?
- what exactly this mean?
Quote:
There is no way I can see of as setting CPropertySheet to wizard mode as there is no control for it.
To see the difference between child and owned, take a look at these FAQs:
Anyhow, the initial idea of using a tab control to switch between viwes or to show/hide different sets of controls is not so good.
Using the property sheet is easier and more elegant.
-
Re: Function to Draw Controls from a different dialog box template
Quote:
Originally Posted by
ovidiucucu
It's not very clear what exactly you want to accomplish, so please clarfy the points below:
- you want a property sheet which is is in wizard mode or not?
- you want a property sheet which is child or is owned by a (form) view?
- what exactly this mean?
To see the difference between
child and
owned, take a look at these FAQs:
Anyhow, the initial idea of using a tab control to switch between viwes or to show/hide different sets of controls is not so good.
Using the property sheet is easier and more elegant.
Ok
What I want to do is have a Formview where I can have the functionality of a CTabCtrl. The functionality I'm looking for is to be able to access controls in a designated area, and also manipulate controls in the remaining client area. Property PAGES in a PropertySheet doesn't offer that capability: At least I don't see how to make a PropertySheet( the object that contains the PropertyPages) a Child of a FormView.
I see the that:
Quote:
CPropertySheet::Create
BOOL Create( CWnd* pParentWnd = NULL, DWORD dwStyle = WS_SYSMENU | WS_POPUP | WS_CAPTION | DS_MODALFRAME | WS_VISIBLE, DWORD dwExStyle = WS_EX_DLGMODALFRAME );
But I don't see how to set the position coordinates of the CPropertySheet.
-
Re: Function to Draw Controls from a different dialog box template
Quote:
Originally Posted by
ADSOFT
But I don't see how to set the position coordinates of the CPropertySheet.
Don't you know CWnd::MoveWindow exists? :confused:
-
Re: Function to Draw Controls from a different dialog box template
Quote:
Originally Posted by
ADSOFT
I'm not sure if you are talking about CPropertySheet or CPropertyPage.
There is no way I can see of as setting CPropertySheet to wizard mode as there is no control for it.
Still don't see how you position the the PropertyPage. ... all I get is a popup centered on the screen.
You may create a class derived from CPropertySheet. The constructor of the class will either take an ID for the string caption to be used or a const char* for the caption itself. The CPropertySheet isn't a dialog but actually (only) a customized tab control (window) with basic functions to take and manage dialog pages.
Each dialog page can be created with the resource editor and should be a child window (no menu, no frame) and not a popup. Then you need to add each page to the property sheet calling the AddPage member.
If you have some dialog controls common to each page, you might think of using a class derived from CDialog (or CFormView) rather than from CPropertySheet. This form may have any number of controls and a (big) tab control which is supposed to take and handle the property pages. If you do so, you would need to add functions like AddPage, RemovePage, GetActivePage and so on yourself, what isn't much difficult cause you could get most implementations from the MFC source dlgprop.cpp.
-
Re: Function to Draw Controls from a different dialog box template
Quote:
Originally Posted by
ADSOFT
how to make a PropertySheet( the object that contains the PropertyPages) a Child of a FormView.
This way
Code:
int CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFormView::OnCreate(lpCreateStruct) == -1)
return -1;
m_pps = new CMyPropertySheet(_T("My Propery Sheet"));
// create child property sheet
m_pps->Create(this, WS_CHILD|WS_VISIBLE);
-
Re: Function to Draw Controls from a different dialog box template
Quote:
Originally Posted by
itsmeandnobodyelse
CPropertySheet isn't a dialog but actually (only) a customized tab control (window) with basic functions to take and manage dialog pages.
Although CPropertySheet isn't drived from CDialog, a property sheet IS a dialog (of window class #32770). In fact it's a kind of complex Windows control having a dialog as a layer for a tab control (if not in wizard mode), some buttons and several other dialogs (pages).
Quote:
Originally Posted by
itsmeandnobodyelse
...you might think of using a class derived from CDialog (or CFormView) rather than from CPropertySheet. This form may have any number of controls and a (big) tab control which is supposed to take and handle the property pages. If you do so, you would need to add functions like AddPage, RemovePage, GetActivePage and so on yourself, what isn't much difficult cause you could get most implementations from the MFC source dlgprop.cpp
It's like reinventing the wheel. I made it once myself, but it's not a good choice.
-
Re: Function to Draw Controls from a different dialog box template
To understand better what property sheets are, you can take a look in MSDN at Property Sheet topics.
The MFC classes CPropertySheet and CPropertyPage, just encapsulate the WinAPI stuff presented there.
An also you can take a look at this article: http://www.codexpert.ro/articole.php?id=11
It is in Romanian, but the pictures are self-explanatory. :)
-
Re: Function to Draw Controls from a different dialog box template
Quote:
Originally Posted by
ovidiucucu
Although CPropertySheet isn't drived from CDialog, a property sheet IS a dialog (of window class #32770). In fact it's a kind of complex Windows control having a dialog as a layer for a tab control (if not in wizard mode), some buttons and several other dialogs (pages).
It's like reinventing the wheel. I made it once myself, but it's not a good choice.
You can't seed it with a dialog resource, so all the internal properties are of no value - beside you are content with the functionality of a tabcontrol which can manage dialog pages.
'Reinventing the wheel' would at least mean there is a wheel. But the CPropertySheet has only a poor interface and was not able to 'roll' a normal dialog.
I often used a own property sheet dialog form and there is no easy alternative in MFC if you want to run a main dialog form together with tabbed subforms where all forms were designable using the resource editor.
-
Re: Function to Draw Controls from a different dialog box template
Well I've tried the following and I can't get it to pop up.The App runs but it doesn't show anything.
If I set it to modal it works and also the the wizard mode works
Code:
::CPropertySheet nameSheet( "Hobby List",this);
CNamePage pgName;
CHobbyPage pgHobby;
nameSheet.AddPage(&pgName);
nameSheet.AddPage(&pgHobby);
//nameSheet.SetWizardMode(); //works
//nameSheet.DoModal(); //works, but I don't want modal
nameSheet.Create(this, WS_CHILD | WS_CAPTION | WS_VISIBLE);
nameSheet.SetWindowPos(this,0,0,100,100,SWP_SHOWWINDOW);
nameSheet.ShowWindow(SW_SHOW);
-
Re: Function to Draw Controls from a different dialog box template
Quote:
Originally Posted by
ADSOFT
Well I've tried the following and I can't get it to pop up.The App runs but it doesn't show anything.
If I set it to modal it works and also the the wizard mode works
Code:
::CPropertySheet nameSheet( "Hobby List",this);
CNamePage pgName;
CHobbyPage pgHobby;
nameSheet.AddPage(&pgName);
nameSheet.AddPage(&pgHobby);
//nameSheet.SetWizardMode(); //works
//nameSheet.DoModal(); //works, but I don't want modal
nameSheet.Create(this, WS_CHILD | WS_CAPTION | WS_VISIBLE);
nameSheet.SetWindowPos(this,0,0,100,100,SWP_SHOWWINDOW);
nameSheet.ShowWindow(SW_SHOW);
And where was this code placed?
And how and when is is called?
Isn't this CPropertySheet nameSheet a local variable in some block?
-
Re: Function to Draw Controls from a different dialog box template
Quote:
Originally Posted by
ADSOFT
Well I've tried the following and I can't get it to pop up.The App runs but it doesn't show anything.
If I set it to modal it works and also the the wizard mode works
Code:
::CPropertySheet nameSheet( "Hobby List",this);
CNamePage pgName;
CHobbyPage pgHobby;
nameSheet.AddPage(&pgName);
nameSheet.AddPage(&pgHobby);
//nameSheet.SetWizardMode(); //works
//nameSheet.DoModal(); //works, but I don't want modal
nameSheet.Create(this, WS_CHILD | WS_CAPTION | WS_VISIBLE);
nameSheet.SetWindowPos(this,0,0,100,100,SWP_SHOWWINDOW);
nameSheet.ShowWindow(SW_SHOW);
It isn't going to work because the nameSheet will go out of scope. You'll need to create a m_NameSheet variable as part of the CFormView derived class and call the Create method in OnInitialUpdate.
-
Re: Function to Draw Controls from a different dialog box template
Quote:
Originally Posted by
Arjay
It isn't going to work because the nameSheet will go out of scope. You'll need to create a m_NameSheet variable as part of the CFormView derived class and call the Create method in OnInitialUpdate.
Ok, I got it to work.
Did all the initialization in the OnInitialize of the Formview.
Calling SetPosWindow causes an assertion error. Have to look into that.
I also found that doing Modless Dialog Boxes gives me the functionality I'm looking for.
-
Re: Function to Draw Controls from a different dialog box template
Quote:
Originally Posted by
ADSOFT
Did all the initialization in the OnInitialize of the Formview.
What is OnInitialize? Do you mean OnInitialUpdate?
I also found that doing Modless Dialog Boxes gives me the functionality I'm looking for.[/QUOTE]Yes, that is what we told you to do - calling Create( ) on a CPropertySheet creates a modeless property sheet.
-
Re: Function to Draw Controls from a different dialog box template
Quote:
Originally Posted by
Arjay
What is OnInitialize? Do you mean OnInitialUpdate?
I also found that doing Modless Dialog Boxes gives me the functionality I'm looking for.
Yes, that is what we told you to do - calling Create( ) on a CPropertySheet creates a modeless property sheet.[/QUOTE]
That is another way to do it. However, I find it's about the same amount of work as a doing a CTabCtrl. The CTabCtrl also has some nice features as to changing the position of the tabs.
I find the easiest way is to do Modless Dialogs and pass them a pointer to the parent window (so as to manipulate the parents controls, ... the functionality I was looking for) and add the templates as you go along and or as you want to increase proccessing of the parent class( It's better than mount controls on top each other and hiding them, like some else suggested). ... Kind of like a split view with Dialog boxes and a Formview.
Another cool thing about doing the modless dialogs and passing it a pointer to the FormView is that you can make the Modless Dialogs take up the whole area of the Formview and somewhat make it multiview(.. if you don't want to create a View for each screen and go that route.
Thanks for the help, It's always cool to have several ways to do stuff. You never know what situation will come up.
-
Re: Function to Draw Controls from a different dialog box template
Quote:
Originally Posted by
ADSOFT
That is another way to do it. However, I find it's about the same amount of work as a doing a CTabCtrl. The CTabCtrl also has some nice features as to changing the position of the tabs.
Do you think we should mention all the possible ways to something? We've got 29 replies now to get you to this point, would you have gotten to this point sooner if we had suggest several alternatives?
Quote:
Originally Posted by
ADSOFT
I find the easiest way is to do Modless Dialogs and pass them a pointer to the parent window (so as to manipulate the parents controls,
That's another approach to take but it introduces tight coupling between UI components. If you follow any of the recent design patterns, you'd know that it isn't recommended that one UI component manipulate the controls of another UI component.
Quote:
Originally Posted by
ADSOFT
Another cool thing about doing the modless dialogs and passing it a pointer to the FormView is that you can make the Modless Dialogs take up the whole area of the Formview and somewhat
If you want the property pages to actually be a child control of the formview, use the approach I suggested. If you want the prop sheet to be separate, then use a modeless sheet.
It would help if you figured out what you want before asking questions; otherwise, you're wasting the forum's time.
-
Re: Function to Draw Controls from a different dialog box template
Quote:
Originally Posted by
Arjay
It would help if you figured out what you want before asking questions; otherwise, you're wasting the forum's time.
Well what I wanted was a function to use a dialog template to utilize it's componts. The answer is
Code:
myDialog.Create(IDD_MyDialog);
After creating myDialog in classwizard from IDD_MyDialog
I took alot of time to write the title of my question.
It's an open forum, and if it took 29 responses to get the answer of my question, it wasn't a waste of time.
-
Re: Function to Draw Controls from a different dialog box template
Quote:
Originally Posted by
ADSOFT
Well what I wanted was a function to use a dialog template to utilize it's componts. The answer is
Code:
myDialog.Create(IDD_MyDialog);
After creating myDialog in classwizard from IDD_MyDialog
I took alot of time to write the title of my question.
It's an open forum, and if it took 29 responses to get the answer of my question, it wasn't a waste of time.
I didn't expect you to see things from a different point of view.
-
Re: Function to Draw Controls from a different dialog box template
-
Re: Function to Draw Controls from a different dialog box template
Quote:
Originally Posted by
ovidiucucu
It's not very clear what exactly you want to accomplish, so please clarfy the points below:
- you want a property sheet which is is in wizard mode or not?
- you want a property sheet which is child or is owned by a (form) view?
- what exactly this mean?
To see the difference between
child and
owned, take a look at these FAQs:
Anyhow, the initial idea of using a tab control to switch between viwes or to show/hide different sets of controls is not so good.
Using the property sheet is easier and more elegant.
Btw, Thanks.
This post was very helpfull