lee321987 Posted December 10, 2009 Posted December 10, 2009 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
Yashied Posted December 10, 2009 Posted December 10, 2009 (edited) 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 December 10, 2009 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
Authenticity Posted December 10, 2009 Posted December 10, 2009 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?
lee321987 Posted December 10, 2009 Author Posted December 10, 2009 Yes, on statup, sometimes the image is visible, sometimes not. To address your points: 1) That makes it visible. 2) Minimize/restore does not make it visible. @Yashied Thank you, but still has intermittent no-display of the image.
Authenticity Posted December 10, 2009 Posted December 10, 2009 And what happen if you add a sleep of 500 ms just after you show the window but before you draw the image?
lee321987 Posted December 10, 2009 Author Posted December 10, 2009 Thank you. I put a Sleep(20) right before _GDIPlus_GraphicsDrawImage, and the image now always shows. Thanks a lot.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now