Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8062897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:49:53+00:00 2026-06-05T10:49:53+00:00

I am attempting to draw a slightly transparent blue rectangle in Native Win32 C++.

  • 0

I am attempting to draw a slightly transparent blue rectangle in Native Win32 C++. I am using the function AlphaBlend() but its not drawing anything onto the window, nothing happens.

My Problem: When I run my function to draw a slightly transparent rectangle, it doesn’t get shown on my window. I have a feeling I am doing this wrong, maybe I should be using a HBITMAP?

Can you tell me what I need to do to get my function to draw a slightly transparent rectangle on the window?

Also I’m aware of GDI+ but I want to avoid it for now because I am getting alot of compile/include errors when I use that library plus I want to go as low/native as possible without the help of libraries that do everything for me.

bool paintRect(HDC hdc, RECT dim, COLORREF penCol, COLORREF brushCol, unsigned int opacity)
{
    HDC tempHdc         = CreateCompatibleDC(hdc);
    BLENDFUNCTION blend = {AC_SRC_OVER, 0, 127, AC_SRC_ALPHA};

    SetDCPenColor(tempHdc, RGB(255,255,0));
    SetDCBrushColor(tempHdc, RGB(255,255,0));
    Rectangle(tempHdc, dim.left, dim.top, dim.right, dim.bottom);

    return bool(AlphaBlend(hdc, dim.left, dim.top, dim.right, dim.bottom, tempHdc, dim.left, dim.top, dim.right, dim.bottom, blend)); 
}
// Usage
case WM_PAINT:
{
   HDC hdc;
   PAINTSTRUCT ps;
   hdc = BeginPaint(hwnd, &ps);

   RECT a = {0,0,100,100};
   paintRect(hdc, a, RGB(255,255,0), RGB(255,255,0), 127); // 127 is 50% transparency right?

   EndPaint(hwnd, &ps);
}
break;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:49:56+00:00Added an answer on June 5, 2026 at 10:49 am

    This will work:

    bool paintRect(HDC hdc, RECT dim, COLORREF penCol, COLORREF brushCol, unsigned int opacity)
    {
            HDC tempHdc         = CreateCompatibleDC(hdc);
            BLENDFUNCTION blend = {AC_SRC_OVER, 0, 127, 0};
    
            HBITMAP hbitmap;       // bitmap handle 
            BITMAPINFO bmi;        // bitmap header 
            // zero the memory for the bitmap info 
            ZeroMemory(&bmi, sizeof(BITMAPINFO));
    
            // setup bitmap info  
            // set the bitmap width and height to 60% of the width and height of each of the three horizontal areas. Later on, the blending will occur in the center of each of the three areas. 
            bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
            bmi.bmiHeader.biWidth = dim.right-dim.left;
            bmi.bmiHeader.biHeight = dim.bottom-dim.top;
            bmi.bmiHeader.biPlanes = 1;
            bmi.bmiHeader.biBitCount = 32;         // four 8-bit components 
            bmi.bmiHeader.biCompression = BI_RGB;
            bmi.bmiHeader.biSizeImage = (dim.right-dim.left) * (dim.bottom-dim.top) * 4;
    
            // create our DIB section and select the bitmap into the dc 
            hbitmap = CreateDIBSection(tempHdc, &bmi, DIB_RGB_COLORS, NULL, NULL, 0x0);
            SelectObject(tempHdc, hbitmap);
    
            SetDCPenColor(tempHdc, RGB(0,0,255));
            SetDCBrushColor(tempHdc, RGB(0,0,255));
            FillRect(tempHdc, &dim, CreateSolidBrush(RGB(0,0,255)));
    
            return bool(AlphaBlend(hdc, dim.left, dim.top, dim.right, dim.bottom, tempHdc, dim.left, dim.top, dim.right, dim.bottom, blend)); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm attempting to draw a red stroke (1 thickness) around a rounded rectangle but
So, i'm attempting simple card game. I have player class with draw function, and
I am trying to draw a transparent plane (X[0..100],Y[0..100],Z=0) in Java 3D, but can't
I'm attempting to draw text to the screen using GLUT in 2d. I want
Using OpenGL I'm attempting to draw a primitive map of my campus. Can anyone
I'm attempting to draw a graph using Cubic Hermite Splines . I grabbed the
I've been attempting to create a pen tool for my Java drawing program using
I am attempting to draw an image onto a CALayer. I only need an
I am attempting to just draw basic shapes to a panel on my form.
Attempting to find printers / shares in Active Directory using C#. This is my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.