flat assembler
Message board for the users of flat assembler.

Index > Windows > [solved]WIC+D2D1+LayeredWindow+headache

Goto page Previous  1, 2, 3  Next
Author
Thread Post new topic Reply to topic
Overclick



Joined: 11 Jul 2020
Posts: 442
Location: Ukraine
Overclick
Updated:
Code:
        struct  D2D1_PIXEL_FORMAT
                format          dd 0
                alphaMode       dd 0
        ends
        struct  D2D1_BITMAP_PROPERTIES
                pixelFormat     D2D1_PIXEL_FORMAT
                dpiX            dd 96.0f
                dpiY            dd 96.0f
        ends
        BitmapProperties        D2D1_BITMAP_PROPERTIES
        struct  D2D1_RENDER_TARGET_PROPERTIES
                type            dd 0
                pixelFormat     D2D1_PIXEL_FORMAT
                dpiX            dd 0
                dpiY            dd 0
                usage           dd 1
                minLevel        dd 0
        ends
        renderTargetProperties D2D1_RENDER_TARGET_PROPERTIES
::::::::::::::::::::::::::::::::
        cominvk pIWICFactory,CreateBitmapFromMemory,640,480,\
                        GUID_WICPixelFormat32bppPBGRA,[cbStride],640*480*4,\
                        image,pIWICBitmap
        cominvk pD2DFactory,CreateWicBitmapRenderTarget,[pIWICBitmap],\
                        renderTargetProperties,pRenderTarget
        cominvk pRenderTarget,CreateBitmapFromWicBitmap,[pIWICBitmap],\
                        BitmapProperties,pD2D1Bitmap    

Seems ok, no more errors
Post 07 Aug 2021, 16:38
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 442
Location: Ukraine
Overclick
The only error I have at UpdateLayeredWindow -- code 87 The parameter is incorrect.
I have semi-transparent black square without image on that.
Code:
.idata
        import  kernel32clone,\
                        HeapSetInformation,'HeapSetInformation'
        import  user32clone,\
                        UpdateLayeredWindow,'UpdateLayeredWindow'
        import  D2d1,\
                        D2D1CreateFactory,'D2D1CreateFactory'
        import  ole32,\ 
                        CoInitializeEx,'CoInitializeEx',\ 
                        CoUninitialize,'CoUninitialize',\ 
                        CoCreateInstance,'CoCreateInstance',\
                        CoGetClassObject,'CoGetClassObject',\
                        CoTaskMemFree,'CoTaskMemFree'
