Solved

CProgressCtrl problem

Posted on 1998-03-22
3
564 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

840 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