Solved

CProgressCtrl problem

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Question regarding Copy/Paste 16 95
ODBC Connection Logging, ADO.NET 6 64
fizzArray2 challenge 1 78
pre4 challenge 19 100
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. …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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 shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

786 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