.data
        interface               IWICImagingFactory,\
                                        QueryInterface,\
                    AddRef,\
                    Release,\
                    CreateDecoderFromFilename,\
                    CreateDecoderFromStream,\
                    CreateDecoderFromFileHandle,\
                    CreateComponentInfo,\
                    CreateDecoder,\
                    CreateEncoder,\
                    CreatePalette,\
                    CreateFormatConverter,\
                    CreateBitmapScaler,\
                    CreateBitmapClipper,\
                    CreateBitmapFlipRotator,\
                    CreateStream,\
                    CreateColorContext,\
                    CreateColorTransformer,\
                    CreateBitmap,\
                    CreateBitmapFromSource,\
                    CreateBitmapFromSourceRect,\
                    CreateBitmapFromMemory,\
                    CreateBitmapFromHBITMAP,\
                    CreateBitmapFromHICON,\
                    CreateComponentEnumerator,\
                    CreateFastMetadataEncoderFromDecoder,\
                    CreateFastMetadataEncoderFromFrameDecode,\
                    CreateQueryWriter,\
                    CreateQueryWriterFromReader
        
        interface               IWICStream,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        Read,\
                                        Write,\
                                        Seek,\
                                        SetSize,\
                                        CopyTo,\
                                        Commit,\
                                        Revert,\
                                        LockRegion,\
                                        UnlockRegion,\
                                        Stat,\
                                        Clone,\
                                        InitializeFromIStream,\
                                        InitializeFromFilename,\
                                        InitializeFromMemory,\
                                        InitializeFromIStreamRegion
        
        interface               IWICBitmapFrameDecode,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        GetSize,\
                                        GetPixelFormat,\
                                        GetResolution,\
                                        CopyPalette,\
                                        CopyPixels,\
                                        GetMetadataQueryReader,\
                                        GetColorContexts,\
                                        GetThumbnail
        
        interface               IWICFormatConverter,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        GetSize,\
                                        GetPixelFormat,\
                                        GetResolution,\
                                        CopyPalette,\
                                        CopyPixels,\
                                        Initialize,\
                                        CanConvert
        
        interface               IWICBitmapDecoder,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        QueryCapability,\
                                        Initialize,\
                                        GetContainerFormat,\
                                        GetDecoderInfo,\
                                        CopyPalette,\
                                        GetMetadataQueryReader,\
                                        GetPreview,\
                                        GetColorContexts,\
                                        GetThumbnail,\
                                        GetFrameCount,\
                                        GetFrame
        
        interface               IWICBitmap,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        GetSize,\
                                        GetPixelFormat,\
                                        GetResolution,\
                                        CopyPalette,\
                                        CopyPixels,\
                                        Lock,\
                                        SetPalette,\
                                        SetResolution
        
        interface               IWICBitmapSource,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        GetSize,\
                                        GetPixelFormat,\
                                        GetResolution,\
                                        CopyPalette,\
                                        CopyPixels
        
        interface               ID2D1Factory,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        ReloadSystemMetrics,\
                                        GetDesktopDpi,\
                                        CreateRectangleGeometry,\
                                        CreateRoundedRectangleGeometry,\
                                        CreateEllipseGeometry,\
                                        CreateGeometryGroup,\
                                        CreateTransformedGeometry,\
                                        CreatePathGeometry,\
                                        CreateStrokeStyle,\
                                        CreateDrawingStateBlock,\
                                        CreateWicBitmapRenderTarget,\
                                        CreateHwndRenderTarget,\
                                        CreateDxgiSurfaceRenderTarget,\
                                        CreateDCRenderTarget
        
        interface               ID2D1DCRenderTarget,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        GetFactory,\
                                        CreateBitmap,\
                                        CreateBitmapFromWicBitmap,\
                                        CreateSharedBitmap,\
                                        CreateBitmapBrush,\
                                        CreateSolidColorBrush,\
                                        CreateGradientStopCollection,\
                                        CreateLinearGradientBrush,\
                                        CreateRadialGradientBrush,\
                                        CreateCompatibleRenderTarget,\
                                        CreateLayer,\
                                        CreateMesh,\
                                        DrawLine,\
                                        DrawRectangle,\
                                        FillRectangle,\
                                        DrawRoundedRectangle,\
                                        FillRoundedRectangle,\
                                        DrawEllipse,\
                                        FillEllipse,\
                                        DrawGeometry,\
                                        FillGeometry,\
                                        FillMesh,\
                                        FillOpacityMask,\
                                        DrawBitmap,\
                                        DrawText,\
                                        DrawTextLayout,\
                                        DrawGlyphRun,\
                                        SetTransform,\
                                        GetTransform,\
                                        SetAntialiasMode,\
                                        GetAntialiasMode,\
                                        SetTextAntialiasMode,\
                                        GetTextAntialiasMode,\
                                        SetTextRenderingParams,\
                                        GetTextRenderingParams,\
                                        SetTags,\
                                        GetTags,\
                                        PushLayer,\
                                        PopLayer,\
                                        Flush,\
                                        SaveDrawingState,\
                                        RestoreDrawingState,\
                                        PushAxisAlignedClip,\
                                        PopAxisAlignedClip,\
                                        Clear,\
                                        BeginDraw,\
                                        EndDraw,\
                                        GetPixelFormat,\
                                        SetDpi,\
                                        GetDpi,\
                                        GetSize,\
                                        GetPixelSize,\
                                        GetMaximumBitmapSize,\
                                        IsSupported,\
                                        BindDC
        

        
        
        interface               ID2D1Bitmap,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        GetFactory,\
                                        GetSize,\
                                        GetPixelSize,\
                                        GetPixelFormat,\
                                        GetDpi,\
                                        CopyFromBitmap,\
                                        CopyFromRenderTarget,\
                                        CopyFromMemory
        
        
        
        
        
        
        
        
        
        pIWICFactory            IWICImagingFactory
        pIWICStream                     IWICStream
        pIWICDecoder            IWICBitmapDecoder
        pIWICFrameDecoder       IWICBitmapFrameDecode
        pIWICBitmap                     IWICBitmap
        pIWICConverter          IWICFormatConverter
        pIWICBitmapSource       IWICBitmapSource
        
        pD2D1Factory    ID2D1Factory
        pD2D1Bitmap             ID2D1Bitmap
        pD2D1Target             ID2D1DCRenderTarget
        
CLSID_WICImagingFactory                 GUID cacaf262-9370-4615-a13b-9f5539da4c0a
        dq 0
IID_IWICImagingFactory                  GUID ec5ec8a9-c395-4314-9c77-54d7a935ff70
        dq 0
IID_ID2D1Factory                                GUID 06152247-6f50-465a-9245-118bfd3b6007
        dq 0
GUID_WICPixelFormat32bppRGBA    GUID f5c7ad2d-6a8d-43dd-a7a8-a29935261ae9
        dq 0
