Problem mit UpdateLayeredWindow



  • Ich experimentiere im Moment ein bisschen mit Layered Windows. Ich habe schon transparente Fenster mit SetLayeredWindowAttributes gemacht und will jetzt auch mal ein Bild auf dem Fenster anzeigen lassen. Allerdings ist das Fenster immer unsichtbar, nachdem ich UpdateLayeredWindow angewendet habe.

    Hier der Codeausschnitt:

    HWND window = CreateWindowEx( WS_EX_LAYERED, "windowclass", "Fenster", WS_VISIBLE | WS_POPUP, 100, 100, 400, 300, 0, 0, GetModuleHandle( 0 ), 0 );
    
    	POINT sPoint = { 100, 100 };
    	SIZE sSize = { 400, 300 };
    	POINT sSrc = { 0, 0 };
    
    	BLENDFUNCTION sBlend;
    	sBlend.AlphaFormat = AC_SRC_ALPHA;
    	sBlend.BlendOp = AC_SRC_OVER;
    	sBlend.BlendFlags = 0;
    	sBlend.SourceConstantAlpha = 255;
    
    	HDC hScreenDC = GetDC( 0 );
    	HDC hMemoryDC = CreateCompatibleDC( hScreenDC );
    
    	HBITMAP hBitmap = ( HBITMAP )LoadImage( GetModuleHandle( 0 ), "bitmap.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
    	SelectObject( hMemoryDC, hBitmap );
    
    	HRESULT hRes = UpdateLayeredWindow( window, hScreenDC, &sPoint, &sSize, hMemoryDC, &sSrc, 0, &sBlend, ULW_ALPHA );
    

    Ich hab keine Ahnung, warum es nicht funktioniert. 😞



  • Hi,

    probier mal:

    HDC hMemoryDC = CreateCompatibleDC(NULL)
    

    Verwendest du ein 32-Bit-Bild?
    Hast du die Farben schon mit deren Alphawert vormultipliziert?



  • Danke für Deine Antwort.
    Mit CreateCompatibleDC( NULL ) geht es aber leider auch nicht.
    Ich verwende eine 24-Bit Bitmap und was meinst Du mit Vormultiplizieren? 😕



  • Hi,

    UpdateLayeredWindow() macht ja nur Sinn, wenn deine Bitmap einen Alphakanal besitzt. Sonst könntest du die Bitmap einfach nur blitten.


Anmelden zum Antworten