CProgressCtrl显示Debug Assert失败 [英] CProgressCtrl showing Debug Assert Failed

查看:77
本文介绍了CProgressCtrl显示Debug Assert失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CProgressCtrl显示调试断言失败



请检查此代码并帮助解决问题



标题文件

  #pragma once 
#include afxcmn.h
#include afxwin.h


// CFlashingProgressBar对话框

class CFlashingProgressBar: public CDialogEx
{
DECLARE_DYNAMIC(CFlashingProgressBar)

public
CFlashingProgressBar(CWnd * pParent =空值); // 标准构造函数
virtual ~CFlashingProgressBar();

// 对话数据
enum {IDD = IDD_FLASHPROGRESSBAR};

受保护
虚拟 void DoDataExchange(CDataExchange * pDX); // DDX / DDV支持

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

受保护
// for two value of two timer
int m_EndDialog; // 等待结束对话框
int m_Counter; // 计数器计时器

DECLARE_MESSAGE_MAP()

};





c ++文件



  //   FlashingProgressBar.cpp:实施文件 
//

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


#define EndDialogTimer 1001
#define CounterTimer 1002

int i = 0 ;
// CFlashingProgressBar对话框

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()


< span class =code-comment> // CFlashingProgressBar消息处理程序

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();
}
}







在计时器上我正在增加设定步骤并取得进展吧但它显示调试断言失败

解决方案

我解决了这个问题。我们需要编写UpdateData(FALSE)来更新initDialog()上的控件。



 BOOL CFlashingProgressBar :: OnInitDialog()
{
SetTimer(EndDialogTimer,40 * 1000,NULL);
SetTimer(CounterTimer,5 * 1000,NULL);
UpdateData(FALSE); // 这就是我添加的内容
return TRUE;
}


你应该使用SetTimer()的返回值,将它们存储在成员变量中,并在杀死计时器时传递它们:

 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 ;
}



当窗口关闭时也不要忘记杀掉计时器(例如在 OnClose())。


CProgressCtrl showing Debug Assert Failed

Please Check this code and help what is wrong

Header File

#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

// 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

解决方案

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

BOOL CFlashingProgressBar::OnInitDialog()
{
    SetTimer(EndDialogTimer,40*1000,NULL);
    SetTimer(CounterTimer,5*1000,NULL);
    UpdateData(FALSE); //This is what i added
    return TRUE;
}


You should use the return values of SetTimer() by storing them in member variables and pass these when killing the timer:

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()).


这篇关于CProgressCtrl显示Debug Assert失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