GUID_WICPixelFormat32bppPBGRA   GUID 6fddc324-4e03-4bfe-b185-3d77768dc910
        dq 0
        
        CLSCTX_INPROC_SERVER = 1
        COINIT_APARTMENTTHREADED = 2
        COINIT_DISABLE_OLE1DDE = 4
        D2D1_FACTORY_TYPE_SINGLE_THREADED = 0
        
                struct  D2D1_PIXEL_FORMAT
                        format          dd 0
                        alphaMode       dd 0
                ends
                struct  D2D1_BITMAP_PROPERTIES
                        pixelFormat     D2D1_PIXEL_FORMAT
                        dpiX            dd 96.0f
                        dpiY            dd 96.0f
                ends
        BitmapProperties        D2D1_BITMAP_PROPERTIES
                DXGI_FORMAT_B8G8R8A8_UNORM = 87
                D2D1_ALPHA_MODE_PREMULTIPLIED = 1
                struct  D2D1_PIXEL_FORMAT2
                        format          dd DXGI_FORMAT_B8G8R8A8_UNORM
                        alphaMode       dd D2D1_ALPHA_MODE_PREMULTIPLIED
                ends
                struct  D2D1_RENDER_TARGET_PROPERTIES
                        type            dd 0
                        pixelFormat     D2D1_PIXEL_FORMAT2
                        dpiX            dd 0
                        dpiY            dd 0
                        usage           dd 0    ;D2D1_RENDER_TARGET_USAGE
                        minLevel        dd 0
                ends
        renderTargetProperties D2D1_RENDER_TARGET_PROPERTIES
                struct  D2D1_SIZE_F ;float
                        width   dd ?
                        height  dd ?
                ends
                struct  D2D1_SIZE_U
                        width   dd ?
                        height  dd ?
                ends
                
                struct  D2D1_RECT_F
                        left            dd 0 ;float
                        top                     dd 0
                        right           dd 0
                        bottom          dd 0
                ends
        align 16
        Rect            RECT
        D2D1RectF       RECT
        
        
        D2D1SizeF       D2D1_SIZE_F
        D2D1SizeU       D2D1_SIZE_U
        
        D2D1Tag1                dq 0
        D2D1Tag2                dq 0
        
        
        
        HeapEnableTerminationOnCorruption = 1
        wcex            WNDCLASSEX
        className               db 'myClass',0
        DLGWINDOWEXTRA = 48
        hProcess                dq ?
        hDCWindow               dq ?
        hDCCompatible   dq ?
        msg                             MSG
        colorref                dd 0
        
                struct  BLENDFUNCTION
                        BlendOp                         db 1 ;AC_SRC_OVER
                        BlendFlags                      db 0
                        SourceConstantAlpha     db 255
                        AlphaFormat                     db 1 ;AC_SRC_ALPHA
                ends
        blendfunction   BLENDFUNCTION
        Point                   POINT
        
        
        cbStride        dq ?
        
        
        passDraw        db 0
.code
        ;invoke HeapSetInformation,0,HeapEnableTerminationOnCorruption,0,0
        mov             [wcex.cbSize],sizeof.WNDCLASSEX
        mov             [wcex.style],CS_HREDRAW or CS_VREDRAW
        mov             [wcex.lpfnWndProc],WndProc
        mov             [wcex.cbClsExtra],0
        mov             [wcex.cbWndExtra],DLGWINDOWEXTRA
        invoke  GetModuleHandle,0
        mov             [wcex.hInstance],rax
        invoke  LoadIcon,rax,IDI_ICON
        mov             [wcex.hIcon],rax
        invoke  LoadCursor,0,IDC_ARROW
        mov             [wcex.hCursor],rax
        mov             [wcex.hbrBackground],0
        ;mov            [wcex.lpszMenuName],0
        mov             [wcex.lpszClassName],className
        mov             [wcex.hIconSm],0
        invoke  RegisterClassEx,wcex
        invoke  CreateWindowEx,WS_EX_LAYERED or WS_EX_TOPMOST,\
                        className,'Any temp',\
                        WS_POPUP or WS_VISIBLE,\
                        CW_USEDEFAULT,CW_USEDEFAULT,640,480,0,0,[wcex.hInstance],0
        mov             [hProcess],rax
        @@:
        invoke  GetMessage,msg,0,0,0
        invoke  DispatchMessage,msg
        jmp @b
        
        
proc    WndProc         uses rbx rsi rdi,hWnd,wMsg,wParam,lParam
        mov                     [hWnd],rcx
        mov                     [wMsg],rdx
        mov                     [wParam],r8
        mov                     [lParam],r9

        cmp             rdx,WM_CREATE
                je      .wm_create
        cmp             rdx,WM_PAINT
                je      .wm_paint
        cmp             rdx,WM_SIZE
                je      .wm_size
        cmp             rdx,WM_CLOSE
                je      .wm_close
        .wm_default:
                invoke          DefWindowProc,[hWnd],[wMsg],[wParam],[lParam]
                ret
        .wm_create:
                invoke  CoInitializeEx,0,\
                                COINIT_APARTMENTTHREADED or COINIT_DISABLE_OLE1DDE
                invoke  CoCreateInstance,CLSID_WICImagingFactory,0,\
                                CLSCTX_INPROC_SERVER,IID_IWICImagingFactory,pIWICFactory
                invoke  D2D1CreateFactory,D2D1_FACTORY_TYPE_SINGLE_THREADED,\
                                IID_ID2D1Factory,0,pD2D1Factory
                                
                                
                cominvk pIWICFactory,CreateStream,pIWICStream
                
                cominvk pIWICStream,InitializeFromMemory,image,imagesize
                
                cominvk pIWICFactory,CreateDecoderFromStream,[pIWICStream],0,1,\
                                pIWICDecoder
                
                cominvk pIWICFactory,CreateFormatConverter,pIWICConverter
                
                cominvk pIWICDecoder,GetFrame,0,pIWICFrameDecoder
                
                cominvk pIWICConverter,Initialize,[pIWICFrameDecoder],\
                                GUID_WICPixelFormat32bppPBGRA,0,0,float 0.0f,0  ;or 1
