Click here to Skip to main content
15,844,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
C++
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#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,      // Must be a layered window
    HBITMAP hBmp,   // The image. Must be 32bpp ARGB format
    BYTE alpha )    // Overall opacity (0=transparent, 255=opaque)
{
    BLENDFUNCTION bf =
    {
        AC_SRC_OVER,    // BlendOp
        0,              // BlendFlags
        alpha,          // SourceConstantAlpha
        AC_SRC_ALPHA    // AlphaFormat
    };

    // Find the image's size in pixels
    BITMAP bm = {};
    if( sizeof(bm) != GetObject(hBmp, sizeof(bm), &bm) ) return FALSE;
    SIZE size = { bm.bmWidth, bm.bmHeight };

    // Create a screen device context and select the image into it.
    HDC hdc = CreateCompatibleDC(NULL);
    if( !hdc ) return FALSE;
    HBITMAP hBmpOld = SelectBitmap(hdc, hBmp);

    // Update the layered window
    POINT ptSrc = { 0, 0 };
    BOOL bRet = UpdateLayeredWindow(
        hWnd,
        NULL /*hdcDst NULL to use the default palette for the screen*/,
        NULL /*pptDst NULL because the removed isn't changing */,
        &size,
        hdc,
        &ptSrc,
        RGB(0,0,0),
        &bf,
        ULW_ALPHA );

    // Restore the device context and clean up
    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; // 8 bytes, to allow for 64-bit architecture
	wcex.hInstance       = hInstance; // CHECK
	wcex.hIcon           = NULL;
	wcex.hCursor         = ::LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground   = (HBRUSH)NULL_BRUSH; // CHECK
	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.
Posted
Updated 14-Nov-12 2:34am
v2
Comments
Richard MacCutchan 14-Nov-12 7:51am    
What do you mean by " i can't draw standart controls like buttons ..."? There is no drawing code in your application.
Light.D.Right 14-Nov-12 7:56am    
for example i want to create a button with CreateWindow(
"BUTTON","Click here"
,WS_CHILD | WS_VISIBLE // style : child window
,10,10,100,30 // coordinates relative to your window
,hWndParent // the HWND of your window
,HMENU(123) // optionally an identifier - you can set it to NULL!
,hInstance // you can also pass NULL, because BUTTON is a global class!
,NULL // no data passed to the button!
);

it doesn't show anything. and yeah i put it out. But i create the Button in WM_CREATE of the wndproc.
Other words same question. How do i create Standart Controls on Layered Window?
Richard MacCutchan 14-Nov-12 18:19pm    
Not sure about this, I suggest you read this whitepaper on the subject.

1 solution

The word you want is 'standard'. If you created a window, then you can add controls to it, the fact you drew an image on it is immaterial. WinAPI C in the age of C# seems like masochism to me. Why ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900