Solved

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

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
c++ syntax question 9 49
Dialogbox API leak? 18 96
Unable to start eclipse ? 17 141
Why  my code (program) build with old compiler? 11 47
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 …
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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.
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…

809 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