Solved

CDialog DoModal fails to instanciate dialog.

Posted on 2000-04-15
6
3,200 Views
Last Modified: 2013-11-20
I'm using Visual Studio V6 in Win98.

My dialog template is very basic I think.
     6 Text Boxes
     3 Progrsss Bars
     1 button = IDOK

The support class was constructed with the Wizzard.
Program compiles and links perfectly.

When the program runs and I select the menu item for this dialog the DoModal fails, retun = -1.

The calling code is as follows.
void CMainFrame::OnSlctEvalSummary()
{
     // Display the Self Appraisal Summary Results Dialog.
     CAppraisalResultsDlg  appraisalResults;
     int iReturnVal = appraisalResults.DoModal();
}

I traced into the failure with these results.

int CDialog::DoModal()
{
   TRY{
     AfxHookWindowCreat(this);
          // this = 0x0066f6d0{CAppraisalResultsDlg hWnd = 0x000000}
     if(CreateDlgIndirect(lpDialogTemplete,
          // lpDialogTemplete = 0x0042f580
        CWnd::FromHandle(hWndParent),
          // hWndParent = 0x00000574
        hInst))
          // hInst = 0x00400000

}

Here inside the TRY of the DoModal function at the 'if' is where it fails.  I can't find
documentation on the CreateDlgIndirect function and the above values appear to me as valid.

What can cause this failure?
Any ideas will be greatly appriciated.

Thanks in advance.
0
Comment
Question by:TrainMan
  • 3
  • 2
6 Comments
 

Author Comment

by:TrainMan
ID: 2719381
Here's a thought.  Could this problem be cause by the CProgressCtrl class if it were not setup right?

When I first used this I was asked to select 3 options.  One was for Control, another for Ole, and the third I don't remember.  I de-select the last 2.

How can I change this?
0
 

Expert Comment

by:bertp
ID: 2719727
make sure you have rebuilt everything so that all is in sync with your class definition. my best guess  
is your resources, precompiled headers, and dialogbox implememtation are out of snyc and tripping up the CreateDlgIndirect function
 
If it still blows, see if your dialog processes the initdialog message

To make sure that the problem is the dialog box and not the program calling it, temporarily replace CAppraisalResultsDlg   with CAboutDlg to see if it can load the about dialog at that point...

HTH! Good luck debugging!

0
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 2719766
Put the following code in your application object's InitInstance function.

INITCOMMONCONTROLSEX InitCtrls =
{
    sizeof(INITCOMMONCONTROLSEX),
    ICC_PROGRESS_CLASS
};
::InitCommonControlsEx(&InitCtrls);
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:TrainMan
ID: 2727093
Thanks chensu for the input.  Haven't had the chance to try it and will not until maybe Wednesday night because of school and work.  
What does it do?

I did notice that by trying bertp's suggestion that the problem was in my template.  So I removed the 3 Progress Bars and the 2 MS Forms Labels, and everything worked fine.

When I tried to place a Forms Label in I had the same problem.  Then I tried placing just 1 Progress Bar in and got an assertion in my OnIninitDialog() function at SetRange().

So, what gives?
Do I need to enter similar code for that also?

Thanks in advance.
0
 
LVL 23

Expert Comment

by:chensu
ID: 2727457
The InitCommonControlsEx function initializes the Common Control library.

In order for the MS Forms Label ActiveX controls to work, you need to call the AfxEnableControlContainer function as well.
0
 

Author Comment

by:TrainMan
ID: 2738260
The problem with the CProgressCtrl was that the SetRange() and SetPos() functions got entered _prior_ to the call for CDialog::OnInitDialog().  Kinda dumb to try to use a pointer to an object that doesn't exists yet isn't it.  So I didn't need your first code fragment.

However the call to AfxEnableControlContainer() did need to be added to my apps InitInstance() function.

Thanks again for your help.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 49
not able to insert into temp table 68 162
notReplace  challenge 53 125
Window placement 17 80
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

806 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