CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Join Date
    Apr 2009
    Posts
    50

    HBRUSH assertion failure

    I'm trying to set a background color on a label. When I run get a assertion error listed below. C++ code and header listed below. Any recommendations?

    Assertion failure location:
    afxcmn.inl line 375

    _AFXCMN_INLINE void CSpinButtonCtrl::SetRange(int nLower, int nUpper)
    { ASSERT(::IsWindow(m_hWnd)); ::SendMessage(m_hWnd, UDM_SETRANGE, 0, MAKELPARAM(nUpper, nLower)); }


    C++ code
    HBRUSH CListMngr::CtlColor(CDC* pDC, UINT nCtlColor)
    {
    switch (nCtlColor)
    {
    case IDC_COLOR_LABEL:
    pDC->SetTextColor(RGB(255,255,255) );
    return (HBRUSH)( m_pBkBrushMe->GetSafeHandle() );
    }
    pDC->SetTextColor( RGB( 200, 200, 0 ) );
    pDC->SetBkColor( RGB( 0, 0, 0 ) );
    return (HBRUSH)( m_pBkBrushMe->GetSafeHandle() );
    }

    BEGIN_MESSAGE_MAP(CListMngr, CFormView)

    ON_WM_CTLCOLOR_REFLECT()

    END_MESSAGE_MAP()

    Header file
    //{{AFX_MSG(CListMngr)
    afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
    //}}AFX_MSG

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: HBRUSH assertion failure

    How is "m_pBkBrushMe" declared? is it a valid GDIObject at the time WM_CTLCOLOR is handled?

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: HBRUSH assertion failure

    CSpinButtonCtrl::SetRange

    I think your assumption of the cause is incorrect

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: HBRUSH assertion failure

    I agree with GCDEF.
    crxcte, when and where from do you call CSpinButtonCtrl::SetRange method?
    Victor Nijegorodov

  5. #5
    Join Date
    Apr 2009
    Posts
    50

    Re: HBRUSH assertion failure

    I searched my project and I never call CSpinButtonCtrl or CSpinButtonCtrl::SetRange. CSpinButtonCtrl was found in:
    ...MFC\INCLUDE\AFXCMN.H(394):class CSpinButtonCtrl : public CWnd

    CSpinButtonCtrl::SetRange was found in:
    ...MFC\INCLUDE\AFXCMN.INL(374):_AFXCMN_INLINE void CSpinButtonCtrl::SetRange(int nLower, int nUpper)
    ...MFC\INCLUDE\AFXCMN2.INL(28):_AFXCMN_INLINE void CSpinButtonCtrl::SetRange32(int nLower, int nUpper)


    I declare m_pBkBrushMe:
    Class CListMnge : public CFormView
    Public:
    CBrush* m_pBkBrushMe;

  6. #6
    Join Date
    Apr 1999
    Posts
    27,449

    Re: HBRUSH assertion failure

    Quote Originally Posted by crxcte View Post
    I searched my project and I never call CSpinButtonCtrl or CSpinButtonCtrl::SetRange.
    Searching your code is not the ideal way to find out who is calling that function. You should be using the call stack.

    Run the program, and when the assertion occurs, look at the call stack. One function in the call stack must be yours. That is the function that is triggering the error.

    Regards,

    Paul McKenzie

  7. #7
    Join Date
    Apr 2009
    Posts
    50

    Re: HBRUSH assertion failure

    The call stack had before the CSpinButtonCtrl::SetRange was CListMngr::OnInitialUpdate() line 248. On that line was m_responseTimeoutSpin.SetBase( 10 );.

    I commented out that line and reran the code and assertion failed again. CListMngr::OnInitialUpdate() line 249.

    I commented out that line and reran the code and assertion failed again. CListMngr::OnInitialUpdate() line 250.

    Call Stack:
    CSpinButtonCtrl::SetRange(int 5, int 60) line 375 + 46 bytes
    CListMngr::OnInitialUpdate() line 250
    CWnd::OnWndMsg(unsigned int 868, unsigned int 0, long 0, long * 0x0012fa8c) line 1825
    CWnd::WindowProc(unsigned int 868, unsigned int 0, long 0) line 1585 + 30 bytes
    AfxCallWndProc(CWnd * 0x00453c40 {CListMngr hWnd=???}, HWND__ * 0x0092076a, unsigned int 868, unsigned int 0, long 0) line 215 + 26 bytes
    CWnd::SendMessageToDescendants(HWND__ * 0x00400610, unsigned int 868, unsigned int 0, long 0, int 1, int 1) line 2309
    CWnd::SendMessageToDescendants(HWND__ * 0x006f066a, unsigned int 868, unsigned int 0, long 0, int 1, int 1) line 2320
    CWnd::SendMessageToDescendants(unsigned int 868, unsigned int 0, long 0, int 1, int 1) line 146 + 32 bytes
    CFrameWnd::InitialUpdateFrame(CDocument * 0x004526f0 {CRMMDoc}, int 1) line 749

    I noticed below in the call stack the line with hWnd=??? I set HBRUSH like,
    HBRUSH CListMngr::CtlColor(CDC* pDC, UINT nCtlColor) but have seen it set like
    HBRUSH CSiteListMngr::CtlColor(CDC* pDC, WND* pWnd, UINT nCtlColor)

    I've tried setting HBRUSH on the later but still have the same issue with assertion failure.

  8. #8
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: HBRUSH assertion failure

    Read carefully. The problem is not the brush.

    It's here. CListMngr::OnInitialUpdate() line 250

    Pleas post lines 245 through 255.

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: HBRUSH assertion failure

    Quote Originally Posted by GCDEF View Post
    Read carefully. The problem is not the brush.

    It's here. CListMngr::OnInitialUpdate() line 250

    Pleas post lines 245 through 255.
    I agree again.
    however, I'd like to see the lines from the beginning of
    CListMngr::OnInitialUpdate() line 250
    and up to at least the base class OnInitialUpdate() call...
    Victor Nijegorodov

  10. #10
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: HBRUSH assertion failure

    Quote Originally Posted by VictorN View Post
    I agree again.
    however, I'd like to see the lines from the beginning of and up to at least the base class OnInitialUpdate() call...
    More than likely the end result of this is going to be a call to SetRange before the base class OnInitialUpdate(). Since it's pointing to line 250, that call is probably on line 250 or really close to it.

  11. #11
    Join Date
    Apr 2009
    Posts
    50

    Re: HBRUSH assertion failure

    void CListMngr::OnInitialUpdate()
    {
    CFormView::OnInitialUpdate();
    CString colTitle;
    colTitle.LoadString( IDS_COL_SITEID );
    m_slCtrl.InsertColumn( COLPOS_SITEID, colTitle );
    colTitle.LoadString( IDS_COL_SITENAME );
    m_slCtrl.InsertColumn( COLPOS_SITENAME, colTitle );
    colTitle.LoadString( IDS_COL_SITESTATE );
    m_slCtrl.InsertColumn( COLPOS_SITESTATE, colTitle );
    colTitle.LoadString( IDS_COL_SITEPHONE );
    m_slCtrl.InsertColumn( COLPOS_SITEPHONE, colTitle,
    m_slCtrl.GetStringWidth(colTitle)*3 );

    m_stateImageList.Create( IDB_STATEICON, 16, 1, RGB( 255, 0, 0 ) );
    m_slCtrl.SetImageList( &m_stateImageList, LVSIL_STATE );
    m_slCtrl.m_bHasStateIcons = TRUE;
    m_slCtrl.DefineSortProcess( (PFNLVCOMPARE)SortProc );
    FillListCtrl();
    sSortInfo sort = { 0, SORT_ASCENDING };
    m_slCtrl.Sort( sort );

    CSplitFrame* pSplitFrame = (CSplitFrame*) AfxGetMainWnd();
    m_pTapi = &(pSplitFrame->m_tapi);
    SetSLMngrWnd( m_hWnd );
    OnUpdateSysParams( 0, (LPARAM)(&(pSplitFrame->m_sysParams)) );

    m_checkAutoDialTimerID = SetTimer( IDT_CHK_AUTODIAL_TIME,CHK_AUTODIAL_TIME_TIME_INTRVL, NULL );

    m_autoDialInProgressStat.SetSel( 0, -1 );
    m_autoDialInProgressStat.ReplaceSel( " " );
    GetDlgItem( IDC_TERMINATE_AD )->ShowWindow( SW_HIDE );

    m_delayTimeSpin.SetRange( MIN_RMMENTRY_DELAYTIME, MAX_RMMENTRY_DELAYTIME );
    m_delayTimeSpin.SetBase( 10 );
    m_delayTimeSpin.SetPos( m_delayTime );
    m_responseTimeoutSpin.SetRange( MIN_RESPONSE_TIMEOUT, MAX_RESPONSE_TIMEOUT );
    m_responseTimeoutSpin.SetBase( 10 );
    m_responseTimeoutSpin.SetPos( m_responseTimeout );
    m_dialRetriesSpin.SetRange( MIN_RETRIES, MAX_RETRIES );
    m_dialRetriesSpin.SetBase( 10 );
    m_dialRetriesSpin.SetPos( m_dialRetries );
    m_dialDTP.SetFormat( "HH':'mm" );
    m_dialDTP.SetTime( &m_dialTime );

    SetDlgItemText(IDC_AUTO_DIAL_PW, m_autoDialPassword);

    UpdateData( FALSE );
    }

  12. #12
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: HBRUSH assertion failure

    Quote Originally Posted by crxcte View Post
    void CListMngr::OnInitialUpdate()
    {
    CFormView::OnInitialUpdate();
    CString colTitle;
    colTitle.LoadString( IDS_COL_SITEID );
    m_slCtrl.InsertColumn( COLPOS_SITEID, colTitle );
    colTitle.LoadString( IDS_COL_SITENAME );
    m_slCtrl.InsertColumn( COLPOS_SITENAME, colTitle );
    colTitle.LoadString( IDS_COL_SITESTATE );
    m_slCtrl.InsertColumn( COLPOS_SITESTATE, colTitle );
    colTitle.LoadString( IDS_COL_SITEPHONE );
    m_slCtrl.InsertColumn( COLPOS_SITEPHONE, colTitle,
    m_slCtrl.GetStringWidth(colTitle)*3 );

    m_stateImageList.Create( IDB_STATEICON, 16, 1, RGB( 255, 0, 0 ) );
    m_slCtrl.SetImageList( &m_stateImageList, LVSIL_STATE );
    m_slCtrl.m_bHasStateIcons = TRUE;
    m_slCtrl.DefineSortProcess( (PFNLVCOMPARE)SortProc );
    FillListCtrl();
    sSortInfo sort = { 0, SORT_ASCENDING };
    m_slCtrl.Sort( sort );

    CSplitFrame* pSplitFrame = (CSplitFrame*) AfxGetMainWnd();
    m_pTapi = &(pSplitFrame->m_tapi);
    SetSLMngrWnd( m_hWnd );
    OnUpdateSysParams( 0, (LPARAM)(&(pSplitFrame->m_sysParams)) );

    m_checkAutoDialTimerID = SetTimer( IDT_CHK_AUTODIAL_TIME,CHK_AUTODIAL_TIME_TIME_INTRVL, NULL );

    m_autoDialInProgressStat.SetSel( 0, -1 );
    m_autoDialInProgressStat.ReplaceSel( " " );
    GetDlgItem( IDC_TERMINATE_AD )->ShowWindow( SW_HIDE );

    m_delayTimeSpin.SetRange( MIN_RMMENTRY_DELAYTIME, MAX_RMMENTRY_DELAYTIME );
    m_delayTimeSpin.SetBase( 10 );
    m_delayTimeSpin.SetPos( m_delayTime );
    m_responseTimeoutSpin.SetRange( MIN_RESPONSE_TIMEOUT, MAX_RESPONSE_TIMEOUT );
    m_responseTimeoutSpin.SetBase( 10 );
    m_responseTimeoutSpin.SetPos( m_responseTimeout );
    m_dialRetriesSpin.SetRange( MIN_RETRIES, MAX_RETRIES );
    m_dialRetriesSpin.SetBase( 10 );
    m_dialRetriesSpin.SetPos( m_dialRetries );
    m_dialDTP.SetFormat( "HH':'mm" );
    m_dialDTP.SetTime( &m_dialTime );

    SetDlgItemText(IDC_AUTO_DIAL_PW, m_autoDialPassword);

    UpdateData( FALSE );
    }
    It's one of them. Which is line 250?

  13. #13
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: HBRUSH assertion failure

    I believe that when you break on ASSERT(), the stack pointer in the calling function wll be on the NEXT line, so look one line up.
    That BTW explains your "moving" target..
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  14. #14
    Join Date
    Apr 2009
    Posts
    50

    Re: HBRUSH assertion failure

    m_responseTimeoutSpin.SetBase( 10 );

    9 lines up from the bottom. I removed the lines commented out so it error on the stack points to line 248.

    Stack:

    CSpinButtonCtrl::SetRange(int 5, int 60) line 375 + 46 bytes
    CListMngr::OnInitialUpdate() line 248
    CWnd::OnWndMsg(unsigned int 868, unsigned int 0, long 0, long * 0x0012fa8c) line 1825
    CWnd::WindowProc(unsigned int 868, unsigned int 0, long 0) line 1585 + 30 bytes
    AfxCallWndProc(CWnd * 0x00453c40 {CListMngr hWnd=???}, HWND__ * 0x002e0898, unsigned int 868, unsigned int 0, long 0) line 215 + 26 bytes
    CWnd::SendMessageToDescendants(HWND__ * 0x003408be, unsigned int 868, unsigned int 0, long 0, int 1, int 1) line 2309
    CWnd::SendMessageToDescendants(HWND__ * 0x00290870, unsigned int 868, unsigned int 0, long 0, int 1, int 1) line 2320
    CWnd::SendMessageToDescendants(unsigned int 868, unsigned int 0, long 0, int 1, int 1) line 146 + 32 bytes

  15. #15
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: HBRUSH assertion failure

    Quote Originally Posted by crxcte View Post
    I searched my project and I never call CSpinButtonCtrl or CSpinButtonCtrl::SetRange.
    Really?
    Then what is it:
    Quote Originally Posted by crxcte View Post
    Code:
    void CListMngr::OnInitialUpdate() 
    { 
    	CFormView::OnInitialUpdate();
    ...
    	m_delayTimeSpin.SetRange( MIN_RMMENTRY_DELAYTIME, MAX_RMMENTRY_DELAYTIME );
            ...
    	m_responseTimeoutSpin.SetRange( MIN_RESPONSE_TIMEOUT, MAX_RESPONSE_TIMEOUT );
            ...
    	m_dialRetriesSpin.SetRange(MIN_RETRIES, MAX_RETRIES );
    Aren't all these controls not the Spin controls?
    Victor Nijegorodov

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured