Jump to content

_GDIPlus_GraphicsDrawImage


lee321987
 Share

Recommended Posts

Sometimes when I run this script the image (bitmap.gif) displays, and sometimes it does not. I can't figure out why.

(bitmap.gif is attached)

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

Global $hForm1, $hBitmap, $hGraphic, $nMsg

$hForm1 = GUICreate("GDI_Tester", 200, 100)
GUISetState(@SW_SHOW, $hForm1)

_GDIPlus_Startup()

$hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\bitmap.gif"); create a bitmap object from file
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hForm1); create a graphic object in form1
_GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0); draws the bitmap image in the graphic


While 1
    $nMsg = GUIGetMsg()
    If $nMsg = $GUI_EVENT_CLOSE Then
;~ ; Clean up resources
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_ImageDispose($hBitmap)
        _WinAPI_DeleteObject($hBitmap)
;~ ; Shut down GDI+ library
        _GDIPlus_Shutdown()
        Exit
    EndIf
WEnd

post-49471-12604089610715_thumb.gif

Link to comment
Share on other sites

You need to redraw the image.

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

Global $hForm1, $hBitmap, $hGraphic, $nMsg

$hForm1 = GUICreate("GDI_Tester", 200, 100)
GUIRegisterMsg($WM_PAINT, 'WM_PAINT')
GUISetState(@SW_SHOW, $hForm1)

_GDIPlus_Startup()

$hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\bitmap.gif"); create a bitmap object from file
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hForm1); create a graphic object in form1
_GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0); draws the bitmap image in the graphic


While 1
    $nMsg = GUIGetMsg()
    If $nMsg = $GUI_EVENT_CLOSE Then
;~ ; Clean up resources
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_ImageDispose($hBitmap)
        _WinAPI_DeleteObject($hBitmap)
;~ ; Shut down GDI+ library
        _GDIPlus_Shutdown()
        Exit
    EndIf
WEnd

Func WM_PAINT($hWnd, $iMsg, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_PAINT
Edited by Yashied
Link to comment
Share on other sites

Sometimes when? I can think of two possibilities.

1) You set the focus to another window (which covers your GUI) and then switch back to your GUI, you see it.

2) You minimize your GUI and restore the window, you don't see it.

Do you mean that on start up, you sometimes see it and other times you don't?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...