Transparent Background Child Windows

Hi there, I'm using the below code to create a video switching app. As you can see in the image linked below, the text over the buttons has a grey BG. How can I remove that?


Image:
vesav.com.au/logo/demo2.jpg


Code :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include <windows.h>
#include <tchar.h>
#include <objidl.h>
#include "stdafx.h"
#include "gdiplus.h"
#include <iostream>
#include <string>

Gdiplus::Bitmap* m_pBitmap;

#define ID_BTNHI 0
const char g_szClassName[] = "myWindowClass";

HWND button;
using namespace std;

class inputButton {
	HWND hWnd;
	int xpos, ypos;

public:
	void createButton(HWND, int, int, int, LPCSTR, int);
};



void inputButton::createButton(HWND hWnd, int xpos, int ypos, int nCmdShow, LPCSTR buttonText, int buttonState) {

	// Create button    
	HWND hButton1;
	hButton1 = CreateWindowEx(
		0,														// _In_     DWORD     dwExStyle											
		_T("BUTTON"),											// _In_opt_ LPCTSTR   lpClassName
		_T(buttonText),										// _In_opt_ LPCTSTR   lpWindowName
		BS_ICON | WS_VISIBLE | WS_CHILD , //| SS_NOTIFY,			// _In_     DWORD     dwStyle
		xpos,													// _In_     int       x
		ypos,													// _In_     int       y
		100,													// _In_     int       nWidth
		100,													// _In_     int       nHeight
		hWnd,													// _In_opt_ HWND      hWndParent
		HMENU(),												// _In_opt_ HMENU     hMenu
		NULL,													// _In_opt_ HINSTANCE hInstance
		NULL													// _In_opt_ LPVOID    lpParam
	);

	// Assign image to button
	Gdiplus::Bitmap* m_pBitmap;
	HICON hicon;
	if (buttonState == 0) { m_pBitmap = Gdiplus::Bitmap::FromFile(L"greySwitch.png"); }
	if (buttonState == 1) { m_pBitmap = Gdiplus::Bitmap::FromFile(L"greenSwitch.png"); }
	if (buttonState == 2) { m_pBitmap = Gdiplus::Bitmap::FromFile(L"redSwitch.png"); }
	if (buttonState == 3) { m_pBitmap = Gdiplus::Bitmap::FromFile(L"yellowSwitch.png"); }
	m_pBitmap->GetHICON(&hicon);


	LRESULT lr = SendMessage(hButton1, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hicon);
	ShowWindow(hButton1, nCmdShow);
	UpdateWindow(hButton1);

	DWORD Flags1 = WS_EX_COMPOSITED | WS_EX_LAYERED | WS_EX_NOACTIVATE | WS_EX_TOPMOST | WS_EX_TRANSPARENT;
	//DWORD Flags1 =  WS_EX_TRANSPARENT;
	DWORD Flags2 = WS_POPUP;


	HWND hStatic;


	hStatic = CreateWindowEx(
		WS_EX_TRANSPARENT,									// _In_     DWORD     dwExStyle	
		TEXT("STATIC"),										// _In_opt_ LPCTSTR   lpClassName
		TEXT(buttonText),									// _In_opt_ LPCTSTR   lpWindowName
		WS_CHILD | WS_VISIBLE | SS_CENTER,					// _In_     DWORD     dwStyle
		10,													// _In_     int       x
		40,													// _In_     int       y
		80,													// _In_     int       nWidth
		20,													// _In_     int       nHeight
		hButton1,											// _In_opt_ HWND      hWndParent
		HMENU(),											// _In_opt_ HMENU     hMenu
		NULL,												// _In_opt_ HINSTANCE hInstance
		NULL												// _In_opt_ LPVOID    lpParam
	);

	

	

	ShowWindow(hStatic, nCmdShow);
	UpdateWindow(hStatic);
	LRESULT ls = SendMessage(hStatic, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hicon);

}



LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
	switch (msg) {

		case WM_CLOSE:
			DestroyWindow(hWnd);
			break;
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		case WM_CTLCOLORSTATIC: {/*::MessageBox(NULL, "WM_CTLCOLORSTATIC", "", MB_OK); 	*/		}
			break;
		case WM_CREATE:			{/*::MessageBox(NULL, "WM_CREATE", "", MB_OK);	*/	}
			break;
		case WM_ERASEBKGND:		{/*::MessageBox(NULL, "WM_ERASEBKGND", "", MB_OK);	*/	}
			break;
		case WM_CTLCOLORDLG:	{/*::MessageBox(NULL, "WM_CTLCOLORDLG", "", MB_OK);	*/	}
			break;
		case WM_CTLCOLORBTN:	{/*::MessageBox(NULL, "WM_CTLCOLORBTN", "", MB_OK);	*/	}
			break;
		default:
			return DefWindowProc(hWnd, msg, wParam, lParam);
	}
	return 0;
}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
	FreeConsole(); //Hides console


				   // Initialize GDI+
	Gdiplus::GdiplusStartupInput gdiplusStartupInput;
	ULONG_PTR gdiplusToken;
	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

	

	WNDCLASSEX wc;
	HWND hWnd;
	MSG Msg;

	//Step 1: Registering the Window Class
	wc.cbSize = sizeof(WNDCLASSEX);
	wc.style = 0;
	wc.lpfnWndProc = WndProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
	wc.lpszMenuName = NULL;
	wc.lpszClassName = g_szClassName;
	wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

	if (!RegisterClassEx(&wc))
	{
		MessageBox(NULL, "Window Registration Failed!", "Error!",
			MB_ICONEXCLAMATION | MB_OK);
		return 0;
	}

	// Step 2: Creating the Window
	hWnd = CreateWindowEx(
		WS_EX_CLIENTEDGE,
		g_szClassName,
		"BMD AUX Switch",
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, CW_USEDEFAULT, 600, 500,
		NULL, NULL, hInstance, NULL);

	if (hWnd == NULL)
	{
		MessageBox(NULL, "Window Creation Failed!", "Error!",
			MB_ICONEXCLAMATION | MB_OK);
		return 0;
	}

	ShowWindow(hWnd, nCmdShow);
	UpdateWindow(hWnd);


	inputButton button1;
	button1.createButton(hWnd, 50, 50, 1, LPCSTR("CAM 1"), 3);
	inputButton button2;
	button2.createButton(hWnd, 150, 50, 1, LPCSTR("CAM 2"), 1);
	inputButton button3;
	button3.createButton(hWnd, 250, 50, 1, LPCSTR("CAM 3"), 0);
	inputButton button4;
	button4.createButton(hWnd, 350, 50, 1, LPCSTR("CAM 4"), 2);





	while (GetMessage(&Msg, NULL, 0, 0) > 0) {
		TranslateMessage(&Msg);
		DispatchMessage(&Msg);
	}
	return Msg.wParam;
}
Last edited on
Hi mate, I'm getting closer using that page and many others.

I have got the transparency to work, but I now have issues with re-painting the labels.

When it first runs it's fine, but when I re-paint the label after the button is pressed (because it disappears), I can't ssem to get it to paint in the right place. I can destroy the label and recreate it, but is this a wise thing to do?

It also has massive issues if the main window is resized/moved... the labels re-paint all over the place in the WM_DRAWITEM message handler...

Is there any way to attach the script to this message?
Topic archived. No new replies allowed.