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. Using SetWindowRgn on bitmap buttons

Using SetWindowRgn on bitmap buttons

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

    I've got a bitmap on a button and I want the user to be only able to click the area of the button that is covered by the bitmap. For circular bitmaps I've used the following code:

    CRect button_rect ; // size of button
    HRGN rgn ;

    button->GetClientRect ( &button_rect ) ;

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

    button->SetWindowRgn ( rgn,
    TRUE ) ;

    However I've got a bitmap that has a rectangle that is diagonal across the bitmap, does anyone know how I can create a HRGN object with the points for the diagonal rectangle. TIA,

    K 1 Reply Last reply
    0
    • M mcsherry

      I've got a bitmap on a button and I want the user to be only able to click the area of the button that is covered by the bitmap. For circular bitmaps I've used the following code:

      CRect button_rect ; // size of button
      HRGN rgn ;

      button->GetClientRect ( &button_rect ) ;

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

      button->SetWindowRgn ( rgn,
      TRUE ) ;

      However I've got a bitmap that has a rectangle that is diagonal across the bitmap, does anyone know how I can create a HRGN object with the points for the diagonal rectangle. TIA,

      K Offline
      K Offline
      khan
      wrote on last edited by
      #2

      I think you can use CreatePolygonRgn(...) Also, you can use the CRgn wrapper instead of HRGN: CRgn rgn; CPoint pt[3]; pt[0].x = 10; pt[0].y = 10; pt[1].x = 100; pt[1].y = 100; pt[2].x = 10; pt[2].y = 100; rgn.CreatePolygonRgn(pt,3,ALTERNATE);

      this is this.

      M 1 Reply Last reply
      0
      • K khan

        I think you can use CreatePolygonRgn(...) Also, you can use the CRgn wrapper instead of HRGN: CRgn rgn; CPoint pt[3]; pt[0].x = 10; pt[0].y = 10; pt[1].x = 100; pt[1].y = 100; pt[2].x = 10; pt[2].y = 100; rgn.CreatePolygonRgn(pt,3,ALTERNATE);

        this is this.

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

        thanks for your reply, got it semi working using this just need to get my polygon region the right shape/size now! cheers,

        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