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. Bitmap on Controls

Bitmap on Controls

Scheduled Pinned Locked Moved C / C++ / MFC
c++graphicshelptutorialquestion
4 Posts 3 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.
  • M Offline
    M Offline
    mcsherry
    wrote on last edited by
    #1

    Hi all, I'm currently loading a circular image onto a CBitmapButton which has the outside area of the bitmap coloured the same as the dialog so that the user is fooled into thinking it's a circular button. However the problem I have is that the user can still click on the part of the button that is outside of the circular bitmap. One solution I found was when the button is clicked, get the mouse position and if it is outside of the circle then ignore the click, however and this is the tricky part, the button has two bitmaps associated to it (down and up) and these get processed before the ON_BN_CLICK event so the bitmap changes temporarily. Here's what I want to happen:

    User presses left mouse button down
    Check that mouse pos is within circle
    If mouse is within circle
    load 'down' bitmap

    User releases left mouse button
    if mouse is within circle
    load 'up' bitmap
    do some clever stuff :laugh:
    if conditions are met
    load 'selected' bitmap

    Looking at the button methods the only suitable one is the ON_BN_CLICK event but not a WM_LBUTTONDOWN event like on the dialog. Does anyone have any ideas on how to do this? This is getting developed within Studio 2003 and is a Dialog based MFC app. cheers, Andy

    F 1 Reply Last reply
    0
    • M mcsherry

      Hi all, I'm currently loading a circular image onto a CBitmapButton which has the outside area of the bitmap coloured the same as the dialog so that the user is fooled into thinking it's a circular button. However the problem I have is that the user can still click on the part of the button that is outside of the circular bitmap. One solution I found was when the button is clicked, get the mouse position and if it is outside of the circle then ignore the click, however and this is the tricky part, the button has two bitmaps associated to it (down and up) and these get processed before the ON_BN_CLICK event so the bitmap changes temporarily. Here's what I want to happen:

      User presses left mouse button down
      Check that mouse pos is within circle
      If mouse is within circle
      load 'down' bitmap

      User releases left mouse button
      if mouse is within circle
      load 'up' bitmap
      do some clever stuff :laugh:
      if conditions are met
      load 'selected' bitmap

      Looking at the button methods the only suitable one is the ON_BN_CLICK event but not a WM_LBUTTONDOWN event like on the dialog. Does anyone have any ideas on how to do this? This is getting developed within Studio 2003 and is a Dialog based MFC app. cheers, Andy

      F Offline
      F Offline
      Force Code
      wrote on last edited by
      #2

      There are several code project articles on irregularly shaped buttons. In general, SetWindowRgn is the Win SDK call you use to give any window (for example a button) an irregular shape. SetWindowRgn is acessible somehow through MFC, or if you're using managed code, thorugh that as well, I presume.

      M 1 Reply Last reply
      0
      • F Force Code

        There are several code project articles on irregularly shaped buttons. In general, SetWindowRgn is the Win SDK call you use to give any window (for example a button) an irregular shape. SetWindowRgn is acessible somehow through MFC, or if you're using managed code, thorugh that as well, I presume.

        M Offline
        M Offline
        mcsherry
        wrote on last edited by
        #3

        cheers, you were right, all I needed was:

        HRGN rgn ;

        m_MyButton.GetClientRect ( &button_rect ) ;
        rgn = CreateEllipticRgn( 0, 0,
        button_rect.Width(), button_rect.Height() );

        int ret_val = m_MyButton.SetWindowRgn(rgn, true);

        Andy,

        D 1 Reply Last reply
        0
        • M mcsherry

          cheers, you were right, all I needed was:

          HRGN rgn ;

          m_MyButton.GetClientRect ( &button_rect ) ;
          rgn = CreateEllipticRgn( 0, 0,
          button_rect.Width(), button_rect.Height() );

          int ret_val = m_MyButton.SetWindowRgn(rgn, true);

          Andy,

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          So does your (round) bitmap touch the four sides of the bounding rectangle? What if your bitmap was an oval instead? Would CreateEllipticRgn() still work?


          "A good athlete is the result of a good and worthy opponent." - David Crow

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          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