;;;
                invoke  GetClientRect,[hWnd],Rect
                cvtdq2ps xmm1,xword[Rect]
                movaps  xword[D2D1RectF],xmm1

                cominvk pD2D1Factory,CreateDCRenderTarget,\
                                renderTargetProperties,\
                                pD2D1Target
                invoke  GetDC,[hWnd]
                mov             [hDCWindow],rax
                invoke  CreateCompatibleDC,[hDCWindow]
                mov             [hDCCompatible],rax
                cominvk pD2D1Target,BindDC,[hDCCompatible],Rect
                
                cominvk pD2D1Target,CreateBitmapFromWicBitmap,[pIWICConverter],\
                                0,pD2D1Bitmap   ;0 or BitmapProperties
                ret
        .wm_size:
                ;...
        .wm_paint:
                cmp             [passDraw],0
                jne             .wm_default
                mov             [passDraw],1
                
                invoke  SetLayeredWindowAttributes,[hWnd],colorref,200,2

                mov     [D2D1RectF.left],0
                mov     [D2D1RectF.top],0
                mov     [D2D1RectF.right],640.0f
                mov     [D2D1RectF.bottom],480.0f
                mov     [Point.x],0
                mov     [Point.y],0
                
                cominvk pD2D1Target,BeginDraw
                cominvk pD2D1Target,DrawBitmap,[pD2D1Bitmap],D2D1RectF,\
                                float 0.5f,1,0
                cominvk pD2D1Target,EndDraw,D2D1Tag1,D2D1Tag2
                
        invoke  UpdateLayeredWindow,[hWnd],[hDCWindow],Point,\
                        0,[hDCCompatible],Point,\
                        colorref,\
                        blendfunction
;here is the error
                mov             [passDraw],0
                ret
        .wm_close:
                invoke  ExitProcess,0
                ret
endp
        
.data
        image       file 'Res\Tray.png'
        ;db 1228800 dup(0)
        imagesize = $-image    

Same result with hwndRenderTarget. Seems I missing something
Post 16 Aug 2021, 17:11
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3387
Location: vpcmipstrm
bitRAKE
What is the dwFlags value of UpdateLayeredWindow?

_________________
¯\(°_o)/¯ unlicense.org
Post 16 Aug 2021, 19:31
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 442
Location: Ukraine
Overclick
Done, but error still the same.
Code:
invoke  UpdateLayeredWindow,[hWnd],[hDCWindow],Point,\
                        0,[hDCCompatible],Point,\
                        colorref,blendfunction,dword 2    
Post 17 Aug 2021, 05:35
View user's profile Send private message Visit poster's website Reply with quote
Hrstka



Joined: 05 May 2008
Posts: 32
Location: Czech republic
Hrstka
In .wm_create: after CreateCompatibleDC, you should call ReleaseDC

In .wm_paint: Use BeginPaint to get the DC and EndPaint when you're done
Post 17 Aug 2021, 13:12
View user's profile Send private message Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 442
Location: Ukraine
Overclick
I did
Code:
                invoke  GetWindowDC,[hWnd]
                mov             [hDCWindow],rax
                invoke  CreateCompatibleDC,[hDCWindow]
                mov             [hDCCompatible],rax
                invoke  ReleaseDC,[hWnd],[hDCWindow]    


Code:
                invoke  BeginPaint,[hWnd],lpPaint
                mov             [hDCWindow],rax
...
        invoke  UpdateLayeredWindow,[hWnd],[hDCWindow],Point,\
                        0,[hDCCompatible],Point,\
                        colorref,blendfunction,dword 2
        invoke  EndPaint,[hWnd],lpPaint    

Still the same error after UpdateLayeredWindow
I'm trying to translate this example to asm but I'm not sure my png converted at all
https://docs.microsoft.com/en-us/archive/msdn-magazine/2009/december/windows-with-c-layered-windows-with-direct2d


Description:
Filesize: 27.73 KB
Viewed: 4207 Time(s)

Capture.PNG


Post 17 Aug 2021, 15:58
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3387
Location: vpcmipstrm
bitRAKE
Several places the documentation warns:
Quote:
Please note that after SetLayeredWindowAttributes has been called, subsequent UpdateLayeredWindow calls will fail until the layering style bit is cleared and set again.
I don't see any toggling of the WS_EX_LAYERED bit in any fragments you've posted. You seem to be mixing the simple and complex layering methods. Early in the article it touches on the two types of layered windows.

Simple layered windows use the SetLayeredWindowAttributes functions and WM_PAINT happens as typical.

The complex layered windows do not receive WM_PAINT messages and complete control of painting the entire window is through the UpdateLayeredWindow and UpdateLayeredWindowIndirect functions. The complex method is used throughout the article - there is no use of SetLayeredWindowAttributes except to demonstrate the simple type.

_________________
¯\(°_o)/¯ unlicense.org
Post 17 Aug 2021, 19:59
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 442
Location: Ukraine
Overclick
I seen this but I'm lost on it as no luck to find any more of good examples. What exactly that bit is and how to set it again?
Do you mean I have to SetWindowLong with that bit everytime after Update..?
If I wanna use complex one is that mean I have to use UpdateLayeredWindow by own refresh timer?
Why it doesn't show me my image by processing WM_PAINT as simple one?
Wich one exactly I need to get layered window as almost usual window or faster one? Do I really need that layered window to work with D2D1 engine?


Last edited by Overclick on 17 Aug 2021, 21:47; edited 1 time in total
Post 17 Aug 2021, 21:31
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3387
Location: vpcmipstrm
bitRAKE
SetWindowLong is used to change the bit.

The other questions I don't have answers to. I'll need to code my own example and see what works.

