Solved

Using CPropertySheet on a dialog

Posted on 2002-05-07
13
542 Views
Last Modified: 2007-12-19
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?
0
Comment
Question by:xebra19
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
  • +1
13 Comments
 
LVL 1

Expert Comment

by:Yechezkel
ID: 6996185
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
 
LVL 16

Expert Comment

by:AlexNek
ID: 6996409
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
 

Author Comment

by:xebra19
ID: 6997830
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Accepted Solution

by:
Yechezkel earned 50 total points
ID: 6998264
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
 
LVL 16

Expert Comment

by:AlexNek
ID: 6998413
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
 

Author Comment

by:xebra19
ID: 7000197
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 7000679
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
 
LVL 16

Expert Comment

by:AlexNek
ID: 7001005
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
 

Author Comment

by:xebra19
ID: 7002673
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 7002904
>> besides text.
Is this text in a RichEdit control?
0
 

Author Comment

by:xebra19
ID: 7002920
It's just normal "static text".
0
 
LVL 16

Expert Comment

by:AlexNek
ID: 7003085
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 7003589
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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C++ get user from AD  (VS6) 7 111
Adding items to a C# list incrementally 5 82
Can Live bindings change TGrid Cell Colour ? 1 61
Need some help with design 17 46
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question