문제

So, I have a WINDOWCLASSX that I want to set the background to, including the alpha channel, but I only saw an "RGB" macro; no RGBA.

So how do I set alpha on hbrBackground? Here is my code:

    WNDCLASSEX wincl;  


wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;      
wincl.style = CS_DBLCLKS;               
wincl.cbSize = sizeof (WNDCLASSEX);

wincl.hIcon = LoadIcon (GetModuleHandle(0), MAKEINTRESOURCE(IDI_MYAPP));
wincl.hIconSm = LoadIcon (GetModuleHandle(0), MAKEINTRESOURCE(IDI_MYAPP));
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = MAKEINTRESOURCE(IDR_MAINFRAME);               
wincl.cbClsExtra = 0;                     
wincl.cbWndExtra = 0;                     

wincl.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);

On that last line, I want to be able to set alpha.

-Thanks for any help.

도움이 되었습니까?

해결책

You cannot create an alpha channel using a background brush on the window class. You have to apply the WS_EX_LAYERED style to the window instead and then use either SetLayeredWindowAttributes() or UpdateLayeredWindow() to set the window's alpha channel. Read the MSDN documentation for more details:

Using Layered Windows

Layered Windows

다른 팁

This just worked out for me:

// Set WS_EX_LAYERED on this window 
SetWindowLong(g_mainWnd, GWL_EXSTYLE, GetWindowLong(g_mainWnd, GWL_EXSTYLE) | WS_EX_LAYERED);

// Make this window 70% alpha
SetLayeredWindowAttributes(g_mainWnd, 0, (255 * 70) / 100, LWA_ALPHA);

The g_mainWnd variable is the reference to the corresponding window (in my case, a HWND variable).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top