_________________
¯\(°_o)/¯ unlicense.org
Post 17 Aug 2021, 21:41
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 442
Location: Ukraine
Overclick
Funny answer when I edit my question ))


Description:
Filesize: 3.27 KB
Viewed: 4189 Time(s)

Capture.PNG


Post 17 Aug 2021, 21:49
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3387
Location: vpcmipstrm
bitRAKE
Here is the old process that has worked since WinXP:
https://github.com/miscellaneousmirrorrepositories/windows-XP-SP1/blob/d521b6360fcff4294ae6c5651c539f1b9a6cbb49/XPSP1/NT/windows/core/ntgdi/test/sprite/test.c#L274

I think using D2D1 will still be very similar.

If you want to switch from the simple/complex type then yes, bit must be cleared and then set again. This is to change the window manager behavior. It's like the window defaults to complex, but once SetLayeredWindowAttributes is called then it's locked to simple type.

That article is confusing because he creates a class and uses that throughout instead of the APIs directly.

_________________
¯\(°_o)/¯ unlicense.org
Post 17 Aug 2021, 22:03
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 442
Location: Ukraine
Overclick
Seems I need to add ID2D1GdiInteropRenderTarget instead of all old school I've done...
And now I understand why I need UpdateLayeredWindow instead of simple one. Bloody english need to read again and again to get the point I need :cry
Post 17 Aug 2021, 22:38
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 442
Location: Ukraine
Overclick
What else is wrong?
Code:
.idata
        import  kernel32clone,\
                        HeapSetInformation,'HeapSetInformation'
        import  user32clone,\
                        UpdateLayeredWindow,'UpdateLayeredWindow'
        import  D2d1,\
                        D2D1CreateFactory,'D2D1CreateFactory'
        import  ole32,\ 
                        CoInitializeEx,'CoInitializeEx',\ 
                        CoUninitialize,'CoUninitialize',\ 
                        CoCreateInstance,'CoCreateInstance',\
                        CoGetClassObject,'CoGetClassObject',\
                        CoTaskMemFree,'CoTaskMemFree'
.data
        interface               IWICImagingFactory,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        CreateDecoderFromFilename,\
                                        CreateDecoderFromStream,\
                                        CreateDecoderFromFileHandle,\
                                        CreateComponentInfo,\
                                        CreateDecoder,\
                                        CreateEncoder,\
                                        CreatePalette,\
                                        CreateFormatConverter,\
                                        CreateBitmapScaler,\
                                        CreateBitmapClipper,\
                                        CreateBitmapFlipRotator,\
                                        CreateStream,\
                                        CreateColorContext,\
                                        CreateColorTransformer,\
                                        CreateBitmap,\
                                        CreateBitmapFromSource,\
                                        CreateBitmapFromSourceRect,\
                                        CreateBitmapFromMemory,\
                                        CreateBitmapFromHBITMAP,\
                                        CreateBitmapFromHICON,\
                                        CreateComponentEnumerator,\
                                        CreateFastMetadataEncoderFromDecoder,\
                                        CreateFastMetadataEncoderFromFrameDecode,\
                                        CreateQueryWriter,\
                                        CreateQueryWriterFromReader
        interface               IWICStream,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        Read,\
                                        Write,\
                                        Seek,\
                                        SetSize,\
                                        CopyTo,\
                                        Commit,\
                                        Revert,\
                                        LockRegion,\
                                        UnlockRegion,\
                                        Stat,\
                                        Clone,\
                                        InitializeFromIStream,\
                                        InitializeFromFilename,\
                                        InitializeFromMemory,\
                                        InitializeFromIStreamRegion
        interface               IWICBitmapFrameDecode,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        GetSize,\
                                        GetPixelFormat,\
                                        GetResolution,\
                                        CopyPalette,\
                                        CopyPixels,\
                                        GetMetadataQueryReader,\
                                        GetColorContexts,\
                                        GetThumbnail
        interface               IWICFormatConverter,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        GetSize,\
                                        GetPixelFormat,\
                                        GetResolution,\
                                        CopyPalette,\
                                        CopyPixels,\
                                        Initialize,\
                                        CanConvert
        interface               IWICBitmapDecoder,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        QueryCapability,\
                                        Initialize,\
                                        GetContainerFormat,\
                                        GetDecoderInfo,\
                                        CopyPalette,\
                                        GetMetadataQueryReader,\
                                        GetPreview,\
                                        GetColorContexts,\
                                        GetThumbnail,\
                                        GetFrameCount,\
                                        GetFrame
        interface               IWICBitmap,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        GetSize,\
                                        GetPixelFormat,\
                                        GetResolution,\
                                        CopyPalette,\
                                        CopyPixels,\
                                        Lock,\
                                        SetPalette,\
                                        SetResolution
        interface               IWICBitmapSource,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        GetSize,\
                                        GetPixelFormat,\
                                        GetResolution,\
                                        CopyPalette,\
                                        CopyPixels
        

        
        interface               ID2D1Factory,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        ReloadSystemMetrics,\
                                        GetDesktopDpi,\
                                        CreateRectangleGeometry,\
                                        CreateRoundedRectangleGeometry,\
                                        CreateEllipseGeometry,\
                                        CreateGeometryGroup,\
                                        CreateTransformedGeometry,\
                                        CreatePathGeometry,\
                                        CreateStrokeStyle,\
                                        CreateDrawingStateBlock,\
                                        CreateWicBitmapRenderTarget,\
                                        CreateHwndRenderTarget,\
                                        CreateDxgiSurfaceRenderTarget,\
                                        CreateDCRenderTarget
        interface               ID2D1DCRenderTarget,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        GetFactory,\
                                        CreateBitmap,\
                                        CreateBitmapFromWicBitmap,\
                                        CreateSharedBitmap,\
                                        CreateBitmapBrush,\
                                        CreateSolidColorBrush,\
                                        CreateGradientStopCollection,\
                                        CreateLinearGradientBrush,\
                                        CreateRadialGradientBrush,\
                                        CreateCompatibleRenderTarget,\
                                        CreateLayer,\
                                        CreateMesh,\
                                        DrawLine,\
                                        DrawRectangle,\
                                        FillRectangle,\
                                        DrawRoundedRectangle,\
                                        FillRoundedRectangle,\
                                        DrawEllipse,\
                                        FillEllipse,\
                                        DrawGeometry,\
                                        FillGeometry,\
                                        FillMesh,\
                                        FillOpacityMask,\
                                        DrawBitmap,\
                                        DrawText,\
                                        DrawTextLayout,\
                                        DrawGlyphRun,\
                                        SetTransform,\
                                        GetTransform,\
                                        SetAntialiasMode,\
                                        GetAntialiasMode,\
                                        SetTextAntialiasMode,\
                                        GetTextAntialiasMode,\
                                        SetTextRenderingParams,\
                                        GetTextRenderingParams,\
                                        SetTags,\
                                        GetTags,\
                                        PushLayer,\
                                        PopLayer,\
                                        Flush,\
                                        SaveDrawingState,\
                                        RestoreDrawingState,\
                                        PushAxisAlignedClip,\
                                        PopAxisAlignedClip,\
                                        Clear,\
                                        BeginDraw,\
                                        EndDraw,\
                                        GetPixelFormat,\
                                        SetDpi,\
                                        GetDpi,\
                                        GetSize,\
                                        GetPixelSize,\
                                        GetMaximumBitmapSize,\
                                        IsSupported,\
                                        BindDC
        interface               ID2D1GdiInteropRenderTarget,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        GetDC,\
                                        ReleaseDC
        interface               ID2D1Bitmap,\
                                        QueryInterface,\
                                        AddRef,\
                                        Release,\
                                        GetFactory,\
                                        GetSize,\
                                        GetPixelSize,\
                                        GetPixelFormat,\
                                        GetDpi,\
                                        CopyFromBitmap,\
                                        CopyFromRenderTarget,\
                                        CopyFromMemory

        
        pIWICFactory                    IWICImagingFactory
        pIWICStream                     IWICStream
        pIWICDecoder                    IWICBitmapDecoder
        pIWICFrameDecoder               IWICBitmapFrameDecode
        pIWICBitmap                     IWICBitmap
        pIWICConverter                  IWICFormatConverter
        pIWICBitmapSource               IWICBitmapSource
        
        pD2D1Factory            ID2D1Factory
        pD2D1Bitmap             ID2D1Bitmap
        pD2D1Target             ID2D1DCRenderTarget
        pD2D1Interop            ID2D1GdiInteropRenderTarget
        
