#include <GUIConstantsEx.au3>
; #include <WindowsConstants.au3>

; ====  Um den Effekt zu sehen, mehrmals auf den OK-Button klicken.  ====
; ====  To see the effect, click the OK button several times.        ====

Opt("MustDeclareVars", 1)

Example()

Func Example()

  ; GUI
  Local $iGuiHeight = 120
  Local $hGui = GUICreate("My GUI", 260, $iGuiHeight, 510, 310)

  ; Label Main
  Local $aLblMainRect
  Local $idLabel_Main = GUICtrlCreateLabel("This is a sample text to fill the label.", 0, 8)
  GUICtrlSetBkColor($idLabel_Main, 0xFFCC00)

  ; Button "Ok"
  Local $idBtn = GUICtrlCreateButton("Ok", 40, 75, 60, 20)

	GUISetState(@SW_SHOW)


	While 1
		Switch GUIGetMsg()

			Case $GUI_EVENT_CLOSE
				ExitLoop

      Case $idBtn

        ; Determine the dimensions of the label.
        ; [0] = X-Position
        ; [1] = Y-Position
        ; [2] = Breite
        ; [3] = Höhe
        $aLblMainRect = ControlGetPos($hGui, "", $idLabel_Main)

;         If @error Then MsgBox(0, "", "Error")

        ; Try to adjust the width of the GUI to the width of the label.
        WinMove($hGui, "", 500, 300, $aLblMainRect[2], $iGuiHeight)

		EndSwitch
	WEnd
	GUIDelete()
EndFunc   ;==>Example
