Link to home
Start Free TrialLog in
Avatar of xebra19
xebra19

asked on

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?
Avatar of Yechezkel
Yechezkel

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.
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. "
Avatar of xebra19

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Yechezkel
Yechezkel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
Avatar of xebra19

ASKER

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?
Avatar of DanRollins
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
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.
Avatar of xebra19

ASKER

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.
>> besides text.
Is this text in a RichEdit control?
Avatar of xebra19

ASKER

It's just normal "static text".
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
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