Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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
?
680 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

719 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