Jump to content
Sign in to follow this  
Anas

GDI+ CPU Usage

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

Share this post


Link to post
Share on other sites

I meant the process CPU usage, not the overall CPU usage.

and the same script will run with almost no CPU usage without these programs/content.

Share this post


Link to post
Share on other sites

Actually I just tested it, and unlike the one I use, it seems that this one is only affected by Games ;)

can you please test it with a directx game?

Share this post


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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...