Using CPropertySheet on a dialog

Hi,
I'm trying to use a CPropertySheet control on a dialog. I had it working before but now there's a problem. I used this method to create the control:

1.) I made a static control on the dialog box.
2.) I positioned this control where I wanted the CPropertySheet control.
3.) I associated a variable with this control.
4.) I created the CPropertSheet control and positioned it over the static control.

CPropertySheet m_sheet; //Creating the CPropertySheet
...
CStatic     m_ctrlStatic; //Declaring the Variable
...
DDX_Control(pDX, IDC_SHEET_STATIC, m_ctrlStatic); //Associating the static control with the variable
...
m_sheet.Create(this,WS_VISIBLE|WS_CHILD); //Create the CPropertySheet control
...
CRect rect; //Make a positioning object
m_ctrlStatic.GetWindowRect(&rect); //Get position of the static control
ScreenToClient(&rect); //Ready the position for the MoveWindow function
m_sheet.MoveWindow(&rect); //Position the CPropertySheet control over the static control

It used to work, but i must have screwed it up somehow because I now get this error:
Debug Assertion Failed!
File: winocc.cpp
Line: 279

I pressed the Retry button and then the Debug button. It pointed me to this line:
ASSERT(::IsWindow(m_hWnd));
in the MoveWindow Function. This prompted me to believe that the error was occuring because of this line:
m_sheet.MoveWindow(&rect);
I compiled my program with this commented out, and it works, but without the CPropertySheet of course.

My question is: what's going wrong here?
xebra19Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
YechezkelConnect With a Mentor Commented:
From MSDN:

CPropertySheet::Create
BOOL Create( CWnd* pParentWnd = NULL, DWORD dwStyle = (DWORD)–1, DWORD dwExStyle = 0 );

Return Value

Nonzero if the property sheet is created successfully; otherwise 0.

So 0 means there was an error. Probably the reason GetLastError is not giving you the error is that MFC does things in between, losing the error value. However, looking at the code for CPropertySheet::Create shows that the error code is sent to the debug output window. So run a debug build of your app in the debugger (ie start it with Go (F5) instead of Execute Program (Ctrl+F5)) and have a look in the debug tab of the output window.
0
 
YechezkelCommented:
It seems that the Property sheet wasn't created. Check the return value of m_sheet.Create(). If it is 0 the sheet couldn't be created. Try GetLastError() to find out exactly what went wrong.
0
 
AlexNekCommented:
2 xebra19
If you use MFC and MSVC++ why you not use resource editor and class wizard? I have no problem with CPropertyPage and CPropertySheet.
Note: "Objects of class CPropertySheet represent property sheets, otherwise known as tab dialog boxes. A property sheet consists of a CPropertySheet object(!) and one or more(!!) CPropertyPage objects. "
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
xebra19Author Commented:
Yechezkel: The Create function returned 0. GetLastError returned 0 also (indicating a successulf operation). Are you sure tha 0 means that there was an error creating the sheet?

AlexNek: From what I've read the CPropertySheet is different from the tab control.
0
 
AlexNekCommented:
2 xebra19
>From what I've read the CPropertySheet is different from the tab control
What do you need Tab Control or Property Sheet? It is possibly that we talkin about different classes. I talked about CPropertySheet class from MFC which is normally used with CPropertyPage classes. What kind of UI do you want?
0
 
xebra19Author Commented:
Yechezkel: I ran it in the debugger and no value was shown (for the Create function) in the output window. Any ideas?

AlexNek: I am talking about what you are talking about. I knew they were similar but i thought they were different. If they aren't, how would I do what i outlined in my question using the resource editor and the class wizard?
0
 
DanRollinsCommented:
The most common reason for failure to create a dialog is because there is a control on that dialog that can't be created.

Did you recently add a Richedit or tree control (or some such) to one of the property pages?  If so, try deleting it ... or don't do the cSheet.AddPage() for that page.  See if the problem goes away.

=-=-=-=-=-=-=-=-=--=
The other reason is related to mismatch between the resource header files and the Cpp files that use them.  Do a Clean and then Build to see if that helps.

-- Dan
0
 
AlexNekCommented:
2 xebra19
> how would I do...
try this link first:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_core_using_property_sheets_in_your_application.asp

For testing you can create a new dialog based project (File/New/Projects/MFcAppWizard exe) and rename CDialog to CPropertySheet. It can replace Step 4 in the link above.
Let me know if this info is not enough.
0
 
xebra19Author Commented:
Alex: ok, however i'm using it as a control. However i read through the example on the MSDN article you pointed out and noticed that they do the AddPage calls before they create the control. Is this necessary? If so that is probably my problem.

Dan: There are no controls on these dialogs besides text. I have done clean builds and the problem is still there.
0
 
DanRollinsCommented:
>> besides text.
Is this text in a RichEdit control?
0
 
xebra19Author Commented:
It's just normal "static text".
0
 
AlexNekCommented:
2 xebra19
>...they do the AddPage calls before they create the control. Is this necessary?
Yes, you must use it.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcsample/html/_sample_mfc_PROPDLG.asp
0
 
DanRollinsCommented:
Actually, you can do AddPage either before or after the DoModal/Create.  Most typically, you add all pages before Create/DoModal, but there are scenarios in which one might want to add or remove pages dynamically after the sheet window is open.

>> The Create function returned 0.

Here is the heart of your problem.  This needs to work or nothing else matters.  Minimize the complexity of the operation by doing m_sheet.AddPage() for just a single page that has no oddball controls on it.  If Create still fails you need to single-step the Create call to see where it fails.  

-- Dan
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.