Triangular Button

Tried out the CRoundButton class by Chris Maunder, and got inspired to make a Triangle Button instead (actually i copy/pasted the code structure from that) - Anyway it might be useful to someone, so here it is.

A class derived from CButton, that displays the button as a triangle pointing in one of four directions (LEFT, RIGHT, UP, DOWN) (see demo).

Download source 31KB



Comments

  • Resourece Leak at DeleteObject in PreSubClassWindow

    Posted by Legacy on 12/20/2002 12:00am

    Originally posted by: Jibesh

    It was great work 
    
    You got appreciation
    Very nice Buttons ...
    if(CurrentRegion.Detach()!=NULL) // Line 102
    CurrentRegion.DeleteObject()
    // Check the Handle Value before deleting it
    // or It will produce a resource leak
    // I got this leak when i debug using Bounds checker in windows 2000

    Reply
  • resource leak

    Posted by Legacy on 07/26/1999 12:00am

    Originally posted by: Peggy Van Lierde

    Hi,

    First of all, I love the control. It really adds something more
    to the interface than just the common rectangular button,
    or even the bitmapbutton.

    When checking my project with boundschecker, I discovered
    a resource-leak for each csxbutton I created.
    Has anyone else noticed this too, or did I forget something ?

    I added here the message which boundschecker reported:
    Resource leak: allocated by CopyImage in Sxbutton.cpp (116), HANDLE: 0x7B050D58

    Following, I copy-pasted the method in which boundschecker detects this resource leak :

    BOOL CSXButton::SetBitmapCommon( UINT nID, int nWidth, int nHeight, COLORREF crTransparentMask, BOOL bUseMask )
    {
    if (m_hBitmapDisabled != 0)
    DeleteObject( m_hBitmapDisabled);
    if ( m_hBitmap )
    DeleteObject( m_hBitmap );

    // GS980730 added AfxFindResourceHandle to make MFC find resources in DLLs too...
    HINSTANCE hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nID),
    RT_BITMAP);

    // If it is not a masked bitmap, just go through the
    // motions as if it was, but set then number of color mappings to 0

    COLORMAP mapColor;
    mapColor.from = crTransparentMask;
    mapColor.to = ::GetSysColor( COLOR_BTNFACE );
    HBITMAP bmTemp = (HBITMAP)::CreateMappedBitmap(hInstResource, nID, IMAGE_BITMAP, &mapColor, bUseMask ? 1 : 0 );

    //Resource leak is in following line
    m_hBitmap = (HBITMAP)::CopyImage( bmTemp, IMAGE_BITMAP, nWidth, nHeight, LR_COPYDELETEORG );

    // Create disabled bitmap. We need to make the masked area white so
    // it will appear transparent when the bitmap is rendered as an
    // 'embossed' (disabled) image in DrawItem() below. Since DrawState
    // converts the image to monochrome, white is transparent, black is
    // graphics data.
    mapColor.to = RGB( 255, 255, 255 );
    bmTemp = (HBITMAP)::CreateMappedBitmap(hInstResource, nID, IMAGE_BITMAP, &mapColor, bUseMask ? 1 : 0 );
    m_hBitmapDisabled = (HBITMAP)::CopyImage( bmTemp, IMAGE_BITMAP, nWidth, nHeight, LR_COPYDELETEORG );

    if( m_hBitmap == 0 || m_hBitmapDisabled == 0 )
    return FALSE;

    m_nImageWidth = nWidth;
    m_nImageHeight = nHeight;

    m_hIcon = 0;

    Redraw();

    return TRUE;
    }

    Regards,
    Peggy Van Lierde.

    Reply
  • TriangleButton works right out of the box!

    Posted by Legacy on 06/17/1999 12:00am

    Originally posted by: G Larkin

    Downloaded the code, and it worked the first try when I incorporated it into my code where I needed triangular buttons. Commented out the focus code in the DrawItem function, as it was leaving some 'droppings'.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • A majority of organizations are operating under the assumption that their network has already been compromised, or will be, according to a survey conducted by the SANS Institute. With many high profile breaches in 2013 occurring on endpoints, interest in improving endpoint security is top-of-mind for many information security professionals. The full results of the inaugural SANS Endpoint Security Survey are summarized in this white paper to help information security professionals track trends in endpoint …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds