MFC: How to draw a semi-transparent shape?

Discussion in 'C++' started by Starlite, Dec 29, 2003.

  1. Starlite

    Starlite Guest

    I am using Microsoft visual c++ 6, and I want to draw a shape (say a
    rectangle) on a view. The code that I have used is below, but this draws a
    solid -filled rectangle, what I want is a displayed shape with a
    semi-transparent color i.e. we should still be able to see whatever is
    beneath the shape. Can anyone help me? Thanks.

    void OnPaint()
    {
    CPaintDC dc(this);
    CPen pPen(PS_SOLID, 1, RGB(0,0,0));
    CBrush bBr(RGB(0,0,150));
    CRect rec;

    //rectangle to be drawn
    rec.top = 0;
    rec.left = 0;
    rec.right = 100;
    rec.bottom = 100;

    dc.SelectObject(pPen);
    dc.SelectObject(bBr);

    dc.Rectangle(rec);
    }
    Starlite, Dec 29, 2003
    #1
    1. Advertising

  2. Starlite

    Dan W. Guest

    On Mon, 29 Dec 2003 14:32:34 +0400, "Starlite"
    <> wrote:

    >I am using Microsoft visual c++ 6, and I want to draw a shape (say a
    >rectangle) on a view. The code that I have used is below, but this draws a
    >solid -filled rectangle, what I want is a displayed shape with a
    >semi-transparent color i.e. we should still be able to see whatever is
    >beneath the shape. Can anyone help me? Thanks.
    >
    >void OnPaint()
    >{
    > CPaintDC dc(this);
    > CPen pPen(PS_SOLID, 1, RGB(0,0,0));
    > CBrush bBr(RGB(0,0,150));
    > CRect rec;
    >
    >//rectangle to be drawn
    > rec.top = 0;
    > rec.left = 0;
    > rec.right = 100;
    > rec.bottom = 100;
    >
    > dc.SelectObject(pPen);
    > dc.SelectObject(bBr);
    >
    > dc.Rectangle(rec);
    >}
    >


    I've seen an MFC-specific newsgroup, you might care to search for
    'mfc' throught the newsgroups list. I have a feeling that you need to
    use Direct X if you want real-time alpha blending. Or OpenGL; I don't
    think the GDI has built-in capabilities for that; but you might want
    to check with MFC gurus.
    Dan W., Dec 29, 2003
    #2
    1. Advertising

  3. Re: How to draw a semi-transparent shape?

    "Starlite" <> wrote...
    > I am using Microsoft visual c++ 6, and I want [...]


    Please post your MFC question to microsoft.public.vc.mfc
    Victor Bazarov, Dec 29, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Minhua Fu

    How to draw a transparent gif in web

    Minhua Fu, Dec 30, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    2,021
    George Ter-Saakov
    Dec 30, 2003
  2. Maflu
    Replies:
    4
    Views:
    10,319
    Hywel Jenkins
    Dec 27, 2003
  3. John Fitzsimons

    Semi transparent pictures - How ?

    John Fitzsimons, Jul 23, 2004, in forum: HTML
    Replies:
    1
    Views:
    550
    Toby Inkster
    Jul 23, 2004
  4. azsx

    semi-transparent Frames

    azsx, Sep 17, 2006, in forum: Java
    Replies:
    1
    Views:
    552
    Andrew Thompson
    Sep 17, 2006
  5. James Stroud

    py2app semi-standalone semi-works

    James Stroud, Oct 4, 2006, in forum: Python
    Replies:
    2
    Views:
    689
    James Stroud
    Oct 4, 2006
Loading...

Share This Page