Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2015-02-03
2
Medium Priority
?
714 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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…

916 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