DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Spike Pierson Guest

    Two PUSHBUTTON Problems


    Hello All,

    I am being perplexed by two different issues regarding the push button control
    and the CButton MFC class. To set the groundwork, I am building an app with
    VS6, using the MFC App Wizard to lay the foundation. It is SDI with Document/View
    support. I derived my view class from CFormView, so the main window is built
    from a dialog template.

    Okay, first issue: I am utilizing a push button as a toggle; push once to
    start an event, push again to stop it. As a visual indication to the user
    that the button is down (or toggled "on"), I call the SetState method of
    the CButton class, such as follows:

    CButton m_btnToggle1;
    ...
    void OnToggle1()
    {
    if (...) // Toggle is off
    {
    ... // Do toggle "on" stuff
    m_btnToggle1.SetState(TRUE); //Toggle ON - Show button down
    ...
    }
    else // Toggle is on
    {
    ... // Do toggle "off" stuff
    m_btnToggle1.SetState(FALSE); //Toggle OFF - Show button up
    ...
    }
    }

    The visual effect works fine, but the problem is that when the button is
    in the down state (toggle "on"), pushing ANY other button on the form causes
    a toggle off. When I comment out the two SetState calls, the problem goes
    away. Why is this happening? Is this a bug in Windows / MFC framework,
    or am I missing something here? Is there a workaround for this problem?
    My boss isn't happy with the lack of visual toggle effect.

    Second issue: I have a row of twelve push button controls which I disable
    at the get-go (in the view's OnInitialUpdate function by calling each button's
    inherited EnableWindow(FALSE) method). I have assigned the twelve keyboard
    function keys (F1 - F12) as accelerators for these buttons (in the IDR_MAINFRAME
    accelerator resource). After starting the app, when I click any of these
    buttons with the mouse, they are disabled like they should be. However,
    if I use the keyboard accelerator instead of the mouse, the message hander
    for each button gets called even though the button control is disabled.
    This definitely seems like a bug. Is there a workaround for this little
    anomaly?

    Any help here would be greatly appreciated. Thanks in advance.

  2. #2
    Boris Karadjov Guest

    Re: Two PUSHBUTTON Problems


    About the first issue:

    To have buttons that look like push buttons and act as toggles, you should
    use a *check box* with "push-like" style set. Then you use the control like
    a normal check box, for example, you should call CButton::SetCheck(...) to
    set the initial state of the button instead of CButton::SetState(...). Even
    better, use the class wizard to associate "check buttons" with a set of Boolean
    member variables and let the dialog data exchange do the rest.


    Boris Karadjov
    Brainbench MVP for Visual C++
    http://www.brainbench.com

    "Spike Pierson" <SPierson@xostech.com> wrote:
    >
    >Hello All,
    >
    >I am being perplexed by two different issues regarding the push button control
    >and the CButton MFC class. To set the groundwork, I am building an app

    with
    >VS6, using the MFC App Wizard to lay the foundation. It is SDI with Document/View
    >support. I derived my view class from CFormView, so the main window is

    built
    >from a dialog template.
    >
    >Okay, first issue: I am utilizing a push button as a toggle; push once

    to
    >start an event, push again to stop it. As a visual indication to the user
    >that the button is down (or toggled "on"), I call the SetState method of
    >the CButton class, such as follows:
    >
    >CButton m_btnToggle1;
    >...
    >void OnToggle1()
    >{
    > if (...) // Toggle is off
    > {
    > ... // Do toggle "on" stuff
    > m_btnToggle1.SetState(TRUE); //Toggle ON - Show button down
    > ...
    > }
    > else // Toggle is on
    > {
    > ... // Do toggle "off" stuff
    > m_btnToggle1.SetState(FALSE); //Toggle OFF - Show button up
    > ...
    > }
    >}
    >
    >The visual effect works fine, but the problem is that when the button is
    >in the down state (toggle "on"), pushing ANY other button on the form causes
    >a toggle off. When I comment out the two SetState calls, the problem goes
    >away. Why is this happening? Is this a bug in Windows / MFC framework,
    >or am I missing something here? Is there a workaround for this problem?
    > My boss isn't happy with the lack of visual toggle effect.



  3. #3
    Nico Guest

    Re: Two PUSHBUTTON Problems


    About your second issue,

    You can just check if button is enabled or not (e.g. - (GetDlgItem( IDC_CHECK_1
    )->IsWindowEnabled()) ) in your button handler.

    Good luck,

    Nico

    "Spike Pierson" <SPierson@xostech.com> wrote:

    Hello All,

    I am being perplexed by two different issues regarding the push button control
    and the CButton MFC class. To set the groundwork, I am building an app with
    VS6, using the MFC App Wizard to lay the foundation. It is SDI with Document/View
    support. I derived my view class from CFormView, so the main window is built
    from a dialog template.

    Okay, first issue: I am utilizing a push button as a toggle; push once to
    start an event, push again to stop it. As a visual indication to the user
    that the button is down (or toggled "on"), I call the SetState method of
    the CButton class, such as follows:

    CButton m_btnToggle1;
    ...
    void OnToggle1()
    {
    if (...) // Toggle is off
    {
    ... // Do toggle "on" stuff
    m_btnToggle1.SetState(TRUE); //Toggle ON - Show button down
    ...
    }
    else // Toggle is on
    {
    ... // Do toggle "off" stuff
    m_btnToggle1.SetState(FALSE); //Toggle OFF - Show button up
    ...
    }
    }

    The visual effect works fine, but the problem is that when the button is
    in the down state (toggle "on"), pushing ANY other button on the form causes
    a toggle off. When I comment out the two SetState calls, the problem goes
    away. Why is this happening? Is this a bug in Windows / MFC framework,
    or am I missing something here? Is there a workaround for this problem?

    My boss isn't happy with the lack of visual toggle effect.

    Second issue: I have a row of twelve push button controls which I disable
    at the get-go (in the view's OnInitialUpdate function by calling each button's
    inherited EnableWindow(FALSE) method). I have assigned the twelve keyboard
    function keys (F1 - F12) as accelerators for these buttons (in the IDR_MAINFRAME
    accelerator resource). After starting the app, when I click any of these
    buttons with the mouse, they are disabled like they should be. However,
    if I use the keyboard accelerator instead of the mouse, the message hander
    for each button gets called even though the button control is disabled. This
    definitely seems like a bug. Is there a workaround for this little anomaly?

    Any help here would be greatly appreciated. Thanks in advance.


  4. #4
    Spike Pierson Guest

    Re: Two PUSHBUTTON Problems


    Many thanks to both "Boris Karadjov" and "Nico". Collectively, the suggestions
    from the two of you were just the ticket for my two problems. Thanks again!!


    With kindest regards,

    Spike Pierson



    "Boris Karadjov" <bbmvp@cpppp.virtualave.net> wrote:
    >
    >About the first issue:
    >
    >To have buttons that look like push buttons and act as toggles, you should
    >use a *check box* with "push-like" style set. Then you use the control like
    >a normal check box, for example, you should call CButton::SetCheck(...)

    to
    >set the initial state of the button instead of CButton::SetState(...). Even
    >better, use the class wizard to associate "check buttons" with a set of

    Boolean
    >member variables and let the dialog data exchange do the rest.
    >
    >
    >Boris Karadjov
    >Brainbench MVP for Visual C++
    >http://www.brainbench.com
    >


    "Nico" <Nico@hotmail.com> wrote:
    >
    >About your second issue,
    >
    > You can just check if button is enabled or not (e.g. - (GetDlgItem( IDC_CHECK_1
    >)->IsWindowEnabled()) ) in your button handler.
    >
    > Good luck,
    >
    >Nico
    >
    >"Spike Pierson" <SPierson@xostech.com> wrote:
    >
    >Hello All,
    >
    >I am being perplexed by two different issues regarding the push button control
    >and the CButton MFC class. To set the groundwork, I am building an app

    with
    >VS6, using the MFC App Wizard to lay the foundation. It is SDI with Document/View
    >support. I derived my view class from CFormView, so the main window is

    built
    >from a dialog template.
    >
    >Okay, first issue: I am utilizing a push button as a toggle; push once

    to
    >start an event, push again to stop it. As a visual indication to the user
    >that the button is down (or toggled "on"), I call the SetState method of
    >the CButton class, such as follows:
    >
    >CButton m_btnToggle1;
    >...
    >void OnToggle1()
    >{
    > if (...) // Toggle is off
    > {
    > ... // Do toggle "on" stuff
    > m_btnToggle1.SetState(TRUE); //Toggle ON - Show button down
    > ...
    > }
    > else // Toggle is on
    > {
    > ... // Do toggle "off" stuff
    > m_btnToggle1.SetState(FALSE); //Toggle OFF - Show button up
    > ...
    > }
    >}
    >
    >The visual effect works fine, but the problem is that when the button is
    >in the down state (toggle "on"), pushing ANY other button on the form causes
    >a toggle off. When I comment out the two SetState calls, the problem goes
    >away. Why is this happening? Is this a bug in Windows / MFC framework,
    >or am I missing something here? Is there a workaround for this problem?
    >
    >My boss isn't happy with the lack of visual toggle effect.
    >
    >Second issue: I have a row of twelve push button controls which I disable
    >at the get-go (in the view's OnInitialUpdate function by calling each button's
    >inherited EnableWindow(FALSE) method). I have assigned the twelve keyboard
    >function keys (F1 - F12) as accelerators for these buttons (in the IDR_MAINFRAME
    >accelerator resource). After starting the app, when I click any of these
    >buttons with the mouse, they are disabled like they should be. However,
    >if I use the keyboard accelerator instead of the mouse, the message hander
    >for each button gets called even though the button control is disabled.

    This
    >definitely seems like a bug. Is there a workaround for this little anomaly?
    >
    >Any help here would be greatly appreciated. Thanks in advance.
    >



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links