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

  • SEARCH
  • Home
  • 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 6372975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:18:22+00:00 2026-05-25T01:18:22+00:00

Is it possible to create a label with a transparent background within a window

  • 0

Is it possible to create a label with a transparent background within a window using only WinAPI commands?

I am trying to add an image to a Dialog window that will serve as a background image and then display text upon that image. Everything I have tried so far shows the text label on top of the background image with a grey rectangle drawn around it.

This is an example of my code so far (showing the entire message handler for the dialog):

INT_PTR CALLBACK OfferWindowProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{       
    HWND hWndBackground;
    HWND hWndLabel;
    HBRUSH hLabelBackColour = NULL;
      HFONT hfFont;
      HWND hWndTitleLabel;
    HDC hdcStatic = NULL;

    UNREFERENCED_PARAMETER(lParam);
    switch (message)
    {
    case WM_INITDIALOG:             

        //Load the background image
        HANDLE hBitmap;
        hBitmap = LoadImage(NULL, L"C:\\Users\\DavidHall\\Documents\\bg.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
        if (hBitmap != NULL)
        {
            hWndBackground = CreateWindow(L"STATIC", L"image box", WS_CHILD | WS_VISIBLE | SS_BITMAP, 0, 0, 100, 100, hDlg, (HMENU) 2000, NULL, NULL);          
            SendMessage(hWndBackground, STM_SETIMAGE, IMAGE_BITMAP, LPARAM(hBitmap));
        }           

        // Create the label using CreateWindowEx
        hfFont = CreateFont(20, 0, 0, 0, fontWeight, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
            DEFAULT_PITCH, L"Verdana");

        hWndTitleLabel = CreateWindowEx( WS_EX_TRANSPARENT, L"STATIC", L"", WS_CHILD | WS_VISIBLE | SS_LEFT | WS_SYSMENU , xPos, yPos, width, height, hwnd, (HMENU) id, hInst, NULL);           

        SendMessage(hWndTitleLabel, WM_SETTEXT, NULL, (LPARAM) labelText.c_str());

        SendMessage(hWndTitleLabel, WM_SETFONT, (WPARAM)hfFont, NULL);  

        return (INT_PTR)TRUE;   

    case WM_CLOSE:
        EndDialog(hDlg, LOWORD(wParam));    

        // Delete the brush - is that correct?
        DeleteObject(hLabelBackColour);
        return (INT_PTR)TRUE;

    case WM_COMMAND:
        if (LOWORD(wParam) == IDCANCEL)
        {
            EndDialog(hDlg, LOWORD(wParam));
            return (INT_PTR)TRUE;
        }
        break;
    default:
        break;
    }
    return (INT_PTR)FALSE;
}

I’ve tried various combinations of things including:

  • SetLayeredWindowAttributes
  • SetBkMode(hdc, TRANSPARENT)
  • Handling the WM_CTLCOLORSTATIC message
  • 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-05-25T01:18:24+00:00Added an answer on May 25, 2026 at 1:18 am

    I’ve found something that appears to be working, though since I am very new to programming in pure WinAPI this could well be very bad practice and I would have no idea!

    I am handling the WM_CTLCOLORSTATIC message as shown:

    case WM_CTLCOLORSTATIC:
    
        hdcStatic = (HDC) wParam; 
        SetTextColor(hdcStatic, RGB(0,0,0));    
        SetBkMode (hdcStatic, TRANSPARENT);
    
        return (LRESULT)GetStockObject(NULL_BRUSH);
    

    This gives the effect that I’m after of my label appearing on top of my image with a transparent background.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using this article from sun. I am trying to create a transparent window. I
I'm trying to create a translucent window with Java on OSX and add a
Is it possible to create a REST web service using ASP.NET 2.0? The articles
Is it possible to create Selenium tests using the Firefox plugin that use randomly
I'm trying to create an HTML form (using JSP) which contains Javascript buttons (rather
I am trying to create a rounded header that could possible be multiple lines.
Is it possible to write code like the following. I'm trying to using Moq
Is it possible to create a multi-line label with word wrap that resizes in
Hi it'd like to know if it's at all possible create a parametric equalizer
Possible Duplicate: Create a temporary directory in Java Duplicate: stackoverflow.com/questions/375910 Is there a way

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.