Solved

CProgressCtrl problem

Posted on 1998-03-22
3
565 Views
Last Modified: 2013-11-19

    private:
    public:
        CTestDialog(CWnd* pParentWnd=NULL):CDialog("D_SEND", pParentWnd){}    
        int DoIt();
    };

    int CTestDlg::DoIt(){
      1  CProgressCtrl * pProgress = (CProgressCtrl *) GetDlgItem(IDC_PROGRESS1);
      2  pProgress->SetRange( 0, 100 );
      3  pProgress->SetStep(20);
      4  pProgress->StepIt();
    }
    // This is called when I chose a menu item.
    void CWindow::HandleTest(){
        CTestDlg MyD;
        MyD.DoIt();
    }

    Why is this dont work? I get some assertion error. If I put these 4 lines
    into some CDialog member, as OnOk, it will work.
    I also tested to set a CProgressCtrl in class CTestDlg, and try it that way,
    but I get the same error. My main window is a CWindow. This CDialog appears if I make a menu choise.
    ---------------
    In release mode, line 1 is no problem, but line 2 is failes.
    In debug mode, it failes on line 1. I followed the debugger: file Winocc.cpp/ CWnd * CWnd::GetDlgItem(int ...)
    ASSERT(::isWindow(m_hWnd)); --> Afxasert.cpp / BOOL bResult=_CrtDbgReport ... I am still helpless.
    I use VC++ 5.0 I also tested to use the //{{AFX_DATA(CTestDLG)methode to get in contact with the dialog, but
    with the same result. I want to use the progress bar for its purpose: to be able to set StepIt() calls in different places in
    a procedure. As I said, if this procedure is a member of CDialog, it works. But people usually want to put StepIt() in
    their own procedures, and that is not working for me.

    Please help, Tomas
0
Comment
Question by:tko092397
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 20 total points
ID: 1317135
You need to make sure that the dialog has been created before using that code. You cannot do anything to something that doesn't exist yet. So you have to wait until OnInitDialog has been called before using your code. For example, you can use

  BOOL CMyDialog::OnInitDialog()
  {
    BOOL retVal = CDialog::OnInitDialog();
    if (retVal)
    {
      // Put your code here
    }
    return retVal;
  }



0
 

Author Comment

by:tko092397
ID: 1317136
Thanks for the hint. I figured out that I must call my procedure from the procedure void CTestDlg::OnOK(). Before, I made some stupid coding found in a bok as follows:

void CWindow::HandleSend()
{
    CTestDlg myDlg(this);
    if (myDlg.DoModal()==IDOK)
        myDlg.DoIt();
}

The right code follows. Move all the code to the place it belongs to. It is pure logic.

int CTestDlg::DoIt()
{
    CProgressCtrl * pProgress = (CProgressCtrl *) GetDlgItem(IDC_PROGRESS1);
    pProgress->SetRange( 0, 100 );
    pProgress->SetStep(12);
    ...
}

void CPromptDialog::OnOK()
{
    DoIt();
    EndDialog(IDOK);
}

void CWindow::HandleSend()
{
    CTestDlg myDlg(this);
    myDlg.DoModal();
}
0
 

Author Comment

by:tko092397
ID: 1317137
Correction:

void CTestDlg::OnOK()
      {
          DoIt();
          EndDialog(IDOK);
      }
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

679 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