Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Assertion failure While Editing CTreeView Label.

Assertion failure While Editing CTreeView Label.

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shanmugarajaa
    wrote on last edited by
    #1

    Dear Friend, After adding all necessary message handler to support to edit label in CTreeView

    void CMyTreeView::OnBeginLabelEdit( NMHDR* /*pNMHDR*/, LRESULT* pResult)
    {
    // This is the Limit the size of the Tag Name to 127
    CTreeCtrl &ctlFiles = GetTreeCtrl();
    ctlFiles.GetEditControl()->LimitText( 127 );
    *pResult = 0;
    }

    void CMyTreeView::OnEndLabelEdit( NMHDR * pNMHDR, LRESULT * pResult )
    {
    *pResult = TRUE;
    }

    BOOL CMyTreeView::PreTranslateMessage(MSG* pMsg)
    {

    if ( pMsg->message == WM\_KEYDOWN )
    {
    	CTreeCtrl &ctlFiles = GetTreeCtrl();
    	CEdit\* edit = ctlFiles.GetEditControl();
    	if (edit)
    	{
    		if( GetKeyState( VK\_CONTROL ) && pMsg->wParam == VK\_C )
    		{
    			edit->Copy();
    			return TRUE;
    		}
    		if( GetKeyState( VK\_CONTROL ) && pMsg->wParam == VK\_V )
    		{
    			edit->Paste();
    			return TRUE;
    		}
    		if( GetKeyState( VK\_CONTROL ) && pMsg->wParam == VK\_X )
    		{
    			edit->Cut();
    			return TRUE;
    		}
    		if( GetKeyState( VK\_CONTROL ) && pMsg->wParam == VK\_Z )
    		{
    			edit->Undo();
    			return TRUE;
    		}
    		if( pMsg->wParam == VK\_RETURN || pMsg->wParam == VK\_ESCAPE || pMsg->wParam == VK\_CONTROL || pMsg->wParam == VK\_INSERT )
    		{
    			edit->SendMessage(WM\_KEYDOWN, pMsg->wParam, pMsg->lParam);
    			return TRUE;
    		}
    	}
    }
    return CTreeView::PreTranslateMessage(pMsg);
    

    }

    If I press a character 'a' to 'z' and 'A' to 'z' then MFC throwing Assertion. I don't know what I am missing out to avoid this issue. Kindly help me on this. Thanks, S Shanmuga Raja

    J D _ 3 Replies Last reply
    0
    • S shanmugarajaa

      Dear Friend, After adding all necessary message handler to support to edit label in CTreeView

      void CMyTreeView::OnBeginLabelEdit( NMHDR* /*pNMHDR*/, LRESULT* pResult)
      {
      // This is the Limit the size of the Tag Name to 127
      CTreeCtrl &ctlFiles = GetTreeCtrl();
      ctlFiles.GetEditControl()->LimitText( 127 );
      *pResult = 0;
      }

      void CMyTreeView::OnEndLabelEdit( NMHDR * pNMHDR, LRESULT * pResult )
      {
      *pResult = TRUE;
      }

      BOOL CMyTreeView::PreTranslateMessage(MSG* pMsg)
      {

      if ( pMsg->message == WM\_KEYDOWN )
      {
      	CTreeCtrl &ctlFiles = GetTreeCtrl();
      	CEdit\* edit = ctlFiles.GetEditControl();
      	if (edit)
      	{
      		if( GetKeyState( VK\_CONTROL ) && pMsg->wParam == VK\_C )
      		{
      			edit->Copy();
      			return TRUE;
      		}
      		if( GetKeyState( VK\_CONTROL ) && pMsg->wParam == VK\_V )
      		{
      			edit->Paste();
      			return TRUE;
      		}
      		if( GetKeyState( VK\_CONTROL ) && pMsg->wParam == VK\_X )
      		{
      			edit->Cut();
      			return TRUE;
      		}
      		if( GetKeyState( VK\_CONTROL ) && pMsg->wParam == VK\_Z )
      		{
      			edit->Undo();
      			return TRUE;
      		}
      		if( pMsg->wParam == VK\_RETURN || pMsg->wParam == VK\_ESCAPE || pMsg->wParam == VK\_CONTROL || pMsg->wParam == VK\_INSERT )
      		{
      			edit->SendMessage(WM\_KEYDOWN, pMsg->wParam, pMsg->lParam);
      			return TRUE;
      		}
      	}
      }
      return CTreeView::PreTranslateMessage(pMsg);
      

      }

      If I press a character 'a' to 'z' and 'A' to 'z' then MFC throwing Assertion. I don't know what I am missing out to avoid this issue. Kindly help me on this. Thanks, S Shanmuga Raja

      J Offline
      J Offline
      jeron1
      wrote on last edited by
      #2

      Which line does it occur on when you step through it, and what is the assertion being hit?

      "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

      1 Reply Last reply
      0
      • S shanmugarajaa

        Dear Friend, After adding all necessary message handler to support to edit label in CTreeView

        void CMyTreeView::OnBeginLabelEdit( NMHDR* /*pNMHDR*/, LRESULT* pResult)
        {
        // This is the Limit the size of the Tag Name to 127
        CTreeCtrl &ctlFiles = GetTreeCtrl();
        ctlFiles.GetEditControl()->LimitText( 127 );
        *pResult = 0;
        }

        void CMyTreeView::OnEndLabelEdit( NMHDR * pNMHDR, LRESULT * pResult )
        {
        *pResult = TRUE;
        }

        BOOL CMyTreeView::PreTranslateMessage(MSG* pMsg)
        {

        if ( pMsg->message == WM\_KEYDOWN )
        {
        	CTreeCtrl &ctlFiles = GetTreeCtrl();
        	CEdit\* edit = ctlFiles.GetEditControl();
        	if (edit)
        	{
        		if( GetKeyState( VK\_CONTROL ) && pMsg->wParam == VK\_C )
        		{
        			edit->Copy();
        			return TRUE;
        		}
        		if( GetKeyState( VK\_CONTROL ) && pMsg->wParam == VK\_V )
        		{
        			edit->Paste();
        			return TRUE;
        		}
        		if( GetKeyState( VK\_CONTROL ) && pMsg->wParam == VK\_X )
        		{
        			edit->Cut();
        			return TRUE;
        		}
        		if( GetKeyState( VK\_CONTROL ) && pMsg->wParam == VK\_Z )
        		{
        			edit->Undo();
        			return TRUE;
        		}
        		if( pMsg->wParam == VK\_RETURN || pMsg->wParam == VK\_ESCAPE || pMsg->wParam == VK\_CONTROL || pMsg->wParam == VK\_INSERT )
        		{
        			edit->SendMessage(WM\_KEYDOWN, pMsg->wParam, pMsg->lParam);
        			return TRUE;
        		}
        	}
        }
        return CTreeView::PreTranslateMessage(pMsg);
        

        }

        If I press a character 'a' to 'z' and 'A' to 'z' then MFC throwing Assertion. I don't know what I am missing out to avoid this issue. Kindly help me on this. Thanks, S Shanmuga Raja

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        shanmugarajaa wrote:

        ...MFC throwing Assertion.

        Exactly what assertion is being thrown?

        shanmugarajaa wrote:

        Kindly help me on this.

        Have you stepped through the code using the debugger?

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        1 Reply Last reply
        0
        • S shanmugarajaa

          Dear Friend, After adding all necessary message handler to support to edit label in CTreeView

          void CMyTreeView::OnBeginLabelEdit( NMHDR* /*pNMHDR*/, LRESULT* pResult)
          {
          // This is the Limit the size of the Tag Name to 127
          CTreeCtrl &ctlFiles = GetTreeCtrl();
          ctlFiles.GetEditControl()->LimitText( 127 );
          *pResult = 0;
          }

          void CMyTreeView::OnEndLabelEdit( NMHDR * pNMHDR, LRESULT * pResult )
          {
          *pResult = TRUE;
          }

          BOOL CMyTreeView::PreTranslateMessage(MSG* pMsg)
          {

          if ( pMsg->message == WM\_KEYDOWN )
          {
          	CTreeCtrl &ctlFiles = GetTreeCtrl();
          	CEdit\* edit = ctlFiles.GetEditControl();
          	if (edit)
          	{
          		if( GetKeyState( VK\_CONTROL ) && pMsg->wParam == VK\_C )
          		{
          			edit->Copy();
          			return TRUE;
          		}
          		if( GetKeyState( VK\_CONTROL ) && pMsg->wParam == VK\_V )
          		{
          			edit->Paste();
          			return TRUE;
          		}
          		if( GetKeyState( VK\_CONTROL ) && pMsg->wParam == VK\_X )
          		{
          			edit->Cut();
          			return TRUE;
          		}
          		if( GetKeyState( VK\_CONTROL ) && pMsg->wParam == VK\_Z )
          		{
          			edit->Undo();
          			return TRUE;
          		}
          		if( pMsg->wParam == VK\_RETURN || pMsg->wParam == VK\_ESCAPE || pMsg->wParam == VK\_CONTROL || pMsg->wParam == VK\_INSERT )
          		{
          			edit->SendMessage(WM\_KEYDOWN, pMsg->wParam, pMsg->lParam);
          			return TRUE;
          		}
          	}
          }
          return CTreeView::PreTranslateMessage(pMsg);
          

          }

          If I press a character 'a' to 'z' and 'A' to 'z' then MFC throwing Assertion. I don't know what I am missing out to avoid this issue. Kindly help me on this. Thanks, S Shanmuga Raja

          _ Offline
          _ Offline
          _Flaviu
          wrote on last edited by
          #4

          You should avoid overriding PreTranslateMessage ... in your case, you can solve more elegant your task overriding WM_CUT[^], WM_COPY[^], and WM_PASTE[^].

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups