Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CButton - States

CButton - States

Scheduled Pinned Locked Moved C / C++ / MFC
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andy202
    wrote on last edited by
    #1

    I would like to highlight the state of the button when pressed; i.e. show its 'ON' then reset its state when pressed again - 'OFF'. The following code does not quiet do what I require and I have looked at the methods and not found anything that would do. void CTabOne::OnBnClickedRelayButton() { // Maintain the button state along with the bool variable if(m_bRelayState) { m_cRelayButton.SetState(FALSE); m_cRelayButton.SetWindowTextA("OFF"); m_bRelayState = false; } else { m_cRelayButton.SetState(TRUE); m_cRelayButton.SetWindowTextA("ON"); m_bRelayState = true; } } Any suggestions please. Andy.

    T S H 3 Replies Last reply
    0
    • A Andy202

      I would like to highlight the state of the button when pressed; i.e. show its 'ON' then reset its state when pressed again - 'OFF'. The following code does not quiet do what I require and I have looked at the methods and not found anything that would do. void CTabOne::OnBnClickedRelayButton() { // Maintain the button state along with the bool variable if(m_bRelayState) { m_cRelayButton.SetState(FALSE); m_cRelayButton.SetWindowTextA("OFF"); m_bRelayState = false; } else { m_cRelayButton.SetState(TRUE); m_cRelayButton.SetWindowTextA("ON"); m_bRelayState = true; } } Any suggestions please. Andy.

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      you should use either a Radio button or a checkbox button with the pushbutton style.


      TOXCCT >>> GEII power

      [VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]

      1 Reply Last reply
      0
      • A Andy202

        I would like to highlight the state of the button when pressed; i.e. show its 'ON' then reset its state when pressed again - 'OFF'. The following code does not quiet do what I require and I have looked at the methods and not found anything that would do. void CTabOne::OnBnClickedRelayButton() { // Maintain the button state along with the bool variable if(m_bRelayState) { m_cRelayButton.SetState(FALSE); m_cRelayButton.SetWindowTextA("OFF"); m_bRelayState = false; } else { m_cRelayButton.SetState(TRUE); m_cRelayButton.SetWindowTextA("ON"); m_bRelayState = true; } } Any suggestions please. Andy.

        S Offline
        S Offline
        singersinger
        wrote on last edited by
        #3

        you can write this in your void CTabOne::OnBnClickedRelayButton() function CString text; m_cRelayButton.GetWindowText(text); if(text == "OFF") { m_cRelayButton.SetState(TRUE); m_cRelayButton.SetWindowText(_T("ON")); } if(text == "ON") { mm_cRelayButton.SetState(FALSE); m_cRelayButton.SetWindowText(_T("OFF")); } i think this should do hope that it would help a.hemdan

        1 Reply Last reply
        0
        • A Andy202

          I would like to highlight the state of the button when pressed; i.e. show its 'ON' then reset its state when pressed again - 'OFF'. The following code does not quiet do what I require and I have looked at the methods and not found anything that would do. void CTabOne::OnBnClickedRelayButton() { // Maintain the button state along with the bool variable if(m_bRelayState) { m_cRelayButton.SetState(FALSE); m_cRelayButton.SetWindowTextA("OFF"); m_bRelayState = false; } else { m_cRelayButton.SetState(TRUE); m_cRelayButton.SetWindowTextA("ON"); m_bRelayState = true; } } Any suggestions please. Andy.

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          If you have a button I sugget use of a checkbox.


          WhiteSky


          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups