Solved

CProgressCtrl problem

Posted on 1998-03-22
3
558 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

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 video discusses moving either the default database or any database to a new volume.

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

17 Experts available now in Live!

Get 1:1 Help Now