News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

BeginBufferedPaint and EndBufferedPaint

Started by guga, June 25, 2012, 01:52:29 PM

Previous topic - Next topic

guga

Hi guys....as a test i made here http://masm32.com/board/index.php?topic=362.msg2343#msg2343
I created 2 functions for WinXP and below that tries to works on the same way as the ones existent in Windows Vista and Win7 (EndBufferedPaint and BeginBufferedPaint inside uxtheme.dll)

Can someone tell me if they are ok on the example i posted on the other thread ?
Btw: Syntax is for RosAsm

BeginBufferedPaintXP

;;
    BeginBufferedPaintXP V 1.0

    Begins a buffered paint operation.
    This function was designed to work in WinXp and below, on a similar way as BeginBufferedPaint existent in uxtheme.dll used in Windows Vista and above.

    Arguments:
        hDCWin (in) - The handle of the target DC on which the buffer will be painted.
        pRect (in) - A pointer to a RECT structure that specifies the area of the target DC in which to paint.
        phdcMem (out) - A pointer to the new device context created.
        pBmp (out) - A pointer to the newly created DIB
        phbmPrev (out) - Pointer to a handle of the selected bitmap (DIB).

    Return Values:
        If the function suceeds it returns a handle to the buffered paint context. (hdcMem)
        If the function fails, it returns &FALSE

    Remarks:
        If this function suceeds, it creates the values for phdcMem, pBmp, phbmPrev
        You must End this function using EndBufferedPaint

    Author:
        Gustavo Trigueiros (a.k.a: Beyond2000! or guga)
        25/06/2.012
;;

Proc BeginBufferedPaintXP:
    Arguments @hDCWin, @pRect, @phdcMem, @pBmp, @phbmPrev
    Local @RgbQuad
    Structure @BITMAPINFO 44, @BITMAPINFO.bmiHeader.biSizeDis 0, @BITMAPINFO.bmiHeader.biWidthDis 4, @BITMAPINFO.bmiHeader.biHeightDis 8, @BITMAPINFO.bmiHeader.biPlanesDis 12,
                              @BITMAPINFO.bmiHeader.biBitCountDis 14, @BITMAPINFO.bmiHeader.biCompressionDis 16, @BITMAPINFO.bmiHeader.biSizeImageDis 20,
                              @BITMAPINFO.bmiHeader.biXPelsPerMeterDis 24, @BITMAPINFO.bmiHeader.biYPelsPerMeterDis 28, @BITMAPINFO.bmiHeader.biClrUsedDis 32,
                              @BITMAPINFO.bmiHeader.biClrImportantDis 36, @BITMAPINFO.bmiColors.rgbBlueDis 40, @BITMAPINFO.bmiColors.rgbGreenDis 41,
                              @BITMAPINFO.bmiColors.rgbRedDis 42, @BITMAPINFO.bmiColors.rgbReservedDis 43

    Uses edi, ecx, ebx

    xor eax eax
    On D@phdcMem = 0, ExitP
    On D@pBmp = 0, ExitP
    On D@phbmPrev = 0, ExitP

    mov ecx D@phdcMem | mov D$ecx 0
    mov ecx D@pBmp | mov D$ecx 0
    mov ecx D@phbmPrev | mov D$ecx 0

    call 'GDI32.CreateCompatibleDC' D@hDCWin
    On eax = 0, ExitP
    mov edi D@phdcMem
    mov D$edi eax

    call ZeroMemory D@BITMAPINFO, 44
    mov D@RgbQuad 0
    mov ecx D@pRect
    mov ebx D$ecx+RECT.rightDis ; cx
    mov esi D$ecx+RECT.bottomDis ; cy
    mov D@BITMAPINFO.bmiHeader.biSizeDis 44
    mov D@BITMAPINFO.bmiHeader.biWidthDis ebx
    mov D@BITMAPINFO.bmiHeader.biHeightDis esi
    mov W@BITMAPINFO.bmiHeader.biPlanesDis 1
    mov D@BITMAPINFO.bmiHeader.biCompressionDis &BI_RGB

    lea eax D@RgbQuad
    call 'GDI32.CreateDIBSection' D@hDCWin, D@BITMAPINFO, &DIB_RGB_COLORS, eax, &NULL, 0
    .If eax = &NULL
        call 'GDI32.DeleteDC' D@phdcMem
        xor eax eax
    .Else
        mov edi D@pBmp
        mov D$edi eax
        ; SelectBitmap
        call 'GDI32.SelectObject' D@phdcMem, D@pBmp
        If eax = &NULL
            call 'GDI32.DeleteObject' D@pBmp
            call 'GDI32.DeleteDC' D@phdcMem
            xor eax eax
        Else
            mov edi D@phbmPrev
            mov D$edi eax
            mov eax D@phdcMem
        End_If
    .End_If
