Hello all,
i'm new here, if i'm in the wrong section sorry.
Here is my problem.
I did a Layered Window (WS_EX_LAYERED) and draw a bitmap on it.
Using alpha blending function from msdn.
Behind the Scenes: The Splash Screen
Here is a screen.
Picture
and here is my sourcecode
#include <windows.h>
#include <WindowsX.h>
#include <GdiPlus.h>
#include "resource.h"
#pragma comment ( lib, "Gdiplus.lib" )
ULONG_PTR m_gdiplusToken;
HBITMAP hBmpSplash;
BOOL Blend(
HWND hWnd, HBITMAP hBmp, BYTE alpha ) {
BLENDFUNCTION bf =
{
AC_SRC_OVER, 0, alpha, AC_SRC_ALPHA };
BITMAP bm = {};
if( sizeof(bm) != GetObject(hBmp, sizeof(bm), &bm) ) return FALSE;
SIZE size = { bm.bmWidth, bm.bmHeight };
HDC hdc = CreateCompatibleDC(NULL);
if( !hdc ) return FALSE;
HBITMAP hBmpOld = SelectBitmap(hdc, hBmp);
POINT ptSrc = { 0, 0 };
BOOL bRet = UpdateLayeredWindow(
hWnd,
NULL ,
NULL ,
&size,
hdc,
&ptSrc,
RGB(0,0,0),
&bf,
ULW_ALPHA );
SelectBitmap(hdc, hBmpOld);
DeleteDC(hdc);
return bRet;
}
LRESULT CALLBACK WndProc(HWND window, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
case WM_CREATE:
break;
case WM_MOUSEMOVE:
break;
case WM_LBUTTONDOWN:
{
PostMessage(window, WM_NCLBUTTONDOWN, HTCAPTION,NULL);
break;
}
case WM_NCDESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(window, uMsg, wParam, lParam);
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR,
int nCmdShow)
{
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
hBmpSplash = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_SPLASH));
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 8; wcex.hInstance = hInstance; wcex.hIcon = NULL;
wcex.hCursor = ::LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)NULL_BRUSH; wcex.lpszMenuName = NULL;
wcex.lpszClassName = "GDI_Window";
wcex.hIconSm = NULL;
RegisterClassEx(&wcex);
HWND wnd = CreateWindowEx(WS_EX_TOPMOST | WS_EX_LAYERED, "GDI_Window", "GDI Window", WS_POPUP , 0, 0, 700, 500, NULL, NULL, hInstance, NULL);
Blend(wnd, hBmpSplash, 255);
ShowWindow(wnd, nCmdShow);
UpdateWindow(wnd);
MSG msg = { 0 };
while ( ::GetMessage( &msg, NULL, 0, 0 ) )
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
Gdiplus::GdiplusShutdown(m_gdiplusToken);
return 0;
}
Everythings works fine, except that i can't draw standart controls like buttons, edit control, etc.
Did you have any solution for me?
PS: I don't want to use MFC.