Solved

Using CPropertySheet on a dialog

Posted on 2002-05-07
13
511 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
  • 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

762 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now