Jump to content

GDI+ CPU Usage


Anas
 Share

Recommended Posts

Hello

If I run a GDIplus code in a loop then run a Game, WMP or some webpages (like Youtube) the CPU usage increases from 0 to 30-45% till that program is closed, is this normal? Can it be avoided without having to increase sleep time?

Example:

#include <GUIConstants.au3>
#include <GDIplus.au3>

Global Const $width=100
Global Const $height=10
GLobal $title="GDI+"

; Build your GUI here
Opt("GUIOnEventMode",1)
$hwnd = GUICreate($title,$width,$height)
GUISetOnEvent($GUI_EVENT_CLOSE, "close")
GUISetState()

; Load your GDI+ resources here:
_GDIPlus_Startup()
$graphics=_GDIPlus_GraphicsCreateFromHWND($hwnd)
$bitmap=_GDIPlus_BitmapCreateFromGraphics($width,$height,$graphics)
$backbuffer=_GDIPlus_ImageGetGraphicsContext($bitmap)

$hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
$hFormat = _GDIPlus_StringFormatCreate()
_GDIPlus_StringFormatSetAlign($hFormat, 1)

Do
    _GDIPlus_GraphicsClear($backbuffer)

    $hFamily = _GDIPlus_FontFamilyCreate("7px2bus")
    $hFont = _GDIPlus_FontCreate($hFamily, 5.5, 0)

    $tLayout = _GDIPlus_RectFCreate(8, 3, 0, 0)
    _GDIPlus_GraphicsDrawStringEx($backbuffer, "0", $hFont, $tLayout, $hFormat, $hBrush)

    _GDIPlus_GraphicsDrawImageRect($graphics,$bitmap,0,0,$width,$height)
    Sleep(10)
Until False

Func close()
    _GDIPlus_GraphicsDispose($backbuffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_GraphicsDispose($graphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc
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...