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

    Disabling Buttons

    how can I disable and enable command buttons in a simple dialog at runtime? I can´t find some kind of an instance name for a command button (the idname IDC_MYBUTTON surely doesn´t do it) that´s of any use. Besides, I can´t even find a suitable CButton:isable/Enable command.
    What can i do?


  2. #2
    Join Date
    May 1999
    Location
    CA, USA
    Posts
    586

    Re: Disabling Buttons

    Well in ClassWizard create a member variable of type Control for your button... This will create a member variable of type CButton in the header of your CDialog derived class. CButton is derived from CWnd, so through inheritance it inherits all of CWnd's functions, including EnableWindow().

    So say you create a member variable in ClassWizard of type Control and name it m_CtrlButton, you can enable and disable it using the following code:

    m_CtrlButton.EnableWindow(TRUE); // Enable

    m_CtrlButton.EnableWindow(FALSE); // Disable


    Rail

    Recording Engineer/Software Developer
    Rail Jon Rogut Software
    [email protected]
    http://home.earthlink.net/~railro/

  3. #3
    Join Date
    Jul 1999
    Location
    Romania - Iasi
    Posts
    558

    Re: Disabling Buttons

    You can enable and disable it using the following code:


    CWnd *pWndCtrl = GetDlgItem( ID_of your button)
    pWndCtrl->EnableWindow( TRUE ) //Enable

    pWndCtrl->EnableWindow( FALSE ) //Enable



    In this way you can Enable/Disable any control from a dialog






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

    Re: Disabling Buttons

    From the ProgramView.cpp file - use class wizard to select the IDC_xxx for the button in the CProgramView Object ID's window and UPDATE_COMMAND_UI in the Messages window. Create the function framework as ClassWizard requests. The function name will be CProgramView::OnUpdateControlName. Then see the code below for an example for a button with the ID of ID_RETRIEVE_1.

    void CMandelbrotView::OnUpdateRetrieve1(CCmdUI* pCmdUI)
    {
    // Programmer supplied code
    if ( // Enable condition here // )
    pCmdUI->Enable( TRUE );
    else
    pCmdUI->Enable( FALSE );
    // End programmer supplied code
    }




    The class wizard supplies the pointer to the ID in the call. The pCmdUI pointer automatically points to the proper control ID. The Enable call either enables or disables the control. This uses ClassWizard features to reduce the chance for programmer error.


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