FillColor Transparent RGB?HEX?Other?

This is a discussion on FillColor Transparent RGB?HEX?Other? within the C++ Programming forums, part of the General Programming Boards category; Hello, i was updating fill color menu in c++ MFC painting. I did all of them except the transparent one. ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    15

    FillColor Transparent RGB?HEX?Other?

    Hello, i was updating fill color menu in c++ MFC painting. I did all of them except the transparent one. Is there any RGB value for transparency? Or do i have to write it in other form? I found a HEX Code for transparent but could not implement it. Can anybody help?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What do you mean by "transparent"? Do you mean an alphablend, so that you can see some of the background combined with your draw? In that case, you need to set the alpha component of the ARGB colour, where A < 255 (less than 1.0 in nominal terms) (a traditional RGB doesn't have A, so it'll assume a stock value of 255 for A).

    If you are after something else, I suppose you have to expand on what you want a bit, and most importantly "how this is different from the above".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    15
    Yes, i want to see the background, lets say when i am drawing a circle, inner side should be transparent, background is visible.

    When i am defining a color i do:

    Code:
    const COLORREF color_yellow = RGB(255, 255, 0);
    How should i write ARGB?

    Thanks for your help!

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You need to select a "hollow" (or "null" - it's the same thing) brush:
    See:
    http://msdn.microsoft.com/en-us/libr...23(VS.85).aspx
    http://msdn.microsoft.com/en-us/libr...72(VS.85).aspx
    Code:
    HGDIOBJ hollowBrush = GetStockObject(HOLLOW_BRUSH);
    HGDIOBJ oldObj = SelectObject(hdc, hollowBrush);
    ...
    SelectObject(hdc, oldObj);
    This is not "alphablending" [although technically you could do that, but it's by far more complicated].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    15
    Thank you for your help! I started to figure out somethings. Now my problem is implementing this code. It does not work in this way. I'm sure that Null_BRUSH implementation is right. Any suggestion?

    Code:
    void CDrawView::OnUpdateFillcolorTransparent(CCmdUI* pCmdUI) 
    {
    	CBrush brush;//I guess these are wrong
    	pCmdUI->SetCheck(brush.CreateStockObject(NULL_BRUSH));//	
    }
    Code:
    void CDrawView::OnFillcolorTransparent()
    {
    	CBrush brush;
    	brush.CreateStockObject(NULL_BRUSH);
    
    }

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Describe "doesn't work".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    15
    It compiles. However, transparent button always stays clicked and does not effect anything.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So where are you selecting what brush object to use?

    That code looks like it gets a stockobject from Windows, then "looses it", since brush is only a local variable.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    Apr 2008
    Posts
    15
    I'm selecting my brush in shape classes. So i guess i select brush two times, maybe that is the problem.

    Code:
    void CDrawView::OnFillcolorTransparent()
    {
    	So what should i write here.
    
    }

    Code:
    void Circle::Paint (CDC *pDC)
    {
    	// create the pen
    	CPen pen(PS_SOLID, look.lineWidth, look.lineColor);
    	CPen *oldpen = pDC->SelectObject(&pen);
    
    	// create the brush
    	CBrush brush;
    	if (look.transparent)
    		brush.CreateStockObject(NULL_BRUSH);
    	else
    		brush.CreateSolidBrush(look.fillColor);
    	CBrush *oldbrush = pDC->SelectObject(&brush);
    
    	// draw the circle
    	CRect r = GetRect();
    	pDC->Ellipse(r);
    
    	pDC->SelectObject(oldpen);
    	pDC->SelectObject(oldbrush);
    }

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The Circle::Paint() looks fine to me.

    I guess CDrawView::OnFillcolorTransparent should set look.transparent?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #11
    Registered User
    Join Date
    Apr 2008
    Posts
    15
    And how should i set it? any clues?

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by ataman View Post
    And how should i set it? any clues?
    Since I don't even know where that setting gets into the Circle object, I can't really help here.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21