get colour from gdi object

Posted on 2009-02-11
Last Modified: 2013-11-20
i like to initialize a CColorDialog by a colour (COLORREF value) from a GDI Object (CBrush).
I didn't find any function to do this yet.

CBrush br;
// now I'm looking for something like this:

Thanks experts.
Question by:stev75
    LVL 30

    Accepted Solution

    Hi stev75,

    you can use 'GetObject' to retrieve info about GDI objects, i.e. for a CBrush:

    > CBrush brush;
    > brush.CreateSolidBrush( RGB( 255, 255, 0 ) );
    > LOGBRUSH info;
    > brush.GetObject( sizeof( info ), &info );
    > TRACE( "Color of brush is %08x.\n", info.lbColor );

    Hope that helps,

    LVL 19

    Assisted Solution

    You can get the colour of a brush in this way:
    // create a brush
    CBrush oBrush( RGB( 255, 255, 0 ));
    // get the brush descriptor
    LOGBRUSH lbr;
    oBrush.GetLogBrush( &lbr);
    // test the colour
    ASSERT( lbr.lbColor == RGB( 255, 255, 0 ));

    Open in new window


    Author Closing Comment

    thanks, that's it! both comments lead to success so I will split points

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
    If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now