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. [mfc, custom control] Default Button

[mfc, custom control] Default Button

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialc++graphicsquestion
8 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.
  • C Offline
    C Offline
    csrss
    wrote on last edited by
    #1

    Hi. I got my own custom button where i am doing all the painting myself. And now there is a problem: default button behavior. You know, like, these fancy regular windows buttons - when you click inside some Edit Box (let it be anywhere on the main app window) - button is drawn with blue shinning color. When you click on another button - that another button becomes default one. When you click inside some other edit box, again - this first button is drawn with a blue shinning color. The thing is : it is not an issue to check the style with:

    if( GetStyle() & BS_DEFPUSHBUTTON ) then...

    and do some additional drawing. The problem is: how to catch when a user clicked somewhere on another control which is not mine, which is regular windows edit box for example. Or another button which is just windows regular button? How do my button know when to draw some additional stuff to indicate it is a default button? Thanks

    011011010110000101100011011010000110100101101110 0110010101110011

    S L A 3 Replies Last reply
    0
    • C csrss

      Hi. I got my own custom button where i am doing all the painting myself. And now there is a problem: default button behavior. You know, like, these fancy regular windows buttons - when you click inside some Edit Box (let it be anywhere on the main app window) - button is drawn with blue shinning color. When you click on another button - that another button becomes default one. When you click inside some other edit box, again - this first button is drawn with a blue shinning color. The thing is : it is not an issue to check the style with:

      if( GetStyle() & BS_DEFPUSHBUTTON ) then...

      and do some additional drawing. The problem is: how to catch when a user clicked somewhere on another control which is not mine, which is regular windows edit box for example. Or another button which is just windows regular button? How do my button know when to draw some additional stuff to indicate it is a default button? Thanks

      011011010110000101100011011010000110100101101110 0110010101110011

      S Offline
      S Offline
      Software_Developer
      wrote on last edited by
      #2

      MSDN - Implement an NM_CUSTOMDRAW message handler

      void CMyCustomDrawControl::OnCustomDraw(NMHDR* pNMHDR,
      LRESULT* pResult)
      {
      LPNMCUSTOMDRAW pNMCD = reinterpret_cast(pNMHDR);
      ...
      }

      OnCustomDraw articles here and here and here

      C 1 Reply Last reply
      0
      • S Software_Developer

        MSDN - Implement an NM_CUSTOMDRAW message handler

        void CMyCustomDrawControl::OnCustomDraw(NMHDR* pNMHDR,
        LRESULT* pResult)
        {
        LPNMCUSTOMDRAW pNMCD = reinterpret_cast(pNMHDR);
        ...
        }

        OnCustomDraw articles here and here and here

        C Offline
        C Offline
        csrss
        wrote on last edited by
        #3

        i cannot see how this should solve my problem.

        011011010110000101100011011010000110100101101110 0110010101110011

        1 Reply Last reply
        0
        • C csrss

          Hi. I got my own custom button where i am doing all the painting myself. And now there is a problem: default button behavior. You know, like, these fancy regular windows buttons - when you click inside some Edit Box (let it be anywhere on the main app window) - button is drawn with blue shinning color. When you click on another button - that another button becomes default one. When you click inside some other edit box, again - this first button is drawn with a blue shinning color. The thing is : it is not an issue to check the style with:

          if( GetStyle() & BS_DEFPUSHBUTTON ) then...

          and do some additional drawing. The problem is: how to catch when a user clicked somewhere on another control which is not mine, which is regular windows edit box for example. Or another button which is just windows regular button? How do my button know when to draw some additional stuff to indicate it is a default button? Thanks

          011011010110000101100011011010000110100101101110 0110010101110011

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I think your button needs to handle the WM_KILLFOCUS[^] message.

          Unrequited desire is character building. OriginalGriff

          C 1 Reply Last reply
          0
          • L Lost User

            I think your button needs to handle the WM_KILLFOCUS[^] message.

            Unrequited desire is character building. OriginalGriff

            C Offline
            C Offline
            csrss
            wrote on last edited by
            #5

            It handles. But i need to catch somehow messages from other controls. Currently i am handling WM_MOUSEACTIVATE on a dialog window (this msg is posted when non-focused control gets focus, so basically when you click on any control on a dialog window , this dialog window gets this message) and then posting some dummy message to all child controls to make my controls redraw them selfs. But. There is one BUT. This message is posted before last control loses focus or something like that, anyways, only after second message my controls redraw them selfs correctly, so its like, "there is one click delay" - unacceptable in my case :(. So there should be some better way i dont know about

            011011010110000101100011011010000110100101101110 0110010101110011

            1 Reply Last reply
            0
            • C csrss

              Hi. I got my own custom button where i am doing all the painting myself. And now there is a problem: default button behavior. You know, like, these fancy regular windows buttons - when you click inside some Edit Box (let it be anywhere on the main app window) - button is drawn with blue shinning color. When you click on another button - that another button becomes default one. When you click inside some other edit box, again - this first button is drawn with a blue shinning color. The thing is : it is not an issue to check the style with:

              if( GetStyle() & BS_DEFPUSHBUTTON ) then...

              and do some additional drawing. The problem is: how to catch when a user clicked somewhere on another control which is not mine, which is regular windows edit box for example. Or another button which is just windows regular button? How do my button know when to draw some additional stuff to indicate it is a default button? Thanks

              011011010110000101100011011010000110100101101110 0110010101110011

              A Offline
              A Offline
              Andre Kraak
              wrote on last edited by
              #6

              You need to several things: 1. Override CWnd::OnGetDlgCode[^] and specify that your control accepts becoming a default push button (DLGC_DEFPUSHBUTTON). 2. Handle the BM_SETSTYLE[^] message in your button class, so that you are informed when windows set and removes the BS_DEFPUSHBUTTON style for your button and paint the button accordingly.

              0100000101101110011001000111001011101001

              C 1 Reply Last reply
              0
              • A Andre Kraak

                You need to several things: 1. Override CWnd::OnGetDlgCode[^] and specify that your control accepts becoming a default push button (DLGC_DEFPUSHBUTTON). 2. Handle the BM_SETSTYLE[^] message in your button class, so that you are informed when windows set and removes the BS_DEFPUSHBUTTON style for your button and paint the button accordingly.

                0100000101101110011001000111001011101001

                C Offline
                C Offline
                csrss
                wrote on last edited by
                #7

                Thank you so much!! :)

                011011010110000101100011011010000110100101101110 0110010101110011

                A 1 Reply Last reply
                0
                • C csrss

                  Thank you so much!! :)

                  011011010110000101100011011010000110100101101110 0110010101110011

                  A Offline
                  A Offline
                  Andre Kraak
                  wrote on last edited by
                  #8

                  Glad I could help.

                  0100000101101110011001000111001011101001

                  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