HRWL Posted May 30, 2017 Share Posted May 30, 2017 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? expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.2 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 GUISetState(@SW_SHOW) Graphics() ;;;$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 Do $gMsg = GUIGetMsg() Move() Update() If $gMsg = $gui_event_resized Then Graphics() EndIf Until $gMsg = $GUI_EVENT_CLOSE ;cleanup GDI+ resources _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_GraphicsDispose($hBitmap) _GDIPlus_GraphicsDispose($hBackbuffer) _GDIPlus_Shutdown() GUIDelete($hGUI) DllClose($hD32) Exit(0) Func Graphics() Local $aWindow = WinGetPos($hGui) $iWidth = $aWindow[2] $iHeight = $aWindow[3] _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_GraphicsDispose($hBitmap) _GDIPlus_GraphicsDispose($hBackbuffer) $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) EndFunc Func Check() ;xpos+ check If ($ObjectList[$iCurrentObj][0] + $ObjectList[$iCurrentObj][2] > $iWidth) Then $ObjectList[$iCurrentObj][0] = $iWidth - $ObjectList[$iCurrentObj][2] EndIf ;xpos- check If ($ObjectList[$iCurrentObj][0] < 0) Then $ObjectList[$iCurrentObj][0] = 0 EndIf ;ypos+ check If ($ObjectList[$iCurrentObj][1] + $ObjectList[$iCurrentObj][3] > $iHeight) Then $ObjectList[$iCurrentObj][1] = $iHeight - $ObjectList[$iCurrentObj][3] EndIf ;ypos- check If ($ObjectList[$iCurrentObj][1] < 0) Then $ObjectList[$iCurrentObj][1] = 0 EndIf EndFunc Func Move() If Not WinActive($hGUI) Then Return Local $Rate = 1 ;shift faster! If _IsPressed("10", $hD32) Then $Rate *= 10 EndIf ;left If _IsPressed("25", $hD32) Then $ObjectList[$iCurrentObj][0] -= $Rate EndIf ;Up If _IsPressed("26", $hD32) Then $ObjectList[$iCurrentObj][1] -= $Rate EndIf ;Right If _IsPressed("27", $hD32) Then $ObjectList[$iCurrentObj][0] += $Rate EndIf ;Down If _IsPressed("28", $hD32) Then $ObjectList[$iCurrentObj][1] += $Rate EndIf Check() EndFunc Func Update() _GDIPlus_GraphicsClear($hBackbuffer) For $I = 0 To UBound($ObjectList) - 1 _GDIPlus_PenDispose($hPen) $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) Next EndFunc Link to comment Share on other sites More sharing options...
HRWL Posted May 31, 2017 Author Share Posted May 31, 2017 Nevermind, found the error once I had a good nights rest Link to comment Share on other sites More sharing options...
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