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

    How to enable\disable a button at runtime

    Im new to VC++ and I've been wondering how you can enable\disable a button at runtime. For example I would like to disable a button(I'm not talking about a toolbar button) when a text box is blank and enable it when a user enters text (like the Run program in the start menu). I think that it has something to do with the EnableButton function, but im not really sure. Thanks for the help.


  2. #2
    Join Date
    Aug 1999
    Posts
    427

    Re: How to enable\disable a button at runtime

    You have to get a pointer to your button and after this use
    pBut->EnableWindow(FALSE);


  3. #3
    Guest

    Re: How to enable\disable a button at runtime

    When you make a pointer to your button you do this in classwizard under member variables right? Because when I do that, i get the following compile errors:

    error C2819: type 'CButton' does not have an overloaded member 'operator ->'
    error C2227: left of '->EnableButton' must point to class/struct/union

    Thanks.


  4. #4
    Join Date
    Aug 1999
    Posts
    427

    Re: How to enable\disable a button at runtime

    I assume that we are somewhwre in your class dialog wich contain your button

    CButton* pBut=(CButon*)GetDlgItem(IDC_BUTTON);
    pBut->EnableWindow(FALSE);
    of corse IDC_BUTTON is ID of your button, you may check for its name in resurs editor.


  5. #5
    Guest

    Re: How to enable\disable a button at runtime

    Thanks for you help. It worked. But I have one more thing to ask. How do you make it so you can toggle it? Like when you click on one button to enable or disable it.

    Thanks.


  6. #6
    Join Date
    Aug 1999
    Posts
    8

    Re: How to enable\disable a button at runtime

    If you create a member variable (m_button for example) from Class Wizard, you have to enter:

    m_button.EnableWindow(FALSE);



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