Jump to content

WM_PAINT with BitBlt [solved]


Recommended Posts

I am using BitBlt for smoothness of image changing on the gui. And I have a strange problem

When I restore window after minimizing the Image wont redraw and only if I add sleep(2000) to wm_paint function it would redraw after sleep time, what I am doing wrong?

 

#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>



gui_func()




func gui_func()
Global $hBMP, $hBitmap, $hGraphic, $hImage, $iX, $iY, $hClone, $t, $aMPos
Global $GuiSizeX = 974, $GuiSizeY = 510
Global $pngFile =   "1.bmp"
Global $pngFile2 =  "tst2-1.bmp"
Global $hGUI = GUICreate("GDI+", $GuiSizeX, $GuiSizeY)
GUISetState()
_GDIPlus_Startup()
Global $hBitmap = _GDIPlus_ImageLoadFromFile($pngFile) ;create an empty bitmap
Global    $g_hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ;convert GDI+ bitmap to GDI bitmap
_GDIPlus_BitmapDispose($hBitmap) ;delete GDI+ bitmap because not needed anymore
Global  $g_hDC = _WinAPI_GetDC($hGUI) ;get device context from GUI
Global  $g_hDC_Backbuffer = _WinAPI_CreateCompatibleDC($g_hDC) ;creates a memory device context compatible with the specified device
$g_oDC_Obj = _WinAPI_SelectObject($g_hDC_Backbuffer, $g_hHBITMAP) ;selects an object into the specified device context
$g_hGfxCtxt = _GDIPlus_GraphicsCreateFromHDC($g_hDC_Backbuffer) ;create a graphics object from a device context (DC)
_GDIPlus_GraphicsSetSmoothingMode($g_hGfxCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;set smoothing mode (8 X 4 box filter)
_GDIPlus_GraphicsSetPixelOffsetMode($g_hGfxCtxt, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
_WinAPI_BitBlt($g_hDC, 0, 0, $GuiSizeX, $GuiSizeY, $g_hDC_Backbuffer, 0, 0, $SRCCOPY)
GUIRegisterMsg($WM_PAINT, "MY_PAINT")
_WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_INVALIDATE + $RDW_UPDATENOW)
while 1


wend
endfunc

Func MY_PAINT()
;sleep (2000)
_WinAPI_BitBlt($g_hDC, 0, 0, $GuiSizeX, $GuiSizeY, $g_hDC_Backbuffer, 0, 0, $SRCCOPY)
EndFunc ;==>MY_PAINT

Thanx in advance!

Edited by topten
Link to post
Share on other sites
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>



gui_func()




Func gui_func()
    Global $hBMP, $hBitmap, $hGraphic, $hImage, $iX, $iY, $hClone, $t, $aMPos
    Global $GuiSizeX = 974, $GuiSizeY = 510
    Global $pngFile = "GDI+.bmp"
    Global $hGUI = GUICreate("GDI+", $GuiSizeX, $GuiSizeY)
    GUISetState()

    _GDIPlus_Startup()
    Global $hBitmap = _GDIPlus_ImageLoadFromFile($pngFile) ;create an empty bitmap
    Global $g_hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ;convert GDI+ bitmap to GDI bitmap
    _GDIPlus_BitmapDispose($hBitmap) ;delete GDI+ bitmap because not needed anymore
    Global $g_hDC = _WinAPI_GetDC($hGUI) ;get device context from GUI
    Global $g_hDC_Backbuffer = _WinAPI_CreateCompatibleDC($g_hDC) ;creates a memory device context compatible with the specified device
    $g_oDC_Obj = _WinAPI_SelectObject($g_hDC_Backbuffer, $g_hHBITMAP) ;selects an object into the specified device context
    $g_hGfxCtxt = _GDIPlus_GraphicsCreateFromHDC($g_hDC_Backbuffer) ;create a graphics object from a device context (DC)
    _GDIPlus_GraphicsSetSmoothingMode($g_hGfxCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;set smoothing mode (8 X 4 box filter)
    _GDIPlus_GraphicsSetPixelOffsetMode($g_hGfxCtxt, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
    _WinAPI_BitBlt($g_hDC, 0, 0, $GuiSizeX, $GuiSizeY, $g_hDC_Backbuffer, 0, 0, $SRCCOPY)
    GUIRegisterMsg($WM_PAINT, "MY_PAINT")

    While True
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                _WinAPI_SelectObject($g_hDC_Backbuffer, $g_oDC_Obj)
                _GDIPlus_GraphicsDispose($g_hGfxCtxt)
                _WinAPI_DeleteObject($g_hHBITMAP)
                _WinAPI_ReleaseDC($hGUI, $g_hDC)
                _WinAPI_DeleteDC($g_hDC_Backbuffer)
                _GDIPlus_Shutdown()
                GUIDelete($hGUI)
                Exit
            Case $GUI_EVENT_RESTORE
                MY_PAINT()
        EndSwitch

    WEnd
EndFunc   ;==>gui_func

Func MY_PAINT()
    ;sleep (2000)
    _WinAPI_BitBlt($g_hDC, 0, 0, $GuiSizeX, $GuiSizeY, $g_hDC_Backbuffer, 0, 0, $SRCCOPY)
    Return "GUI_RUNDEFMSG"
EndFunc   ;==>MY_PAINT

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...