CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Guest

    how disable button ?


    how can i disable a CButton object ?
    i know how to disalbe CImageButton
    but it not working in the CButton.
    i use dialog project .

    pascal!





  2. #2
    Guest

    Re: how disable button ?

    GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE);

    where IDC_BUTTON1 is the control ID of the button to be disabled.


  3. #3
    Guest

    Re: how disable button ?

    If you have a member variable associated with the button, you can also do this:

    CButton m_ButtonOne

    m_ButtonOne.EnableWindow(TRUE);

    if(m_ButtonOne.IsWindowEnabled())
    m_ButtonOne.EnableWindow(FALSE);

    // etc.





  4. #4
    Join Date
    Aug 1999
    Location
    Ontario, Canada
    Posts
    2

    Re: how disable button ?

    If you want to disable the button on startup, just use the resource editor to disable the button (go to properties, and click on the DISABLE checkbox) - This is provided you are using some version of VC++. If you aren't, you will have to disable the button using the method explained in the first reply. (I just thought this way would be easier if you are using VC++).

    And to disable/enable the button during the program, I usually do this:

    CButton* pBut = static_cast<CButton*>(GetDlgItem(IDC_BUTTON1));
    pBut->EnableWindow(TRUE);
    pBut->EnableWindow(FALSE);

    where IDC_BUTTON1 is the resource ID name.
    Hope that helps.


  5. #5
    Join Date
    Jul 1999
    Location
    Uitca, NY
    Posts
    120

    Re: how disable button ?

    I assume that your button has an ID associated with it and you are using Visual Studio for development. Here is the most conventional process, step by step. First, in your view class use ClassWizard to select your button ID from your Object ID's list. Then use ClassWizard to create an update handler function by selecting UPDATE_COMMAND_UI from the Messages: list. Your new function will be named CxxxView::OnUpdateXxxx with Xxxx being your button ID. Next inside the new function create and if() statement with the condition being whatever turns your button on/off (your choice) and an else statement for the opposite condition. Then inside the enable part of the if/else pair put the statement pCmdUI->Enable( TRUE ); and in the other section of your if/else pair put pCmdUI->Enable( FALSE );
    These statements are exact. pCmdUI is the pointer sent to the handler by Windows. Here is an example I use to enable/disable a menu item/toolbar button:

    void CMandelbrotView::OnUpdateRetrieve5(CCmdUI* pCmdUI)
    {
    // If the parameter array is in use then enable it.
    if ( parameterArray.GetSize() > 4 )
    pCmdUI->Enable( TRUE );
    else
    pCmdUI->Enable( FALSE );
    }



    This enables/disables the object based on the size of an array.
    HTH.


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