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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Push Buttons

Push Buttons

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 2 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.
  • F Offline
    F Offline
    ffazly
    wrote on last edited by
    #1

    I'm trying to create a push button such that when it's clicked on the text on the button changes and the button is depressed. If the button is clicked on again then it gets back to its original state. Here's the code that I've written: if(BM_CLICK) { //if button depressed return to original state if(SendMessage(hwnd[ID_BUTTON_START], BM_GETSTATE, 0, 0) == BST_PUSHED) { SendMessage(hwnd[ID_BUTTON_START], BM_SETSTATE, 0, 0); SetWindowText(hwnd[ID_BUTTON_START], TEXT("start")); } //else depress button and change button text else { SendMessage(hwnd[ID_BUTTON_START], BM_SETSTATE,1 , 0); SetWindowText(hwnd[ID_BUTTON_START], TEXT("Pause")); } } My problem is that I can't get the button to get to it's original state. What am I doing wrong here?

    P 1 Reply Last reply
    0
    • F ffazly

      I'm trying to create a push button such that when it's clicked on the text on the button changes and the button is depressed. If the button is clicked on again then it gets back to its original state. Here's the code that I've written: if(BM_CLICK) { //if button depressed return to original state if(SendMessage(hwnd[ID_BUTTON_START], BM_GETSTATE, 0, 0) == BST_PUSHED) { SendMessage(hwnd[ID_BUTTON_START], BM_SETSTATE, 0, 0); SetWindowText(hwnd[ID_BUTTON_START], TEXT("start")); } //else depress button and change button text else { SendMessage(hwnd[ID_BUTTON_START], BM_SETSTATE,1 , 0); SetWindowText(hwnd[ID_BUTTON_START], TEXT("Pause")); } } My problem is that I can't get the button to get to it's original state. What am I doing wrong here?

      P Offline
      P Offline
      P Rex
      wrote on last edited by
      #2

      Hi, Take a CheckBox and set under the properties the 'Push-like' style and try: void CMyProject::OnMyCheckBox() { m_bPushed = !m_bPushed; if(m_bPushed) GetDlgItem(IDC_CHECK_BTN)->SetWindowText(_T("Pause")); else GetDlgItem(IDC_CHECK_BTN)->SetWindowText(_T("Start")); } Hope its helpful P.

      F 1 Reply Last reply
      0
      • P P Rex

        Hi, Take a CheckBox and set under the properties the 'Push-like' style and try: void CMyProject::OnMyCheckBox() { m_bPushed = !m_bPushed; if(m_bPushed) GetDlgItem(IDC_CHECK_BTN)->SetWindowText(_T("Pause")); else GetDlgItem(IDC_CHECK_BTN)->SetWindowText(_T("Start")); } Hope its helpful P.

        F Offline
        F Offline
        ffazly
        wrote on last edited by
        #3

        Thanks for the reply. I got it to work

        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