EndP


EndBufferedPaintXP

;;
    EndBufferedPaintXP V 1.0

    Completes a buffered paint operation and frees the associated buffered paint handle.
    This function was designed to work in WinXp and below, on a similar way as EndBufferedPaint existent in uxtheme.dll used in Windows Vista and above.

    Arguments:
        phdcMem (in) - A pointer to the new device context created with BeginBufferedPaintXP
        pBmp (in) - A pointer to the newly created DIB using BeginBufferedPaintXP
        phbmPrev (in) - Pointer to a handle of the selected bitmap (DIB) using BeginBufferedPaintXP.

    Return Values:
        If the function suceeds it returns &TRUE
        If the function fails, it returns &FALSE

    Remarks:
        The arguments must be previously created with BeginBufferedPaintXP.

    Author:
        Gustavo Trigueiros (a.k.a: Beyond2000! or guga)
        25/06/2.012
;;

Proc EndBufferedPaintXP:
    Arguments @hdcMem, @hBMP, @hbmPrev

    xor eax eax
    On D@hdcMem = 0, ExitP

    If_and D@hBMP <> 0, D@hbmPrev = 0
        call 'GDI32.DeleteObject' D@hBMP
        call 'GDI32.DeleteDC' D@hdcMem
        xor eax eax
    Else_If_and D@hBMP = 0, D@hbmPrev <> 0
        call 'GDI32.DeleteDC' D@hdcMem
        xor eax eax
    Else_If_and D@hBMP <> 0, D@hbmPrev <> 0
        call 'GDI32.SelectObject' D@hdcMem, D@hbmPrev
        call 'GDI32.DeleteObject' D@hBMP
        call 'GDI32.DeleteDC' D@hdcMem
        mov eax &TRUE
    End_If

EndP


Best Regards,

guga
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

dedndave

a lot depends on what you are trying to achieve
if you want a set of functions that completely emulates the following functions:
BeginBufferedAnimation
BeginBufferedPaint
BufferedPaintClear
BufferedPaintInit
BufferedPaintRenderAnimation
BufferedPaintSetAlpha
BufferedPaintStopAllAnimations
BufferedPaintUnInit

you have your work cut out for you
on the other hand, if you want to replace the functionality in one program, you might be ok

it seems that BeginBufferedPaint creates a DIB section, somewhere along the line
but making the set of functions compatible with the Vista/Win7 functions may not be easy
Quote
BufferedPaintInit is called before BeginBufferedPaint or BeginBufferedAnimation for each thread that uses these functions.

Each call to BufferedPaintInit should be matched with a call to BufferedPaintUnInit when calls to buffered paint APIs are no longer needed. An application may call this API multiple times, as long as each call to BufferedPaintInit is balanced with a call to BufferedPaintUnInit.

This function only needs to be called once in the lifetime of a thread. Typically, this function is called before creating the main application window, or during WM_CREATE. Call BufferedPaintUnInit after destroying the window, or during WM_NCDESTROY.