CLSID_WICImagingFactory                 GUID cacaf262-9370-4615-a13b-9f5539da4c0a
        dq 0
IID_IWICImagingFactory                  GUID ec5ec8a9-c395-4314-9c77-54d7a935ff70
        dq 0
IID_ID2D1Factory                                GUID 06152247-6f50-465a-9245-118bfd3b6007
        dq 0
GUID_WICPixelFormat32bppRGBA    GUID f5c7ad2d-6a8d-43dd-a7a8-a29935261ae9
        dq 0
GUID_WICPixelFormat32bppPBGRA   GUID 6fddc324-4e03-4bfe-b185-3d77768dc910
        dq 0
IID_ID2D1GdiInterop                             GUID e0db51c3-6f77-4bae-b3d5-e47509b35838
        dq 0
        CLSCTX_INPROC_SERVER = 1
        COINIT_APARTMENTTHREADED = 0x2
        COINIT_DISABLE_OLE1DDE = 0x4
        D2D1_FACTORY_TYPE_SINGLE_THREADED = 0
        
                struct  D2D1_PIXEL_FORMAT
                        format          dd 0
                        alphaMode       dd 0
                ends
                struct  D2D1_BITMAP_PROPERTIES
                        pixelFormat     D2D1_PIXEL_FORMAT
                        dpiX            dd 96.0f
                        dpiY            dd 96.0f
                ends
        BitmapProperties        D2D1_BITMAP_PROPERTIES
                DXGI_FORMAT_B8G8R8A8_UNORM = 87
                D2D1_ALPHA_MODE_PREMULTIPLIED = 1
                struct  D2D1_PIXEL_FORMAT2
                        format          dd DXGI_FORMAT_B8G8R8A8_UNORM
                        alphaMode       dd D2D1_ALPHA_MODE_PREMULTIPLIED
                ends
                struct  D2D1_RENDER_TARGET_PROPERTIES
                        type            dd 0
                        pixelFormat     D2D1_PIXEL_FORMAT2
                        dpiX            dd 0
                        dpiY            dd 0
                        usage           dd 2    ;D2D1_RENDER_TARGET_USAGE
                        minLevel        dd 0
                ends
        renderTargetProperties D2D1_RENDER_TARGET_PROPERTIES
                struct  D2D1_SIZE_F ;float
                        width   dd ?
                        height  dd ?
                ends
                struct  D2D1_SIZE_U
                        width   dd ?
                        height  dd ?
                ends
                
                struct  D2D1_RECT_F
                        left            dd 0 ;float
                        top                     dd 0
                        right           dd 0
                        bottom          dd 0
                ends
        align 16
        Rect                    RECT
        D2D1RectF       RECT
        
        D2D1SizeF       D2D1_SIZE_F
        D2D1SizeU       D2D1_SIZE_U
        
        D2D1Tag1                dq 0
        D2D1Tag2                dq 0
        
        HeapEnableTerminationOnCorruption = 1
        wcex            WNDCLASSEX
        className               db 'myClass',0
        DLGWINDOWEXTRA = 48
        hProcess                dq ?
        hDCWindow               dq ?
        hDCCompatible   dq ?
        hDCInterop              dq ?
        msg                             MSG
        colorref                dd 0
        
                struct  BLENDFUNCTION
                        BlendOp                         db 1 ;AC_SRC_OVER
                        BlendFlags                      db 0
                        SourceConstantAlpha     db 255
                        AlphaFormat                     db 1 ;AC_SRC_ALPHA
                ends
        blendfunction   BLENDFUNCTION
        Point                   POINT
        lpPaint                 PAINTSTRUCT
        
        cbStride        dq ?
        
        
        passDraw        db 0
