CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2000
    Posts
    21

    How to enable buttons in my view ?

    Hi everybody,

    Here a strange problem for me.

    In the OnInitialUpdate of my CView class, I disable buttons and control lists because no data is loaded.

    When the user opens a file, in my CMyDoc::Serialize function, I tell my view to enable buttons. But it doesn't work. Look at this code.

    void CMyDoc::Serialize(...)
    {
    if(!ar.IsStoring())
    {
    ...
    POSITION pos = GetFirstViewPosition();
    CMyView* pView = (CMyView*) GetNextView(pos);
    pView->EnableTheControls();
    }
    }
    ...
    void CMyView::EnableTheControls()
    {
    CButton* pButton = (CButton*) GetDlgItem(IDC_BUTTON);
    pButton->EnableWindow(TRUE);
    }

    The code below doesn't work, the controls are still disable. Can someone tell me why ? I try the UpdateWindow() function also in the CMyView function but I don't get anything more. Please help !


  2. #2
    Join Date
    Apr 2001
    Location
    San Diego CA
    Posts
    378

    Re: How to enable buttons in my view ?

    Put breakpoints and observe if they are getting called in the right sequence. Step through your code and verify that EnableTheControls() is being called.



    Rating Helps!!
    þ|êâšë rä†è rëþ|ïëš †hª† hë|þëd

  3. #3
    Join Date
    Apr 2002
    Posts
    36

    Re: How to enable buttons in my view ?

    check if u have disabled the buttons in the base class and enabling them in the derived class.



  4. #4
    Join Date
    Mar 2001
    Location
    Colorado
    Posts
    241

    Re: How to enable buttons in my view ?

    The correct way to do this is to handle the OnSyncToDoc() message in your view. In OnSyncToDoc() you need to add your view to the document, and then this is where you will want to disable/enable your buttons.


    LRESULT CYourClass::OnSyncToDoc(WPARAM wParam, LPARAM lParam)
    {
    CDocument* pNewDoc = lParam;
    CDocument* pDoc = NULL;
    BOOL bClosing = (BOOL)wParam;

    //newdoc may be NULL
    ASSERT_VALID(pNewDoc)
    CDocument* pCurDoc = GetDocument();

    if(pNewDoc)
    //If we have a new doc use it.
    pDoc = pNewDoc;
    else
    {
    //Otherwize, use the current doc.
    if(pCurDoc)
    pDoc = pCurDoc;
    }

    if(bClosing)
    {
    //pNewDoc != pCurDoc if already changed to doc of another Eds4View
    if(pCurDoc && (pNewDoc == pCurDoc || !pNewDoc))
    {
    pCurDoc->RemoveView(this);
    UpdateToDoc();
    }
    EnableTheControls(FALSE) //Disable
    }
    else if(pNewDoc != pCurDoc)
    {
    if(pCurDoc)
    pCurDoc->RemoveView(this);
    if(pNewDoc)
    {
    pNewDoc->AddView(this);
    EnableTheControls();

    }
    }
    return 0; //result has no meaning
    }




    Hope that helps! Good luck.

    Wade

  5. #5
    Join Date
    Mar 2000
    Posts
    21

    Sorry, I can't do it

    Hi,


    Thanks for your help. I can't find any documentation above the OnSyncToDoc function.

    And I cannot compile it correctly because the UpdateToDoc function doesn't exist.

    Can you give me more details above your code please ? Thx.


  6. #6
    Join Date
    Mar 2000
    Posts
    21

    Another bug

    Another bug in my program.

    In the OnInitialUpdate function of my view class, I add columns in a list control. When the user (me) opens a file, this function is called once again and it adds once again columns in the list control. Of course, I can remember if it is the first time or not that the function is called, but I would like to know if this is normal or not.


  7. #7
    Join Date
    Mar 2000
    Posts
    21

    I just understand the problem now

    Well, I can understand why the controls can't be enabled in my program.

    It's simply because I disable them in the OnInitialUpdate function of my view class. But I didn't know that this function is called each time a user opens a file. So, even if I enable them in another function, OnInitialUpdate is called after all and disable the controls.

    Where can I initialize my controls if OnInitialUpdate is called not one time (as I thought first) but many times during the execution of the application ?

    Thx.


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