Problem with the reference to (CTreeCtrlEx)

This is a discussion on Problem with the reference to (CTreeCtrlEx) within the Windows Programming forums, part of the Platform Specific Boards category; I have an MFC dialog which has a Tree(CTreeCtrlEx) structure where each node is a combo box. I want to ...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    5

    Problem with the reference to (CTreeCtrlEx)

    I have an MFC dialog which has a Tree(CTreeCtrlEx) structure where each node is a combo box.
    I want to have a "Cancel" button which will cancel the option chosen by the user and goes with
    the user chosen previosly.I have a cancel button but,as soon as the user changes the (CTreeCtrlEx)
    item,the values will be changed.

    Now all i want is to store the previous option and compared to DoModal return.and use the oprions
    accordingly.

    Currently, i am doing like this ,i have mentioned below
    OC_Dlg_PureMFC_Test_Options_c is a subclass of CTreeCtrlEx
    Code:
    
    OC_Dlg_PureMFC_Test_Options_c(m_Options).DoModal();  // m_Options is a reference...
    How will i save the previous m_Options?....Any idea?
    I tried doing the following ...


    Code:
    OC_TestOptions_Common_c *temp = new OC_TestOptions_Common_c(m_Options);
    OC_Dlg_PureMFC_Test_Options_c(m_Options).DoModal();  // m_Options is a reference...

    But i dont know how to turn it back to m_Options... can any one help me??

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    You would have to write an == (are these equal?) and = (make these equal) operator in/for the CTreeCtrlEx derived class.

    The == operator would run thru each node checking it exists and the text matches. It would return false (zero) as soon as it finds a difference.

    The = operator would run thru each node adding or updating the node (if required).


    Another, possibly easier, way is to store the TVITEM of the last edited node. This could be done within a derived CTreeCtrlEx class.

    Once the user has decided to edit a node (but before the combo is created) save the TVITEM info in a member variable .
    Code:
    //in header
    TVITEM    m_tvItem; // holds last edited TV node
    
    void CMyTreeCtrlEx::OnBeginLabelEdit (NMHDR* pNMHDR, LRESULT* pResult) 
    {
             NMTVDISPINFO *ptvDispInfo = (NMTVDISPINFO *)pNMHDR;
             CopyMemory(&m_tvItem, &ptvDispInfo->item, sizeof(TV_ITEM)); //copy the item being edited
             return CTreeCtrlEx::OnBeginLabelEdit(pNMHDR,pResult); //call the default processing
    }
    Then write a method in the derived CTreeCtrlEx to find this node and reset the text (called if the cancel button is pressed).
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    5

    Problem with reference

    Thanks for the reply...
    But i want to save the m_Options itself which would be a better solution... How to do that??


    Can i do anything with the help of DoDataExchange???


    or like this

    Code:
    a_Options=m_Options;
    	  OC_TestOptions_Common_c *temp = &m_Options;
          if( OC_Dlg_PureMFC_Test_Options_c(m_Options).DoModal() != IDOK)
    	  {
    			m_Options = (OC_TestOptions_Common_c&)temp;
    	  }

    But all these giving RUNTIME EXCEPTION.... Or compile time error


    please help....

    thanks

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    I need more info....

    These are custom classes, so I do not know what functionality is coded into them (what they do, how they interact).

    Nor do i know how complex they are, nor the process required to change them, etc.

    But will have a guess....



    You need a 'copy' (instance) of the 'OC_TestOptions_Common_c' class, not a pointer.
    A pointer to 'm_Options' will change when the user edits the 'm_Options'.


    Code:
    OC_TestOptions_Common_c TempOptions;
    
    TempOptions= &m_Options;//this will only work if the OC_TestOptions_Common_c class has an 'equals operator' method
    
    //show the user the treeview of options
    if( OC_Dlg_PureMFC_Test_Options_c(m_Options).DoModal() != IDOK)
    {
           m_Options =TempOptions;
    }
    I can see m_Options is an object of the class 'OC_TestOptions_Common_c'.

    Does the 'OC_TestOptions_Common_c' class have a equals operator method?
    [many standard classes (ie CString) have operators, your class may not have one]

    something like
    Code:
    //in header
    public:
    OC_TestOptions_Common_c operator=(OC_TestOptions_Common_c &Options);
    
    //in class
    OC_TestOptions_Common_c OC_TestOptions_Common_c::operator =(OC_TestOptions_Common_c &Options)
    {
           //set all the members of 'this' to the one we have been passed ('Options')
           //any members that are derived classes will need their own equals operator
           m_Option=Options.m_Option;
           m_SomeOtherOption=Options.SomeOtherOption;
           etc....
    }
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem creating .so
    By k0k33 in forum C Programming
    Replies: 7
    Last Post: 04-27-2009, 04:41 AM
  2. Learning functors problem. Pointer to reference
    By stumcd in forum C++ Programming
    Replies: 5
    Last Post: 10-21-2008, 02:32 PM
  3. A general quaetion on portability
    By kris.c in forum C Programming
    Replies: 7
    Last Post: 07-20-2006, 03:48 AM
  4. Student Having Problem With Reference Parameters
    By verd in forum C Programming
    Replies: 1
    Last Post: 04-19-2005, 11:19 PM
  5. Undefined Reference Problem
    By esilja in forum C++ Programming
    Replies: 1
    Last Post: 11-08-2001, 08:05 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21