.code
        ;invoke HeapSetInformation,0,HeapEnableTerminationOnCorruption,0,0
        mov             [wcex.cbSize],sizeof.WNDCLASSEX
        mov             [wcex.style],CS_HREDRAW or CS_VREDRAW
        mov             [wcex.lpfnWndProc],WndProc
        mov             [wcex.cbClsExtra],0
        mov             [wcex.cbWndExtra],DLGWINDOWEXTRA
        invoke  GetModuleHandle,0
        mov             [wcex.hInstance],rax
        invoke  LoadIcon,rax,IDI_ICON
        mov             [wcex.hIcon],rax
        invoke  LoadCursor,0,IDC_ARROW
        mov             [wcex.hCursor],rax
        mov             [wcex.hbrBackground],0
        ;mov            [wcex.lpszMenuName],0
        mov             [wcex.lpszClassName],className
        mov             [wcex.hIconSm],0
        invoke  RegisterClassEx,wcex
        invoke  CreateWindowEx,WS_EX_LAYERED,\ ;or WS_EX_TOPMOST,\
                        className,'Any temp',\
                        WS_POPUP or WS_VISIBLE,\
                        CW_USEDEFAULT,CW_USEDEFAULT,640,480,0,0,[wcex.hInstance],0
        mov             [hProcess],rax
        @@:
        invoke  GetMessage,msg,0,0,0
        invoke  DispatchMessage,msg
        jmp @b
        
        
proc    WndProc         uses rbx rsi rdi,hWnd,wMsg,wParam,lParam
        mov                     [hWnd],rcx
        mov                     [wMsg],rdx
        mov                     [wParam],r8
        mov                     [lParam],r9

        cmp             rdx,WM_CREATE
                je      .wm_create
        cmp             rdx,WM_PAINT
                je      .wm_render
        cmp             rdx,WM_COMMAND
                je      .wm_render
        cmp             rdx,WM_SIZE
                je      .wm_size
        cmp             rdx,WM_CLOSE
                je      .wm_close
        .wm_default:
                invoke          DefWindowProc,[hWnd],[wMsg],[wParam],[lParam]
                ret
        .wm_create:
                mov             [hwndRenderTargetProperties.hwnd],rcx
                
                invoke  SetWindowLong,[hWnd],-20,WS_EX_LAYERED ;or WS_EX_TOPMOST
                invoke  CoInitializeEx,0,\
                                COINIT_APARTMENTTHREADED or COINIT_DISABLE_OLE1DDE
                invoke  CoCreateInstance,CLSID_WICImagingFactory,0,\
                                CLSCTX_INPROC_SERVER,IID_IWICImagingFactory,pIWICFactory
                invoke  D2D1CreateFactory,D2D1_FACTORY_TYPE_SINGLE_THREADED,\
                                IID_ID2D1Factory,0,pD2D1Factory         
                cominvk pIWICFactory,CreateStream,pIWICStream
                cominvk pIWICStream,InitializeFromMemory,image,imagesize
                cominvk pIWICFactory,CreateDecoderFromStream,[pIWICStream],0,1,\
                                pIWICDecoder
                cominvk pIWICFactory,CreateFormatConverter,pIWICConverter
                cominvk pIWICDecoder,GetFrame,0,pIWICFrameDecoder
                cominvk pIWICConverter,Initialize,[pIWICFrameDecoder],\
                                GUID_WICPixelFormat32bppPBGRA,0,0,float qword 0.0f,0  ;or 1
                invoke  GetClientRect,[hWnd],Rect
                cvtdq2ps xmm1,xword[Rect]
                movaps  xword[D2D1RectF],xmm1
                cominvk pD2D1Factory,CreateDCRenderTarget,\
                                renderTargetProperties,\
                                pD2D1Target                     
                invoke  GetDC,[hWnd]
                mov             [hDCWindow],rax
                invoke  CreateCompatibleDC,[hDCWindow]
                mov             [hDCCompatible],rax
                cominvk pD2D1Target,BindDC,[hDCCompatible],Rect
                invoke  ReleaseDC,[hWnd],[hDCWindow]
                cominvk pD2D1Target,CreateBitmapFromWicBitmap,[pIWICConverter],\
                                BitmapProperties,pD2D1Bitmap    ;0 or BitmapProperties
                cominvk pD2D1Target,QueryInterface,IID_ID2D1GdiInterop,\
                                pD2D1Interop
                mov     [Point.x],0
                mov     [Point.y],0
                invoke  ShowWindow,[hWnd],SW_SHOW
                ret
        .wm_size:
                invoke  GetClientRect,[hWnd],Rect
                cvtdq2ps xmm1,xword[Rect]
                movaps  xword[D2D1RectF],xmm1
        .wm_render:
                cmp             [passDraw],0
                jne             .wm_default
                mov             [passDraw],1

                invoke  BeginPaint,[hWnd],lpPaint
                mov             [hDCWindow],rax
                cominvk pD2D1Target,BeginDraw
                cominvk pD2D1Target,DrawBitmap,[pD2D1Bitmap],D2D1RectF,\
                                float 0.5f,1,0
                cominvk pD2D1Interop,GetDC,0,hDCInterop
                invoke  UpdateLayeredWindow,[hWnd],[hDCWindow],Point,\
                        0,[hDCInterop],Point,\
                        colorref,blendfunction,dword 2
                cominvk pD2D1Interop,ReleaseDC,Rect
                cominvk pD2D1Target,EndDraw,D2D1Tag1,D2D1Tag2
                invoke  SetWindowLong,[hWnd],-20,0
                invoke  SetWindowLong,[hWnd],-20,WS_EX_LAYERED or WS_EX_TOPMOST
        
        
        
                invoke  EndPaint,[hWnd],lpPaint
                mov             [passDraw],0
                ret
        .wm_close:
                invoke  ExitProcess,0
                ret
