8

Can you get the RGB value from HBRUSH or from brush id? for example: I'm looking for GRAY_BRUSH in RGB value.

GSerg
  • 76,472
  • 17
  • 159
  • 346
xor
  • 93
  • 1
  • 4

2 Answers2

6

You want to use the GetObject function to return a LOGBRUSH structure that contains the brush color.

GSerg
  • 76,472
  • 17
  • 159
  • 346
1
        static COLORREF lbColor;
        HBRUSH hb = GetSysColorBrush(COLOR_BACKGROUND);            
        LOGBRUSH br = { 0 };

        if (GetObject(hb, sizeof(br), &br))
        {
            lbColor = br.lbColor;

            RGBQUAD rgbq = { 0 };
            rgbq.rgbBlue = GetBValue(lbColor);
            rgbq.rgbGreen = GetGValue(lbColor);
            rgbq.rgbRed = GetRValue(lbColor);
            rgbq.rgbReserved = 0;
            //...
        }
  • While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Adrian Mole Aug 25 '22 at 11:05