-
MFC Feature Pack - How to create CMFCPropertySheet control?
Hello.
I'm working on a project that uses the MFC Framework to create the GUI. More specifically, the so-called "Feature Pack" of MFC is used. As I haven't used the MFC Framework until now, I currently try to understand the basics. So I read a few tutorials and I think the "CMFCPropertySheet" control would be what I need. So created a new "empty" MFC project in Visual Studio and now I try add a CMFCPropertySheet control to the main window. Later I will add the Pages, but first I need to add the control.
What I have done so far is deriving my own Class "CMyPropSheet" from "CMFCProperty" sheet. I also added a method OnCreate() to my own class, which I think is the correct place to create and add the Sheets later. But now, how the heck do I create an instance of my CMPropSheet and add it to my main window? I think I must do this inside the OnCreate() method of the "MainFrm" class. Is that correct? If so, what is correct method to call? Create or CreateEx and what parameters do I need to pass? I couldn't find any example on this.
What I tried is:
-
Re: MFC Feature Pack - How to create CMFCPropertySheet control?
Sorry, I mistakenly hit the "Submit" button too early ^^
Another try, what I tried is:
Code:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
[...]
//Create the Properties Sheet
if(!m_wndPropSheet.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
[...]
}
But the result now is "Failed to create empty document" on startup of the application :(
Can anybody point me to the right direction? What am I doing wrong?
Thanks in advance!
Regards,
Daniel.
-
Re: MFC Feature Pack - How to create CMFCPropertySheet control?
Debug your code, step into the
Code:
if(!m_wndPropSheet.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP))
and try to understand what was wrong and why...
-
Re: MFC Feature Pack - How to create CMFCPropertySheet control?
wont propertysheet/propertypage be created on a dialog or some framewnd....
rather than the MainFrame itself ?? correct me if I am wrong..
-
Re: MFC Feature Pack - How to create CMFCPropertySheet control?
Quote:
Originally Posted by
vcdebugger
wont propertysheet/propertypage be created on a dialog or some framewnd....
rather than the MainFrame itself ?? correct me if I am wrong..
Thank you for reply!
Can you elaborate a bit on this? I would like to have the PorpertySheet inside my main window, filling the space between the menubar on the top and the statusbar on the bottom. Is that possible at all? If yes, can you give me some hint how I would do this with the help of a "dialog" or a "framewnd"? If it's not possible, what would be an alternative? Actually all I need is some widget that I can place in the main window and which provides several pages with tabs. Once I have achieved that, the next step will be to arrange the "DockablePanes", which already exist in the project, in their appropriate pages. Currently all those DockablePanes are floating around in the main window, which is rather confusing for the user. So we are trying to get them distributed over several tabs.
(BTW: I managed to "merge" several DockablePanes into a TabbesPane, but then each DockablePane had it's own Tab. I need two or three DockablePanes to be arrange inside the same Tab/Page)
-
Re: MFC Feature Pack - How to create CMFCPropertySheet control?
Quote:
Originally Posted by
VictorN
Debug your code, step into the
Code:
if(!m_wndPropSheet.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP))
and try to understand what was wrong and why...
Okay, I will try to do so later this day. Do you think Create() is the correct function to create the control? And are the flags appropriate?
I couldn't find any information on which flags the PropertySheet control expects in its Create() function.
Somewhere I read that with the "Feature Pack" I am supposed to use CreateEx() instead of Create(), but the CreateEx() function had even more parameters for which I couldn't find any documentation specific to PropertySheet...
Any information on this would be greatly appreciated...
-
Re: MFC Feature Pack - How to create CMFCPropertySheet control?
Which CreateEx do you mean? :confused:
CMFCPropertySheet Class has neither its own [B]Create [/Bnor CreateEx ]method.
CPropertySheet class from which CMFCPropertySheet is derived does have Create, but not CreateEx method.
-
Re: MFC Feature Pack - How to create CMFCPropertySheet control?
Quote:
Originally Posted by
VictorN
Which CreateEx do you mean? :confused:
CMFCPropertySheet Class has neither its own [B]Create [/Bnor
CreateEx ]method.
CPropertySheet class from which
CMFCPropertySheet is derived does have
Create, but not
CreateEx method.
Yeah, I noticed that too, and actually I don't know which one I am supposed to use. In my project the controls (e.g. DockablePane) are created via Create() before they are added to the main window. And this apparently does work. Now, in some "Feature Pack" tutorial I read that with new controls from the Feature Pack I'm supposed to use the CreateEx() function instead of Create(). However I'm not sure if that applies to the PropertiesSheet as well. So can you give me any hint on how to find out what is the correct method to create an instance of CMDPropertySheet, so I can add that new instance to my main window? I looked at the "New Controls" example that ships with the Feature Pack. In that example they use the PropertySheet, but it seems the way they instantiated it is quite different from my project. They used DoModal() on the ProperySheet instead of showing the main window. In my project, I already have a main window with various controls inside, and I need to put the PropertySheet inside the main window too! If that is not possible for some reason, I need an alternative to PropertySheet. Suggestions are very welcome! Or if I need further controls (vcdebugger mentioned "dialog or some framewnd") to put the Property Sheet in the main window, it would be great if you could point me to the right one...
-
Re: MFC Feature Pack - How to create CMFCPropertySheet control?
Quote:
Originally Posted by
dtrick
... Now, in some "Feature Pack" tutorial I read that with new controls from the Feature Pack I'm supposed to use the CreateEx() function instead of Create(). However I'm not sure if that applies to the PropertiesSheet as well. So can you give me any hint on how to find out what is the correct method to create an instance of CMDPropertySheet, ...
1. In *what* "Feature Pack" tutorials did you read about CreateEx() and for *which* controls?
2. I already gave you a hint to MSDN. What could be more "correct" than MSDN? :confused:
-
Re: MFC Feature Pack - How to create CMFCPropertySheet control?
(1) Sorry, I cannot find the paragraph right now. Maybe I was mistaken there. So you are saying creating an instance of CMFCPropertySheet via Create() would be the correct method for MFC? Please remember that I'm new to MFC and I see they sometimes use Create() and sometimes they use CreateEx() to create instances of controls. I haven't yet figured out what the difference is and when I need to use which one. Any hint on this would be helpful.
(2) Well, yes. The MSDN documentation specifies the function and their parameters. Still I don't have a clue whether I'm supposed to used that function for what I try to achieve or not. The documentations says about CPropertySheet::Create "Displays a modeless property sheet". What exactly does mode-less mean in this context? Moreover I want to add the control into my main window. Does Create() create the control in a way that I can use it to add it to main window? Also, as a MFC beginner, I'm pretty confused on all those Style and ExStyle flags. There is a long list about which flags exist. But which ones do I need for what I'm trying to achieve? Would the "defaults", -1 and 0, respectively, be okay?
Furthermore: I'm not sure whether CMFCPropertySheet can what I want. It just looked "suitable" to me in the tutorial at a first glance. Any suggestions on a more suitable would be much appreciated! :)
-
Re: MFC Feature Pack - How to create CMFCPropertySheet control?
To see what the modeless property sheet is - just implement the code shown in MSDN article CPropertySheet::Create
About modal/modeless dialogs - see MSDN
If you'd like, however, to place your propertysheet on some dialog template inside mane frame - then create a MFC SDI project with the CFormView derived class as a View, then in the created CFormView derived class method OnInitialUpdate add your code:
Code:
int void C<SomeViewName>::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
//Create the Properties Sheet
if(!m_wndPropSheet.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
[...]
}
-
Re: MFC Feature Pack - How to create CMFCPropertySheet control?
Okay, thanks!
But since I am working in an existing project, creating a new project is not an option for me. So is it possible to add that so-called "dialog template" to an existing project afterwards? If so and if I understand you correctly, I would create a custom class that is derived from CFormView. Inside that class I create the CPropertySheet. And finally I can my CFormView-derived class to the main window? Please correct me, if I'm wrong...
-
Re: MFC Feature Pack - How to create CMFCPropertySheet control?
Since you are "new to MFC" I'd suggest to do your tests/trials in some other test projects. Then, if you will see that your test is successful - move it to your main project.
Besides:
- Controls are usually placed not in a main frame window but in some dialog or View having dialog template.
- You didn't mention what type of MFC project you you are working with.
-
Re: MFC Feature Pack - How to create CMFCPropertySheet control?
Okay, I followed your suggestion and created a new "Test" project.
I created an "MFC Application" with "Single Document" type and "MFC Standard" style. I also changed the BaseClass of the View to CFormView. I think that is what you ment. I added m_wndPropSheet as a member to CFMCTest4View as a CPropertySheet. Then in the OnInitialUpdate() method of the CFormView-derived class I added the follwoing code:
Code:
void CMFCTest4View::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
//Create the Properties Sheet
if(!m_wndPropSheet.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP))
{
TRACE0("Failed to create toolbar\n");
//return -1; // fail to create <-- can't return anything here
}
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
The result looks like this:
http://img291.imageshack.us/img291/7594/mfctest.png
Now can you please tell me how I can manage the make the PropertySheet actaully appear in the are where the "TODO" text is currently displayed?
Moreover, how would I kick out the clunky "Ribbons" bar, if I don't need it?
(BTW: In my actual project, the MainFrm is a CFrameWnd, the View is a CView and the "main" class is a CWinAppEx, if that matters)
Thanks,
Daniel.
-
Re: MFC Feature Pack - How to create CMFCPropertySheet control?
Quote:
Originally Posted by
dtrick
Please, next time attach images to your post.
Quote:
Originally Posted by
dtrick
Now can you please tell me how I can manage the make the PropertySheet actaully appear in the are where the "TODO" text is currently displayed?
Use CWnd::MoveWindow to move your sheet to a new position.
To know position of "TODO"control - use GetWindowRect (note, that control ID must be changed from IDC_STATIC to something else)
Quote:
Originally Posted by
dtrick
TMoreover, how would I kick out the clunky "Ribbons" bar, if I don't need it?
I don't know. I hate the most of new "themed" and Ribbons" features and don't use them at all.
-
Re: MFC Feature Pack - How to create CMFCPropertySheet control?
Okay, I tried with the following code:
Code:
void CMFCTest4View::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
//Create the Properties Sheet
if(!m_wndPropSheet.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP))
{
TRACE0("Failed to create toolbar\n");
//return -1; // fail to create
}
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
//Make Properties Sheet visible
m_wndPropSheet.MoveWindow(128,128,300,300,true);
}
I also tried:
Code:
//Make Properties Sheet visible
RECT rectParent;
GetParentFrame()->GetWindowRect(&rectParent);
m_wndPropSheet.MoveWindow(rectParent.left, rectParent.top, rectParent.right-rectParent.left, rectParent.top-rectParent.bottom, true);
But now I get an "Assertion Failed" right at startup. It is triggered by CWnd::MoveWindow() :(
More specifically the following Assertion fails:
Code:
void CWnd::MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint)
{
ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL));
[...]
}
Any hint on how to resolve this would be very much appreciated.
Regards,
Daniel.
-
Re: MFC Feature Pack - How to create CMFCPropertySheet control?
It is very strange...
Either your
Code:
m_wndPropSheet.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP)
failed or this CWnd::MoveWindow where assertion failed has nothing to do with
Code:
m_wndPropSheet.MoveWindow(128,128,300,300,true);
-
Re: MFC Feature Pack - How to create CMFCPropertySheet control?
Quote:
Originally Posted by
dtrick
I also tried:
Code:
//Make Properties Sheet visible
RECT rectParent;
GetParentFrame()->GetWindowRect(&rectParent);
m_wndPropSheet.MoveWindow(rectParent.left, rectParent.top, rectParent.right-rectParent.left, rectParent.top-rectParent.bottom, true);
Where is this code called from?
-
Re: MFC Feature Pack - How to create CMFCPropertySheet control?
Quote:
Originally Posted by
VictorN
It is very strange...
Either your
Code:
m_wndPropSheet.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP)
failed or this
CWnd::MoveWindow where assertion failed has nothing to do with
Code:
m_wndPropSheet.MoveWindow(128,128,300,300,true);
You are right, the Create() failed. I put a MessageBoxW() where I had commented out the "return -1" before and it was triggered.
So, any hints on why it couldn't be created? Do I need to specify different flags? Or maybe CreateEx() must be used to create that control?
I would be glad for any advice on how to create a control and add it to the main window in MFC. I can't be the first person who tries to accomplish that ;)
Thanks in advance...
Quote:
Originally Posted by
VictorN
Where is this code called from?
From the same location where I called the MoveWindow() before, i.e. from void CMFCTest4View::OnInitialUpdate() method.
-
Re: MFC Feature Pack - How to create CMFCPropertySheet control?
Quote:
Originally Posted by
dtrick
So, any hints on why it couldn't be created? Do I need to specify different flags? Or maybe CreateEx() must be used to create that control?
You asked already a lot of times about CreateEx for propertysheet. Didn't you read my answer about it? If you don't believe me - search MSDN for how to create propertysheet with propertypages.
To find out the reason why Create failed - debug your code, step in to the Create method and go step-by-step (F10) through the code until you meet the problem...
BTW, this my code is about 10 years old and it works ...
Code:
// in header
CDisabPropSheet m_PropSheet; // CDisabPropSheet is derived from CPropertySheet
// class CSpconfigView is derived from CFormView
...
m_PropSheet.Create(this, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS );
-
Re: MFC Feature Pack - How to create CMFCPropertySheet control?
Quote:
Originally Posted by
VictorN
You asked already a lot of times about CreateEx for propertysheet. Didn't you read my answer about it? If you don't believe me - search MSDN for how to create propertysheet with propertypages.
I'm just wondering how the issue could be resolved. If you tell me you got it working with Create() instead of CreateEx(), I believe you :)
However I still didn't find an enlightening answer on when MFC controls need to be created with Create() and when they need to be created with CreateEx().
In my project I see a wild mixture of both of t hem...
Quote:
Originally Posted by
VictorN
To find out the reason why Create failed - debug your code, step in to the Create method and go step-by-step (F10) through the code until you meet the problem...
BTW, this my code is about 10 years old and it works ...
Code:
// in header
CDisabPropSheet m_PropSheet; // CDisabPropSheet is derived from CPropertySheet
// class CSpconfigView is derived from CFormView
...
m_PropSheet.Create(this, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS );
The problem is, that I wouldn't have to debug my code, but Microsoft's code. After stepping into the Create() I will end up somewhere in the MFC framework. I really don't think I am supposed to debug the framework code. It must be able to create a control in MFC without debugging the framework itself. Anyway, when I have more time I will give a try. Maybe I can find some hint on the problem at least, even though I doubt I will be able to fix it, if the problem lies inside the framework.
About your code snippet: You don't have a piece of code that actually compiles through you could share?
I'm off for this week, but the struggly continues on monday ;)
Best regards,
Daniel.
-
When CMFCPropertySheet::PropSheetLook_List option is used , scroll bars are not disp
When CMFCPropertySheet::PropSheetLook_List option is used , scroll bars are not displayed
When CMFCPropertySheet::PropSheetLook_List option is used , scroll bars are not displayed
----------------------------------------------------------------------------------------------------------------------
According to MSDN :
For PropSheetLook_List
The framework displays scroll arrows if there are more list items than will fit in the visible area of the list.
Unfortunately, scroll bars are not displayed when there are many items presents outside visible area.
-
Re: MFC Feature Pack - How to create CMFCPropertySheet control?
Dear amitgpatil,
what does your post have to do with this thread where we discussed the problem "MFC Feature Pack - How to create CMFCPropertySheet control?"?
Please, don't revive the old threads if they don't need it!
PS: note that you may be banned for such type of posts! :cool: