How do I Enable / Disable button in Dialog Bar? 
Author Message
 How do I Enable / Disable button in Dialog Bar?

I have a dialog bar that I inserted into my program.  It consists of a push
button and an Edit Box.  I'm trying to figure out how to disable the push button
when there are no characters in the Edit Box and enable it when there are.  I'm
handling the ON_EN_CHANGE message for the Edit Box with the following code.  It
checks if the Edit Box has text, it gets the window handle of the button, but
how do I disable / enable the button????

void CMainFrame::OnChangeEdit1()
{
        CString strFubar;
        CWnd *cwnd;
        m_wndMyDialogBar.GetDlgItemText(IDC_EDIT1,strFubar);
        if (strFubar.IsEmpty())         // Disable pushbutton if string is empty
        {
                cwnd = m_wndMyDialogBar.GetDlgItem(IDC_BUTTON1);
// How do I disable the button here?
        }
        else
        {
                cwnd= m_wndMyDialogBar.GetDlgItem(IDC_BUTTON1);
// How do I enable the button here?
        }

Quote:
}

Thanks in advance for ANY help!!!

Rick Suntag
New Visual C++ programmer (as if you couldn't have guessed)!!!

      \\\//
      (o o)
---ooO-(_)-Ooo-------------------+--------------------------------------
   Rick Suntag                   | Senior Technical Staff Member


voice: 201.331.4806              | Room B3B10
fax:   201.331.4635              | Parsippany, NJ 07054
---------------------------------+--------------------------------------



Sat, 30 Oct 1999 03:00:00 GMT  
 How do I Enable / Disable button in Dialog Bar?



Quote:
> I have a dialog bar that I inserted into my program.  It consists of a
push
> button and an Edit Box.  I'm trying to figure out how to disable the push
button
> when there are no characters in the Edit Box and enable it when there
are.  I'm
> handling the ON_EN_CHANGE message for the Edit Box with the following
code.  It
> checks if the Edit Box has text, it gets the window handle of the button,
but
> how do I disable / enable the button????

>       \\\//
>       (o o)
> ---ooO-(_)-Ooo-------------------+--------------------------------------
>    Rick Suntag                   | Senior Technical Staff Member


> voice: 201.331.4806              | Room B3B10
> fax:   201.331.4635              | Parsippany, NJ 07054
> ---------------------------------+--------------------------------------

I move that if this group ever has a FAQ, that this question be number 1.
Not a slight in your direction, Rick, it just gets asked A LOT!
The CButton class is derived from CWnd. It inherits all of the methods of
CWnd. One of these
methods is EnableWindow. Check it out in the help files for details.

Dennis Jump        



Sun, 31 Oct 1999 03:00:00 GMT  
 How do I Enable / Disable button in Dialog Bar?


Quote:



>> I have a dialog bar that I inserted into my program.  It consists of a
>push
>> button and an Edit Box.  I'm trying to figure out how to disable the push
>button
>> when there are no characters in the Edit Box and enable it when there
>are.  I'm
>> handling the ON_EN_CHANGE message for the Edit Box with the following
>code.  It
>> checks if the Edit Box has text, it gets the window handle of the button,
>but
>> how do I disable / enable the button????

>I move that if this group ever has a FAQ, that this question be number 1.
>Not a slight in your direction, Rick, it just gets asked A LOT!
>The CButton class is derived from CWnd. It inherits all of the methods of
>CWnd. One of these
>methods is EnableWindow. Check it out in the help files for details.

>Dennis Jump        

Actually, I tried that and it did not work.  The button would be disabled and
then would immediately enable itself again!  Last night I ran through about 2000
messages in this group and found the answer.  The button must be disabled in an
UPDATE_COMMAND_UI handler with the following call:
        pCmdUI->Enable(m_boolButton);
where m_boolButton is TRUE or FALSE representing the condition of the button.

Rick

BTW, I'd LOVE to see a FAQ for this group.  There is so much to learn when one
is new both to C++ and MFC!



Sun, 31 Oct 1999 03:00:00 GMT  
 How do I Enable / Disable button in Dialog Bar?

Rick,
     Your CMainFrame needs to have something like

ON_UPDATE_COMMAND_UI(IDC_BUTTON1, CMainFrame::OnUpdateButton1)

wherein you would put stuff like
void CMainFrame::OnUpdateButton1(CCmdUI *pCmdUI)
{
        CString  editText;              // text in edit box

        // get text from edit box
        m_wndMyDialogBar.GetDlgItem(IDC_EDIT1)->GetWindowText(editText);

        // enable button if there is any text in the edit box
        pCmdUI->Enable(editText.GetLength());

Quote:
}



Quote:
> I have a dialog bar that I inserted into my program.  It consists of a
push
> button and an Edit Box.  I'm trying to figure out how to disable the push
button
> when there are no characters in the Edit Box and enable it when there
are.  I'm
> handling the ON_EN_CHANGE message for the Edit Box with the following
code.  It
> checks if the Edit Box has text, it gets the window handle of the button
and
> disables/enables the button.  I can see the button "flash" for a brief
moment,
> but it never disables.  What is keeping the button enabled and how can I
disable
> it???

> void CMainFrame::OnChangeEdit1()
> {
>    CString strFubar;
>    m_wndMyDialogBar.GetDlgItemText(IDC_EDIT1,strFubar);
>    if (strFubar.IsEmpty())         // Disable pushbutton if string is empty
>            m_wndMyDialogBar.GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE);
>    else
>            m_wndMyDialogBar.GetDlgItem(IDC_BUTTON1)->EnableWindow(TRUE);
> }



Sun, 31 Oct 1999 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. CDialog bar button enabling/disabling checking/unchecking

2. File Open Dialog - Open button Enable&Disable

3. File Open Dialog - Open button Enable&Disable

4. How to enable/disable Toolbar button in Dialog Based MFC application

5. File Open Dialog - Open button Enable&disable

6. enable/disable toolbar button using pCmdUI->Enable(TRUE/FALSE) doesnt work

7. Enabling/Disabling a dialog Button

8. Real Simple: Enabling/disabling buttons on Dialog boxes

9. Best way to enable / disable controls based on what user is doing at moment

10. button on dialog bar always disabled?

11. how to enable disable status bar

12. Disable CRichEditCtrl But Enable Scroll Bars

 

 
Powered by phpBB® Forum Software