Solved

CDialog DoModal fails to instanciate dialog.

Posted on 2000-04-15
6
3,140 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

19 Experts available now in Live!

Get 1:1 Help Now