#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#cs
	Beispiel - Anfang
#ce
Opt('GUIOnEventMode', 1)
GUICreate('Beispiel', 600, 400)
GUISetOnEvent($GUI_EVENT_CLOSE, '_End')
GUICtrlCreateButton('Zeige Bild...', 20, 20, 160, 35)
GUICtrlSetOnEvent(-1, '_Show')
GUISetState()
While Sleep(50)
WEnd

Func _End()
	Exit
EndFunc   ;==>_End

Func _Show()
	Local $sPath
	$sPath = FileOpenDialog('Bilddatei auswählen', @WorkingDir, 'Images (*.jpg;*.bmp;*.png)', 3)
	If Not @error Then _ShowImage($sPath)
EndFunc   ;==>_Show
#cs
	Beispiel - Ende
#ce

;===============================================================================
; Function Name:   _ShowImage($sImgFile)
; Description::    Zeigt ein Bild in einem separaten Fenster an.
; Parameter(s):    $sImgFile = Pfad zu dem Bild
; Requirement(s):  #include <GDIPlus.au3>
;                  #include <GUIConstantsEx.au3>
;                  #include <WindowsConstants.au3>
; Return Value(s): wenn die Datei nicht existiert wird @error auf "1" gesetzt
; Author(s):       Oscar (www.autoit.de)
;===============================================================================
Func _ShowImage($sImgFile)
	If Not FileExists($sImgFile) Then Return SetError(1, 0, 0)
	Local $hGui, $hBitmap, $hGraphic, $aWinPos, $iFrameWidth, $iFrameHeight, $iImgWidth, $iImgHeight, $iFactor
	Local $iOldOpt = Opt('WinTitleMatchMode', 4)
	Local $aTaskbarPos = WinGetPos('classname=Shell_TrayWnd')
	Opt('WinTitleMatchMode', $iOldOpt)
	$iOldOpt = Opt('GUIOnEventMode', 0)
	Local $iGuiWidth = 300, $iGuiHeight = 300
	$hGui = GUICreate('Calc Frame', $iGuiWidth, $iGuiHeight, -1, -1, BitOR($WS_SYSMENU, $WS_CAPTION))
	_GDIPlus_Startup()
	$hBitmap = _GDIPlus_BitmapCreateFromFile($sImgFile)
	$aWinPos = WinGetPos($hGui)
	GUIDelete($hGui)
	$iFrameWidth = $aWinPos[2] - $iGuiWidth
	$iFrameHeight = $aWinPos[3] - $iGuiHeight + 10
	$iImgWidth = _GDIPlus_ImageGetWidth($hBitmap)
	$iImgHeight = _GDIPlus_ImageGetHeight($hBitmap)
	$iFactor = $iImgWidth / $iImgHeight
	While $iImgHeight > ($aTaskbarPos[1] - $iFrameHeight)
		$iImgHeight -= 1
		$iImgWidth -= $iFactor
	WEnd
	While $iImgWidth > (@DesktopWidth - $iFrameWidth)
		$iImgHeight -= 1
		$iImgWidth -= $iFactor
	WEnd
	$iImgWidth = Int($iImgWidth)
	ConsoleWrite($iImgWidth & ' x ' & $iImgHeight & '   ' & $iFrameWidth & ' x ' & $iFrameHeight & @CR)
	$hGui = GUICreate('Show Image', $iImgWidth, $iImgHeight, -1, -1, BitOR($WS_SYSMENU, $WS_CAPTION))
	GUISetState()
	$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui)
	_RedrawImage($hGraphic, $hBitmap, $iImgWidth, $iImgHeight)
	GUIRegisterMsg($WM_PAINT, '_WM_PAINT')
	While True
		$aMsg = GUIGetMsg(1)
		If $aMsg[1] = $hGui And $aMsg[0] = $GUI_EVENT_CLOSE Then ExitLoop
	WEnd
	GUIRegisterMsg($WM_PAINT, '')
	_GDIPlus_GraphicsDispose($hGraphic)
	_GDIPlus_BitmapDispose($hBitmap)
	_GDIPlus_Shutdown()
	GUIDelete($hGui)
	Opt('GUIOnEventMode', $iOldOpt)
EndFunc   ;==>_ShowImage

Func _WM_PAINT($hWnd, $Msg, $wParam, $lParam)
	If $hWnd = WinGetHandle('Show Image') Then _RedrawImage()
	Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_PAINT

Func _RedrawImage($par1 = 0, $par2 = 0, $par3 = 0, $par4 = 0)
	Local Static $hGraphic, $hBitmap, $iImgWidth, $iImgHeight
	If $par1 <> 0 Then
		$hGraphic = $par1
		$hBitmap = $par2
		$iImgWidth = $par3
		$iImgHeight = $par4
	EndIf
	_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iImgWidth, $iImgHeight)
EndFunc   ;==>_RedrawImage