CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 1999
    Posts
    6

    disabling/enableing button control

    I am trying simple thing of disabling and enabling button controls in dialog. Please give me some suggestion


  2. #2
    Guest

    Re: disabling/enableing button control

    To disable button:

    GetDlgItem(IDC_BUTTON_TEST)->EnableWindow(FALSE); /* TRUE to enable */





  3. #3
    Join Date
    Aug 1999
    Posts
    7

    Re: disabling/enableing button control

    You want to use CWnd::EnableWindow() to do this.



    void CDialog::somefunction()
    {
    CButton * myButton = (CButton *) this->GetDlgItem(idc);
    myButton->EnableWindow(true); // enable the button
    myButton->EnableWindow(false); // disable the button
    }




    idc is the IDC_ value for the control in question which you can get by going into the dialog resource editor and looking at the control's properties.


  4. #4
    Join Date
    Apr 1999
    Posts
    6

    Re: disabling/enableing button control

    Thanks for your help.


  5. #5
    Join Date
    Apr 1999
    Posts
    6

    Re: disabling/enableing button control

    Thanks alot for your help. I got it.


  6. #6
    Join Date
    Apr 1999
    Posts
    6

    Re: disabling/enableing button control

    I was also trying to create and destroy buttons.
    I tried using CButton::Create(). The button doesn't appear on the dialog box. And I do not know the reason. What is the right way of doing it


  7. #7
    Guest

    Re: disabling/enableing button control

    Make sure to have a member or global variable for the control (not local to the function).

    Example:

    m_Button1.Create("test", WS_CHILD|WS_VISIBLE,...

    or

    m_pButton1 = new CButton();
    m_pButton1->Create("test", WS_CHILD|WS_VISIBLE,...
    make sure to delete m_pButton1 when you don't need it anymore



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