Solved

How do I create a "Static" text control in win32 which has a transparent background?

Posted on 2015-02-03
2
629 Views
Last Modified: 2015-02-04
Hi:

I'm building a win32 C++ based application.

The background of the application window is the output from a video stream.
I'm displaying the video stream frame by frame through GDI+ as in the main window's WM_PAINT message.

I'm currently using "Static" text controls to display some textual information on top of the video stream.
I would like the background of the text to be trans parent so that the bitmap shows as the background
instead of the default background color of that static text control.

What is the best way to do that?

Currently, I've tried setting the window's style to:
WS_CHILD | WS_VISIBLE | WS_EX_TRANSPARENT,

Open in new window


and then doing this in my WndProc
	case WM_CTLCOLORSTATIC:
	{
		HWND hCntl = (HWND)lParam;
		SetTextColor((HDC)wParam, RGB(255, 0, 0));
		SetBkMode((HDC)wParam, TRANSPARENT);

		return (BOOL)GetSysColorBrush(HOLLOW_BRUSH);
	}

Open in new window


This approach is not working.
What am I doing wrong here?
Is there a better way to implement this?

Thanks,
JohnB
0
Comment
Question by:jxbma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 40589046
You are missing a call to  'SetLayeredWindowAttributes()' (http://msdn.microsoft.com/en-us/library/windows/desktop/ms633540%28v=vs.85%29.aspx), e.g.

LONG dwExtendedStyle = GetWindowLong(hStaticWnd,GWL_EXSTYLE );
SetWindowLong(hStaticWnd,GWL_EXSTYLE,dwExtendedStyle | WS_EX_LAYERED );
::SetLayeredWindowAttributes(hStaticWnd,RGB(1,11,21),0,LWA_COLORKEY);

Open in new window


right after creating the static control.
0
 
LVL 1

Author Closing Comment

by:jxbma
ID: 40589598
Thanks Man!
I realize that another way to do this is to simply do a TextOut() when handling my WM_PAINT message.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question