Jump to content

Gui & GDI+ resizing issue

Recommended Posts


Been wracking my head trying to figure out why when I resize the gui, GDI+ remaking the controls start getting wrong dimensions and go beyond the window,
Can anyone lend me a second set of eyes and point out what I screwed up if anything?

#cs ----------------------------------------------------------------------------

 AutoIt Version:
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <Array.au3>
#include <WindowsConstants.au3>

Global $iWidth, $iHeight, $iBgColor, $iCurrentObj
Global $hD32, $hGraphics, $hGUI, $hPen, $hBitmap, $hBackbuffer
;$Object[xPos, yPos, oWidth, oHeight, oColor, oName]
Global $ObjectList[1][6]

$hD32 = DllOpen("user32.dll")
$iWidth = 600
$iHeight = 800
$iBgColor = 0x202020
$iCurrentObj = 0

_GDIPlus_Startup() ;initialize GDI+

$hGUI = GUICreate("Example", $iWidth, $iHeight, -1, -1, $WS_SIZEBOX) ;create a test GUI
GUISetBkColor($iBgColor, $hGUI) ;set GUI background color


;;;$Object[xPos, yPos, oWidth, oHeight, oColor, oName]
;Global $xPos, $yPos, $oWidth, $oHeight
;$xPos = 0
;$yPos = 0
;$oWidth = 100
;$oHeight = 50

$ObjectList[0][0] = 0 ; xpos
$ObjectList[0][1] = 0 ; ypos
$ObjectList[0][2] = 120 ; width
$ObjectList[0][3] = 150 ;height
$ObjectList[0][4] = 0xFFFFFFFF ; color with alpha
$ObjectList[0][5] = "test" ; name

Local $gMsg
   $gMsg = GUIGetMsg()
   If $gMsg = $gui_event_resized Then
Until $gMsg = $GUI_EVENT_CLOSE

;cleanup GDI+ resources

Func Graphics()
   Local $aWindow = WinGetPos($hGui)
   $iWidth = $aWindow[2]
   $iHeight = $aWindow[3]
   $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
   _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing)
   $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
   $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)

Func Check()
   ;xpos+ check
   If ($ObjectList[$iCurrentObj][0] + $ObjectList[$iCurrentObj][2] > $iWidth) Then
      $ObjectList[$iCurrentObj][0] = $iWidth - $ObjectList[$iCurrentObj][2]
   ;xpos- check
   If ($ObjectList[$iCurrentObj][0] < 0) Then
      $ObjectList[$iCurrentObj][0] = 0
   ;ypos+ check
   If ($ObjectList[$iCurrentObj][1] + $ObjectList[$iCurrentObj][3] > $iHeight) Then
      $ObjectList[$iCurrentObj][1] = $iHeight - $ObjectList[$iCurrentObj][3]
   ;ypos- check
   If ($ObjectList[$iCurrentObj][1] < 0) Then
      $ObjectList[$iCurrentObj][1] = 0


Func Move()
   If Not WinActive($hGUI) Then Return

   Local $Rate = 1

   ;shift faster!
   If _IsPressed("10", $hD32) Then
      $Rate *= 10

   If _IsPressed("25", $hD32) Then
      $ObjectList[$iCurrentObj][0] -= $Rate

   If _IsPressed("26", $hD32) Then
      $ObjectList[$iCurrentObj][1] -= $Rate

   If _IsPressed("27", $hD32) Then
      $ObjectList[$iCurrentObj][0] += $Rate

   If _IsPressed("28", $hD32) Then
      $ObjectList[$iCurrentObj][1] += $Rate


Func Update()
   For $I = 0 To UBound($ObjectList) - 1
      $hPen = _GDIPlus_PenCreate($ObjectList[$I][4], 4)
      _GDIPlus_GraphicsDrawRect($hBackbuffer, $ObjectList[$I][0], $ObjectList[$I][1], $ObjectList[$I][2], $ObjectList[$I][3], $hPen)
      _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iWidth, $iWidth)


Share this post

Link to post
Share on other sites

Nevermind, found the error once I had a good nights rest

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


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.