本文介绍了CProgressCtrl显示Debug Assert失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 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() // 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 FailedPlease Check this code and help what is wrongHeader File#pragma once#include "afxcmn.h"#include "afxwin.h"// CFlashingProgressBar dialogclass 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 supportpublic: 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 dialogint m_Counter;//Counter timerDECLARE_MESSAGE_MAP()};c++ File// FlashingProgressBar.cpp : implementation file//#include "stdafx.h"#include "AutoVbiosFlash.h"#include "FlashingProgressBar.h"#include "afxdialogex.h"#define EndDialogTimer1001#define CounterTimer1002int i=0;// CFlashingProgressBar dialogIMPLEMENT_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 handlersBOOL 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失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-08 16:51