Solved

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

Posted on 2015-02-03
2
474 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
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now