Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CProgressCtrl problem

Posted on 1998-03-22
3
Medium Priority
?
581 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 80 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

722 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