Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
CProgressCtrl showing Debug Assert Failed

Please Check this code and help what is wrong

Header File
C++
#pragma once
#include "afxcmn.h"
#include "afxwin.h"


// CFlashingProgressBar dialog

class CFlashingProgressBar : public CDialogEx
{
	DECLARE_DYNAMIC(CFlashingProgressBar)

public:
    CFlashingProgressBar(CWnd* pParent = NULL);   // standard constructor
    virtual ~CFlashingProgressBar();

// Dialog Data
    enum { IDD = IDD_FLASHPROGRESSBAR };

protected:
     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

public:
    virtual BOOL OnInitDialog();
    afx_msg void OnTimer(UINT_PTR nIDEvent);
    CProgressCtrl m_ProgressBarCtrl1;

protected:
	//for default value of two timer
    int m_EndDialog;	//Wait for End dialog
	int m_Counter;		//Counter timer

	DECLARE_MESSAGE_MAP()

};


c++ File

C++
// FlashingProgressBar.cpp : implementation file
//

#include "stdafx.h"
#include "AutoVbiosFlash.h"
#include "FlashingProgressBar.h"
#include "afxdialogex.h"


#define EndDialogTimer		1001
#define CounterTimer		1002

int i=0;
// CFlashingProgressBar dialog

IMPLEMENT_DYNAMIC(CFlashingProgressBar, CDialogEx)

CFlashingProgressBar::CFlashingProgressBar(CWnd* pParent /*=NULL*/)
	: CDialogEx(CFlashingProgressBar::IDD, pParent)
{
   //  SetTimer(EndDialogTimer,40*1000,NULL);
	//SetTimer(CounterTimer,5*1000,NULL);
}

CFlashingProgressBar::~CFlashingProgressBar()
{
}

void CFlashingProgressBar::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_FLASHPROGRESSBAR, m_ProgressBarCtrl1);
    DDX_Control(pDX, IDC_EDIT1, k);
}


BEGIN_MESSAGE_MAP(CFlashingProgressBar, CDialogEx)
	ON_WM_TIMER()
END_MESSAGE_MAP()


// CFlashingProgressBar message handlers

BOOL CFlashingProgressBar::OnInitDialog()
{
    SetTimer(EndDialogTimer,40*1000,NULL);
	SetTimer(CounterTimer,5*1000,NULL);
    return TRUE;
}

void CFlashingProgressBar::OnTimer(UINT_PTR nIDEvent)
{
	if(nIDEvent == EndDialogTimer)
	{
		KillTimer(EndDialogTimer);
		KillTimer(CounterTimer);
		EndDialog(IDD_FLASHPROGRESSBAR);
	}
	if(nIDEvent == CounterTimer)
	{
        m_ProgressBarCtrl1.SetStep(5);
		m_ProgressBarCtrl1.StepIt();
	}
}



On timer i am incrementing setstep and making progress bar but it is showing debug assert failed
Posted
Comments
Richard MacCutchan 6-Mar-13 5:12am    
Please provide proper information. Show the details of the failure and the line in your program where it occurs; don't leave us to guess.

I solved this problem. We need to write UpdateData(FALSE) to update the controls on initDialog().

C#
BOOL CFlashingProgressBar::OnInitDialog()
{
    SetTimer(EndDialogTimer,40*1000,NULL);
    SetTimer(CounterTimer,5*1000,NULL);
    UpdateData(FALSE); //This is what i added
    return TRUE;
}
 
Share this answer
 
Comments
Eugen Podsypalnikov 6-Mar-13 10:27am    
Yep, or :) :
BOOL CFlashingProgressBar::OnInitDialog()
{
BOOL bRes(CDialogEx::OnInitDialog());

SetTimer(EndDialogTimer,40*1000,NULL);
SetTimer(CounterTimer,5*1000,NULL);

return bRes;
}
You should use the return values of SetTimer() by storing them in member variables and pass these when killing the timer:
C++
BOOL CFlashingProgressBar::OnInitDialog()
{
    m_nEndTimer = SetTimer(EndDialogTimer,40*1000,NULL);
    m_nCntTimer = SetTimer(CounterTimer,5*1000,NULL);
    return TRUE;
}

void CFlashingProgressBar::KillTimers()
{
    if (m_nEndTimer)
        KillTimer(m_nEndTimer);
    if (m_nCntTimer)
        KillTimer(m_nCntTimer);
    m_nEndTimer = m_nCntTimer = 0;
}

Also don't forget to kill the timers when the window is closed (e.g. in OnClose()).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900