endp

.data
        image       file 'Res\Tray.png'
        ;db 1228800 dup(0)
        imagesize = $-image    

I have black rect on screen... no errors after every single call on code even cominvk pD2D1Target,EndDraw,D2D1Tag1,D2D1Tag2


Last edited by Overclick on 19 Aug 2021, 11:10; edited 1 time in total
Post 19 Aug 2021, 07:06
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1088
Roman
Use null, null in enddraw

https://docs.microsoft.com/en-us/windows/win32/api/d2d1/nf-d2d1-id2d1rendertarget-enddraw

Try write pD2D1Interop,ReleaseDC,Rect after endpaint.

And try write D2D1RectF dd 0,0,200.0,200.0
And not use getclientrect.
I don't like this cvtdq2ps. You shoure its gived correct value?
Post 19 Aug 2021, 08:31
View user's profile Send private message Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 442
Location: Ukraine
Overclick
I tried to setup it manually. There is no problem with that.
Code:
                invoke  BeginPaint,[hWnd],lpPaint
                mov             [hDCWindow],rax
                cominvk pD2D1Target,BeginDraw
                cominvk pD2D1Target,DrawBitmap,[pD2D1Bitmap],D2D1RectF,\
                                float 0.5f,1,0
                cominvk pD2D1Interop,GetDC,0,hDCInterop
                invoke  UpdateLayeredWindow,[hWnd],[hDCWindow],Point,\
                        0,[hDCInterop],Point,\
                        colorref,blendfunction,dword 2
        invoke  EndPaint,[hWnd],lpPaint
        cominvk pD2D1Interop,ReleaseDC,Rect
        cominvk pD2D1Target,EndDraw,D2D1Tag1,D2D1Tag2
                invoke  SetWindowLong,[hWnd],-20,0
                invoke  SetWindowLong,[hWnd],-20,WS_EX_LAYERED or WS_EX_TOPMOST    

Nothing changed
Post 19 Aug 2021, 09:58
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1088
Roman
Overclick attach rar you example and source code (for compiling).
I test in home to day.
Post 19 Aug 2021, 13:58
View user's profile Send private message Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 442
Location: Ukraine
Overclick
I've got some info for that bloody LayeredWindows -- as someone says it needs EnableAeroPeek to be true and DWMSM running
AeroPeek on my 2008r2 is disabled... Aero running ok... confused...
Going to test it again...
Post 19 Aug 2021, 14:56
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1088
Roman
I think you have problem with pD2D1Target,DrawBitmap.
Test only direct2d without LayeredWindows.

And make sure it works you direct2d.

Propose try m_pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White));
Clear color Direct2d and see if you window color correct.
You problem in pD2D1Target,DrawBitmap.

pColor dd 1.0,0,0,1.0 ;window must be red
cominvk pD2D1Target,Clear,pColor
Post 19 Aug 2021, 15:05
View user's profile Send private message Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 442
Location: Ukraine
Overclick
In normal window it shows my picture ok (on black backgroung)
So png is converted ok. Problem is by wrong DCs
I need to transparent that background
Post 19 Aug 2021, 15:23
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 442
Location: Ukraine
Overclick
That Layered bit cause that trouble...
I think I reset it in wrong way
Post 19 Aug 2021, 15:28
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.