Registriere die Nachricht doch einfach erst sobald du sie brauchst...
Oh man, das war der entscheidende Hinweis.
Danke ![]()
![]()
![]()
Registriere die Nachricht doch einfach erst sobald du sie brauchst...
Oh man, das war der entscheidende Hinweis.
Danke ![]()
![]()
![]()
Wie definiere ich, welches Fenster neu gemalt wird.
Bei der Lupe definiere ich dies ja nicht.
Oder wird immer das Fenster welches ontop ist neu gemalt?
Das Lupenfenster dann der Anfangs- bzw. Endpunkt.
Aber diesen Teil schaffe ich alleine
Da müsst ihr keine Mühe reinstecken.
Hm, so wie es aussieht, funktioniert deine Lupe in Zusammenspiel mit
[autoit]GUIRegisterMsg($WM_ERASEBKGND, "OnEraseBkGnd")
[/autoit]Wenn ich bei meiner Lupenversion folgendes deaktiviere geht es auch.
[autoit]WinSetOnTop($lupe_fuer_kreuz, "", 1)
[/autoit]
Kannst du mir erklären warum?
Vielleicht raff ichs dann mal ![]()
$s = StringFormat("%8s", $s)
[/autoit]Nö ist eigentlich nichts größeres.
Ich will Screenshots erstellen (daher die Lupe) und diese dann in der GUI darstellen (daher das Vollbildfoto in der GUI).
Ist halt nur noch nichts zusammenhängendes, da ich erst die einzelnen Teile getestet habe ob dies überhaupt geht. Ich will mir nicht unnötig Arbeite machen um dann zu merken, dass es nicht geht.
Und momentan scheint es nicht zu gehen, dass sich diese beiden Teile beißen ![]()
Und als ich den Fehler bemerkte habe ich von dem Vollbildfoto alle Teile entfernt um den Fehler besser lokalisieren zu können.
Teilweise verstehe ich das Skript.
Ich habe zum testen
alles rausgeschmissen was nichts mit dem Fehler zu tun hat.
Ich wollte es einfacher machen, damit man den Fehler besser finden kann.
Das Skript mit dem Bild in der GUI brauche weiterhin so wie du mir das Skript umgebaut hast.
Die Lupe kommt noch dazu.
So und wieder offen
Habe soeben bemerkt, dass die Zeile
GUIRegisterMsg($WM_ERASEBKGND, "OnEraseBkGnd")
[/autoit]
Probleme macht.
Wenn diese aktiviert ist, funktioniert die Lupe in dem folgenden Beispiel nicht.
Gibt es da eine Möglichkeit dies zu beheben ![]()
#Region ;************ Includes ************
#include <GDIPlus.au3>
#include <StaticConstants.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>
#EndRegion ;************ Includes ************
;allgemeine Deklarierung
Global $MyhWnd
Global $hBitmap, $lupe, $lupe_fuer_kreuz
Global $Start_Pos1, $Ausschnitt
Global $User1DLL = DllOpen("user32.dll")
Global $Mouse_Pos
Global Const $x_gui = 100 ;Größe des Vergrößerungsfensters
Global Const $y_gui = 100 ;Größe des Vergrößerungsfensters
Global $x_verschieben = 120 ;um wie viel das Vergrößerungsfenster in X verschoben werden soll, wenn der Cursor zu nah an den Bildschirmrand kommt
Global $y_verschieben = 120 ;um wie viel das Vergrößerungsfenster in Y verschoben werden soll, wenn der Cursor zu nah an den Bildschirmrand kommt
Global $iGUI_WidthInitial = 800, $iMinWidth = 200, $iMinHeight, $iMaxWidth = 1300, $iMaxHeight, $fRatio_Image, $fRatio_GUI
Global $hBmp, $hDC_Mem, $hWnd
$sPath_ImageInitial = "D:\alt\hide.jpg"
[/autoit] [autoit][/autoit] [autoit]Opt("GUIOnEventMode", 1) ; 0=ausgeschaltet, 1=OnEvent Modus aktiviert
[/autoit] [autoit][/autoit] [autoit]Global Const $BITMAP = "LONG bmType;LONG bmWidth;LONG bmHeight;LONG bmWidthBytes;WORD bmPlanes;WORD bmBitsPixel;PTR bmBits;"
Global Const $HWND_DESKTOP = _WinAPI_GetDesktopWindow()
$hDC = _WinAPI_GetDC($HWND_DESKTOP)
$hDC_Mem = _WinAPI_CreateCompatibleDC($hDC)
_WinAPI_ReleaseDC($HWND_DESKTOP, $hDC)
;~ GUIRegisterMsg($WM_ERASEBKGND, "OnEraseBkGnd") ;<<< ist dies deaktiviert, wird die Lupe angezeigt
[/autoit] [autoit][/autoit] [autoit]_auswahl()
[/autoit] [autoit][/autoit] [autoit];Schleife
While 1
Sleep(10)
WEnd
Func OnEraseBkGnd($hWnd, $message, $wParam, $lParam)
Local $rcClient
Local $hObjOld
Local $rcRight, $rcBottom
Local $bmWidth, $bmHeight
Local $bm = DllStructCreate($BITMAP)
If (Not $hBmp) Then Return 1
[/autoit] [autoit][/autoit] [autoit]; get the window's client area
$rcClient = _WinAPI_GetClientRect($hWnd)
$rcRight = DllStructGetData($rcClient, "Right")
$rcBottom = DllStructGetData($rcClient, "Bottom")
; get the bitmap dimensions
_WinAPI_GetObject($hBmp, DllStructGetSize($bm), DllStructGetPtr($bm))
; select the bitmap into the memory DC
$hObjOld = _WinAPI_SelectObject($hDC_Mem, $hBmp)
$bmWidth = DllStructGetData($bm, "bmWidth")
$bmHeight = DllStructGetData($bm, "bmHeight")
DllCall("gdi32.dll", "INT", "SetStretchBltMode", "HANDLE", $wParam, "INT", 4)
[/autoit] [autoit][/autoit] [autoit]StretchBlt($wParam, 0, 0, $rcRight, $rcBottom, $hDC_Mem, 0, 0, $bmWidth, $bmHeight, $SRCCOPY)
[/autoit] [autoit][/autoit] [autoit]_WinAPI_SelectObject($hDC_Mem, $hObjOld)
[/autoit] [autoit][/autoit] [autoit]Return 1
EndFunc ;==>OnEraseBkGnd
Func StretchBlt($hDCDest, $nXOriginDest, $nYOriginDest, $nWidthDest, $nHeightDest, $hDCSrc, $nXOriginSrc, $nYOriginSrc, $nWidthSrc, $nHeightSrc, $dwRop)
Local $aRes = DllCall("gdi32.dll", "BOOL", "StretchBlt", "HANDLE", $hDCDest, "INT", $nXOriginDest, "INT", $nYOriginDest, "INT", $nWidthDest, "INT", $nHeightDest, "HANDLE", $hDCSrc, "INT", $nXOriginSrc, "INT", $nYOriginSrc, "INT", $nWidthSrc, "INT", $nHeightSrc, "DWORD", $dwRop)
Return $aRes[0]
EndFunc ;==>StretchBlt
Func _beenden()
; free resources
_WinAPI_DeleteObject($hBmp)
_WinAPI_DeleteDC($hDC_Mem)
_GDIPlus_Shutdown()
GUIDelete($hWnd)
EndFunc ;==>_beenden
Func _auswahl()
Local $AuswahlGUI = GUICreate("Vergrößerung", @DesktopWidth, @DesktopHeight, -1, -1, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW)); erstellen eines GUI-Fensters
GUISetCursor(3, 1, $AuswahlGUI); Mouse-Cursor umschalten, Kreuz
WinSetTrans($AuswahlGUI, "", 20)
GUISetState(); öffnen des GUI-Fensters
$Mouse_Pos = MouseGetPos()
[/autoit] [autoit][/autoit] [autoit];kennzeichnet den Bereich, der später fotografiert wird
$Ausschnitt = GUICtrlCreateLabel('', 0, 0, 1, 1, $SS_SUNKEN)
GUICtrlSetBkColor($Ausschnitt, 0xFF0000) ;rötliche Farbe des Ausschnittes
;nur notwendig, da sonst das Positionskreuz leicht flackern würde
$lupe_fuer_kreuz = GUICreate("Kreuz", $x_gui, $y_gui, 500, 500, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW)) ; Vergrößerungsfenster
GUISetBkColor(0xABCDEF)
Local $strich1 = GUICtrlCreateLabel("", 0, 50, 102, 2) ;Kennzeichnung der Mitte des Vergrößerungsfensters
Local $strich2 = GUICtrlCreateLabel("", 50, 0, 2, 102) ;Kennzeichnung der Mitte des Vergrößerungsfensters
GUICtrlSetBkColor($strich1, 0x000000) ;Farbe der Mittelmarkierung ändern
GUICtrlSetBkColor($strich2, 0x000000) ;Farbe der Mittelmarkierung ändern
WinSetOnTop($lupe_fuer_kreuz, "", 1)
_WinAPI_SetLayeredWindowAttributes($lupe_fuer_kreuz, 0xABCDEF, 255)
GUISetState()
;Fenster für die Lupe
$lupe = GUICreate("Lupe", $x_gui, $y_gui, 5000, 5000, $WS_POPUPWINDOW, $WS_EX_TOOLWINDOW) ; Vergrößerungsfensters (außerhalb des Bildschirms erstellen)
GUISetState()
$Start_Pos1 = MouseGetPos()
[/autoit] [autoit][/autoit] [autoit]While Not _IsPressed("01", $User1DLL) ;Linke Maustaste gedrückt
$Mouse_Pos = MouseGetPos()
WinMove($lupe, "", $x_verschieben + $Mouse_Pos[0], $y_verschieben + $Mouse_Pos[1])
WinMove($lupe_fuer_kreuz, "", $x_verschieben + $Mouse_Pos[0], $y_verschieben + $Mouse_Pos[1])
$MyhWnd = WinGetHandle($lupe)
[/autoit] [autoit][/autoit] [autoit]Local $MyHDC = DllCall("user32.dll", "int", "GetDC", "hwnd", $MyhWnd)
If @error Then Return
Local $DeskHDC = DllCall("user32.dll", "int", "GetDC", "hwnd", 0)
If Not @error Then
Local $xy = MouseGetPos()
If Not @error Then
Local $l = $xy[0] - 10
Local $t = $xy[1] - 10
DllCall("gdi32.dll", "int", "StretchBlt", "int", $MyHDC[0], "int", 0, "int", 0, "int", 100, "int", 100, "int", $DeskHDC[0], "int", $l, "int", $t, "int", 20, "int", 20, "long", $SRCCOPY)
EndIf
DllCall("user32.dll", "int", "ReleaseDC", "int", $DeskHDC[0], "hwnd", 0)
EndIf
DllCall("user32.dll", "int", "ReleaseDC", "int", $MyHDC[0], "hwnd", $MyhWnd)
WEnd
EndFunc ;==>_auswahl
zu OrganizeIncludes (dann sollte auch das andere laufen)
Zitatcommand.36.*.au3="$(autoit3dir)\autoit3.exe" "$(SciteDefaultHome)\OrganizeIncludes\OI_1.0.0.50.au3" "$(FilePath)"
dies hast du in 2 Zeilen stehen statt in einer.
Außerdem meine ich, dass in der au3.properties dies hinzu muß (ziemlich oben, Pfad evtl. anpassen)
Zitatautoit3dir=C:\Program Files (x86)\AutoIt3
OK, passt, perfekt ![]()
Tausend Dank an alle die mitgeholfen haben ![]()
Damit gelöst ![]()
Oh man so einfach ![]()
Habe eben noch bemerkt, dass das Bild etwas verzerrt ist.
In der Höhe ist es gestaucht ![]()
Wow, sieht genial aus.
Genauso will ich es.
Allerdings möchte ich vor allem jpgs laden.
Ich habe mal mit GDIPlus eingebaut, dass die jpg in bmp umgewandelt werden.
Gibt es da noch eine bessere Methode oder muss jedesmal eine neue Datei im jpg-Format erzeugt werden?
#region ;************ Includes ************
#include <ScreenCapture.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#endregion ;************ Includes ************
Global $iGUI_WidthInitial = 800, $iMinWidth = 200, $iMinHeight, $iMaxWidth = 1300, $iMaxHeight, $fRatio_Image, $fRatio_GUI
Global $hBmp, $hDC_Mem
;~ Global $sPath_ImageInitial = FileOpenDialog("Bild auswählen", "", "Bilder (*.jpg;*.bmp)")
Opt("GUIOnEventMode", 1) ; 0=ausgeschaltet, 1=OnEvent Modus aktiviert
[/autoit] [autoit][/autoit] [autoit]Global Const $BITMAP = "LONG bmType;LONG bmWidth;LONG bmHeight;LONG bmWidthBytes;WORD bmPlanes;WORD bmBitsPixel;PTR bmBits;"
Global Const $HWND_DESKTOP = _WinAPI_GetDesktopWindow()
$hDC = _WinAPI_GetDC($HWND_DESKTOP)
$hDC_Mem = _WinAPI_CreateCompatibleDC($hDC)
_WinAPI_ReleaseDC($HWND_DESKTOP, $hDC)
GUIRegisterMsg($WM_ERASEBKGND, "OnEraseBkGnd")
GUIRegisterMsg($WM_SIZING, "WM_SIZING")
GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")
Global $hWnd = GUICreate("Test", 0, 0, -1, -1, $WS_OVERLAPPEDWINDOW)
[/autoit] [autoit][/autoit] [autoit]$sPath_ImageInitial = @TempDir & "\" & "test123.jpg"
_ScreenCapture_Capture($sPath_ImageInitial)
_LoadImage($sPath_ImageInitial)
[/autoit] [autoit][/autoit] [autoit]GUISetState()
[/autoit] [autoit][/autoit] [autoit]GUISetOnEvent($GUI_EVENT_CLOSE, "_beenden")
[/autoit] [autoit][/autoit] [autoit];Schleife
While Sleep(1000)
WEnd
Func _LoadImage($sPath_Image)
Local $szDrive, $szDir, $szFName, $szExt, $TestPath, $hImage2, $sCLSID, $sPath_Image_alt
Local $tRect = DllStructCreate($tagRECT)
Local $tBM = DllStructCreate($BITMAP)
If $hBmp Then _WinAPI_DeleteObject($hBmp)
[/autoit] [autoit][/autoit] [autoit];jpg-Datei in bmp-Datei umwandeln
$TestPath = _PathSplit($sPath_Image, $szDrive, $szDir, $szFName, $szExt)
If $TestPath[4] = ".jpg" Then
$sPath_Image_alt = $sPath_Image
$sPath_Image = @TempDir & "\" & $TestPath[3] & ".bmp"
_GDIPlus_Startup()
$hImage2 = _GDIPlus_ImageLoadFromFile($sPath_Image_alt)
$sCLSID = _GDIPlus_EncodersGetCLSID("BMP")
_GDIPlus_ImageSaveToFileEx($hImage2, $sPath_Image, $sCLSID)
_GDIPlus_Shutdown()
EndIf
$hBmp = _WinAPI_LoadImage(0, $sPath_Image, $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE)
_WinAPI_GetObject($hBmp, DllStructGetSize($tBM), DllStructGetPtr($tBM))
$fRatio_Image = DllStructGetData($tBM, "bmWidth") / DllStructGetData($tBM, "bmHeight")
DllStructSetData($tRect, "Left", 0)
DllStructSetData($tRect, "Top", 0)
DllStructSetData($tRect, "Right", $iGUI_WidthInitial)
DllStructSetData($tRect, "Bottom", $iGUI_WidthInitial / $fRatio_Image)
_WinAPI_AdjustWindowRectEx($tRect, BitXOR(_WinAPI_GetWindowLong($hWnd, $GWL_STYLE), $WS_OVERLAPPEDWINDOW), _WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE))
$iWidth = DllStructGetData($tRect, "Right") - DllStructGetData($tRect, "Left")
$iHeight = DllStructGetData($tRect, "Bottom") - DllStructGetData($tRect, "Top")
$iX = @DesktopWidth / 2 - $iWidth / 2
$iY = @DesktopHeight / 2 - $iHeight / 2
$fRatio_GUI = $iWidth / $iHeight
$iMinHeight = $iMinWidth / $fRatio_GUI ;min. Höhe anhand der min. Breite und des Seitenverhältnisse berechnen
$iMaxHeight = $iMaxWidth / $fRatio_GUI ;max. Höhe anhand der max. Breite und des Seitenverhältnisse berechnen
If $iMaxHeight > @DesktopHeight Then ;max. Höhe größer als der Bildschirm >>> neue max. Breite ermitteln
$iMaxHeight = @DesktopHeight
$iMaxWidth = $iMaxHeight * $fRatio_GUI
EndIf
_WinAPI_SetWindowPos($hWnd, 0, $iX, $iY, $iWidth, $iHeight, $SWP_NOZORDER)
EndFunc ;==>_LoadImage
Func OnEraseBkGnd($hWnd, $message, $wParam, $lParam)
Local $rcClient
Local $hObjOld
Local $rcRight, $rcBottom
Local $bmWidth, $bmHeight
Local $bm = DllStructCreate($BITMAP)
If (Not $hBmp) Then Return 1
[/autoit] [autoit][/autoit] [autoit]; get the window's client area
$rcClient = _WinAPI_GetClientRect($hWnd)
$rcRight = DllStructGetData($rcClient, "Right")
$rcBottom = DllStructGetData($rcClient, "Bottom")
; get the bitmap dimensions
_WinAPI_GetObject($hBmp, DllStructGetSize($bm), DllStructGetPtr($bm))
; select the bitmap into the memory DC
$hObjOld = _WinAPI_SelectObject($hDC_Mem, $hBmp)
$bmWidth = DllStructGetData($bm, "bmWidth")
$bmHeight = DllStructGetData($bm, "bmHeight")
DllCall("gdi32.dll", "INT", "SetStretchBltMode", "HANDLE", $wParam, "INT", 4)
[/autoit] [autoit][/autoit] [autoit]StretchBlt($wParam, 0, 0, $rcRight, $rcBottom, $hDC_Mem, 0, 0, $bmWidth, $bmHeight, $SRCCOPY)
[/autoit] [autoit][/autoit] [autoit]_WinAPI_SelectObject($hDC_Mem, $hObjOld)
[/autoit] [autoit][/autoit] [autoit]Return 1
EndFunc ;==>OnEraseBkGnd
Func StretchBlt($hDCDest, $nXOriginDest, $nYOriginDest, $nWidthDest, $nHeightDest, $hDCSrc, $nXOriginSrc, $nYOriginSrc, $nWidthSrc, $nHeightSrc, $dwRop)
Local $aRes = DllCall("gdi32.dll", "BOOL", "StretchBlt", "HANDLE", $hDCDest, "INT", $nXOriginDest, "INT", $nYOriginDest, "INT", $nWidthDest, "INT", $nHeightDest, "HANDLE", $hDCSrc, "INT", $nXOriginSrc, "INT", $nYOriginSrc, "INT", $nWidthSrc, "INT", $nHeightSrc, "DWORD", $dwRop)
Return $aRes[0]
EndFunc ;==>StretchBlt
Func WM_GETMINMAXINFO($hWnd, $Msg, $wParam, $lParam)
Local $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
DllStructSetData($minmaxinfo, 7, $iMinWidth) ; min X
DllStructSetData($minmaxinfo, 8, $iMinHeight) ; min Y
DllStructSetData($minmaxinfo, 9, $iMaxWidth) ; max X
DllStructSetData($minmaxinfo, 10, $iMaxHeight) ; max Y
Return "GUI_RUNDEFMSG"
EndFunc ;==>WM_GETMINMAXINFO
Func WM_SIZING($hWnd, $iMsg, $wParam, $lParam)
Local $tRect_Cur = DllStructCreate("int[4]", $lParam)
Local $left = DllStructGetData($tRect_Cur, 1, 1)
Local $top = DllStructGetData($tRect_Cur, 1, 2)
Local $right = DllStructGetData($tRect_Cur, 1, 3)
Local $bottom = DllStructGetData($tRect_Cur, 1, 4)
Switch $wParam ;drag side or corner
Case 1, 2, 4, 7
Local $iNewY = Int(($right - $left) / $fRatio_GUI)
DllStructSetData($tRect_Cur, 1, $top + $iNewY, 4)
Case Else
Local $iNewX = Int(($bottom - $top) * $fRatio_GUI)
DllStructSetData($tRect_Cur, 1, $left + $iNewX, 3)
EndSwitch
Return "GUI_RUNDEFMSG"
EndFunc ;==>WM_SIZING
Func _beenden()
; free resources
_WinAPI_DeleteObject($hBmp)
_WinAPI_DeleteDC($hDC_Mem)
Exit
EndFunc ;==>_beenden
; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_AdjustWindowRectEx
; Description....: Calculates the required size of the window rectangle, based on the desired size of the client rectangle.
; Syntax.........: _WinAPI_AdjustWindowRectEx ( ByRef $tRECT, $iStyle [, $iExStyle [, $fMenu] )
; Parameters.....: $tRECT - $tagRECT structure that contains the coordinates of the desired client area.
; $iStyle - The window style of the window whose required size is to be calculated. Note that you cannot
; specify the $WS_OVERLAPPED style.
; $iExStyle - The extended window style of the window whose required size is to be calculated.
; $fMenu - Specifies whether the window has a menu, valid values:
; |TRUE - The window has a menu, valid values:
; |FALSE - The window does not has a menu. (Default)
; Return values..: Success - 1.
; Failure - 0 and sets the @error flag to non-zero.
; Author.........: Yashied
; Modified.......:
; Remarks........: None
; Related........:
; Link...........: @@MsdnLink@@ AdjustWindowRectEx
; Example........: Yes
; ===============================================================================================================================
Func _WinAPI_AdjustWindowRectEx(ByRef $tRect, $iStyle, $iExStyle = 0, $fMenu = 0)
[/autoit] [autoit][/autoit] [autoit]Local $Ret = DllCall('user32.dll', 'int', 'AdjustWindowRectEx', 'ptr', DllStructGetPtr($tRect), 'dword', $iStyle, 'int', $fMenu, 'dword', $iExStyle)
[/autoit] [autoit][/autoit] [autoit]If (@error) Or (Not $Ret[0]) Then
Return SetError(1, 0, 0)
EndIf
Return 1
EndFunc ;==>_WinAPI_AdjustWindowRectEx
Ich will ein x-beliebiges Bild in der GUI anzeigen lassen.
In den bisherigen Beispielen wurde (wenn ich es richtig verstehe) immer das Desktopbild verwendet.
Ab dem Befehl "$hdc = _WinAPI_GetDC($HWND_DESKTOP)" hakts dann.
Hoffe du weißt was ich meine.
#Region ;************ Includes ************
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ScreenCapture.au3>
#EndRegion ;************ Includes ************
Global $iMinWidth, $iMaxWidth, $hwnd, $fRatio, $iMinHeight, $iMaxHeight, $hbmp, $hdcMem, $BITMAP
[/autoit] [autoit][/autoit] [autoit]Opt("GUIOnEventMode", 1) ; 0=ausgeschaltet, 1=OnEvent Modus aktiviert
[/autoit] [autoit][/autoit] [autoit]Global $bild_name = "C:\Windows\Web\Wallpaper\Windows\img0.jpg"
[/autoit] [autoit][/autoit] [autoit]_bild_in_gui("Bild123", $bild_name, 500, 200, 700)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]Func _bild_in_gui($title_func, $bild_func, $iGUI_WidthInitial, $iMinWidth_func, $iMaxWidth_func)
Local $array_bildergroesse[3]
$iMinWidth = $iMinWidth_func
$iMaxWidth = $iMaxWidth_func
$BITMAP = "LONG bmType;" & "LONG bmWidth;" & "LONG bmHeight;" & "LONG bmWidthBytes;" & "WORD bmPlanes;" & "WORD bmBitsPixel;" & "PTR bmBits;"
[/autoit] [autoit][/autoit] [autoit];~ Global Const $HWND_DESKTOP = _WinAPI_GetDesktopWindow()
;~ $fRatio = _WinAPI_GetClientWidth($HWND_DESKTOP) / _WinAPI_GetClientHeight($HWND_DESKTOP)
$array_bildergroesse = _bildgroesse2($bild_func)
$fRatio = $array_bildergroesse[1] / $array_bildergroesse[2]
GUIRegisterMsg($WM_CREATE, "OnCreate")
GUIRegisterMsg($WM_ERASEBKGND, "OnEraseBkGnd")
GUIRegisterMsg($WM_SIZING, "WM_SIZING")
GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")
$hwnd = GUICreate($title_func, $iGUI_WidthInitial, Floor($iGUI_WidthInitial / $fRatio), -1, -1, $WS_OVERLAPPEDWINDOW)
GUISetState(@SW_SHOW, $hwnd)
GUISetOnEvent($GUI_EVENT_CLOSE, "_bild_in_gui_beenden")
[/autoit] [autoit][/autoit] [autoit]$fRatio = _WinAPI_GetWindowWidth($hwnd) / _WinAPI_GetWindowHeight($hwnd)
[/autoit] [autoit][/autoit] [autoit];fehlende min. und max. Wert ermitteln
$iMinHeight = $iMinWidth / $fRatio ;min. Höhe anhand der min. Breite und des Seitenverhältnisse berechnen
$iMaxHeight = $iMaxWidth / $fRatio ;max. Höhe anhand der max. Breite und des Seitenverhältnisse berechnen
If $iMaxHeight > @DesktopHeight Then ;max. Höhe größer als der Bildschirm >>> neue max. Breite ermitteln
$iMaxHeight = @DesktopHeight
$iMaxWidth = $iMaxHeight * $fRatio
EndIf
;Schleife
While 1
Sleep(10)
WEnd
EndFunc ;==>_bild_in_gui
Func OnCreate($hwnd, $message, $wParam, $lParam)
Local $hdc
;~ $hbmp = _ScreenCapture_Capture()
;~ If (Not $hbmp) Then ConsoleWrite(StringFormat("_WinAPI_LoadImage fehlgeschlagen!\n")); error handling here
$hdc = _WinAPI_GetDC($HWND_DESKTOP)
$hdcMem = _WinAPI_CreateCompatibleDC($hdc)
_WinAPI_ReleaseDC($HWND_DESKTOP, $hdc)
[/autoit] [autoit][/autoit] [autoit]If (Not $hdcMem) Then ConsoleWrite(StringFormat("_WinAPI_CreateCompatibleDC fehlgeschlagen!\n")) ; error handling here
[/autoit] [autoit][/autoit] [autoit]Return $GUI_RUNDEFMSG
EndFunc ;==>OnCreate
Func OnEraseBkGnd($hwnd, $message, $wParam, $lParam)
Local $rcClient
Local $hObjOld
Local $rcRight, $rcBottom
Local $bmWidth, $bmHeight
Local $bm = DllStructCreate($BITMAP)
If (Not $hbmp) Then Return 1
[/autoit] [autoit][/autoit] [autoit]; get the window's client area
$rcClient = _WinAPI_GetClientRect($hwnd)
$rcRight = DllStructGetData($rcClient, "Right")
$rcBottom = DllStructGetData($rcClient, "Bottom")
; get the bitmap dimensions
_WinAPI_GetObject($hbmp, DllStructGetSize($bm), DllStructGetPtr($bm))
; select the bitmap into the memory DC
$hObjOld = _WinAPI_SelectObject($hdcMem, $hbmp)
$bmWidth = DllStructGetData($bm, "bmWidth")
$bmHeight = DllStructGetData($bm, "bmHeight")
DllCall("gdi32.dll", "INT", "SetStretchBltMode", "HANDLE", $wParam, "INT", 4)
[/autoit] [autoit][/autoit] [autoit]StretchBlt($wParam, 0, 0, $rcRight, $rcBottom, $hdcMem, 0, 0, $bmWidth, $bmHeight, $SRCCOPY)
[/autoit] [autoit][/autoit] [autoit]_WinAPI_SelectObject($hdcMem, $hObjOld)
[/autoit] [autoit][/autoit] [autoit]Return 1
EndFunc ;==>OnEraseBkGnd
Func StretchBlt($hdcDest, $nXOriginDest, $nYOriginDest, $nWidthDest, $nHeightDest, $hdcSrc, $nXOriginSrc, $nYOriginSrc, $nWidthSrc, $nHeightSrc, $dwRop)
Local $aRes = DllCall("gdi32.dll", "BOOL", "StretchBlt", "HANDLE", $hdcDest, "INT", $nXOriginDest, "INT", $nYOriginDest, "INT", $nWidthDest, "INT", $nHeightDest, "HANDLE", $hdcSrc, "INT", $nXOriginSrc, "INT", $nYOriginSrc, "INT", $nWidthSrc, "INT", $nHeightSrc, "DWORD", $dwRop)
Return $aRes[0]
EndFunc ;==>StretchBlt
Func WM_GETMINMAXINFO($hwnd, $Msg, $wParam, $lParam)
Local $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
DllStructSetData($minmaxinfo, 7, $iMinWidth) ; min X
DllStructSetData($minmaxinfo, 8, $iMinHeight) ; min Y
DllStructSetData($minmaxinfo, 9, $iMaxWidth) ; max X
DllStructSetData($minmaxinfo, 10, $iMaxHeight) ; max Y
Return "GUI_RUNDEFMSG"
EndFunc ;==>WM_GETMINMAXINFO
Func WM_SIZING($hwnd, $iMsg, $wParam, $lParam)
Local $tRect_Cur = DllStructCreate("int[4]", $lParam)
Local $left = DllStructGetData($tRect_Cur, 1, 1)
Local $top = DllStructGetData($tRect_Cur, 1, 2)
Local $right = DllStructGetData($tRect_Cur, 1, 3)
Local $bottom = DllStructGetData($tRect_Cur, 1, 4)
Switch $wParam ;drag side or corner
Case 1, 2, 4, 7
Local $iNewY = Int(($right - $left) / $fRatio)
DllStructSetData($tRect_Cur, 1, $top + $iNewY, 4)
Case Else
Local $iNewX = Int(($bottom - $top) * $fRatio)
DllStructSetData($tRect_Cur, 1, $left + $iNewX, 3)
EndSwitch
Return "GUI_RUNDEFMSG"
EndFunc ;==>WM_SIZING
Func _bild_in_gui_beenden()
; free resources
_WinAPI_DeleteObject($hbmp)
_WinAPI_DeleteDC($hdcMem)
GUIDelete($hwnd)
EndFunc ;==>_bild_in_gui_beenden
Func _bildgroesse2($bildgroesse_pfad_dateiname)
Local $array_bilder_1[3], $hImage3
; Initialisiert (startet) Microsoft Windows GDI+
_GDIPlus_Startup()
; Lädt ein Bild
$hImage3 = _GDIPlus_ImageLoadFromFile($bildgroesse_pfad_dateiname)
; Erzeugt eine Kopie einer 24 bit Bitmap
$array_bilder_1[1] = _GDIPlus_ImageGetWidth($hImage3)
$array_bilder_1[2] = _GDIPlus_ImageGetHeight($hImage3)
; Ressourcen freigeben
_GDIPlus_ImageDispose($hImage3)
; Gibt die durch Microsoft Windows GDI+ verwendeten Ressourcen wieder frei
_GDIPlus_Shutdown()
Return $array_bilder_1
EndFunc ;==>_bildgroesse
Bitte nochmals um Rat zur Vervollständigkeit des Skript
[ offen ] Bildgröße laufend an GUI anpassen
Kurz aber leider von der Darstellungsqualiltät nicht so gut wie die anderen Beispiele ![]()
Von dem her ist Post 14 immernoch gültig
[ offen ] Bildgröße laufend an GUI anpassen
Muß den Thread doch nochmal aufmachen.
Ich will als Quelle ein x-beliebiges jpg-Bild nehmen und das ganze in eine Funktion packen.
Leider komme ich mit den ganzen _Winapi-Befehlen nicht klar.
Ich hab mal das geändert was ist weiß.
Probierts aus dann seht ihr wo die Fehlermeldungen kommen.
Hoffe ihr könnt mir nochmal weiterhelfen.
#Region ;************ Includes ************
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ScreenCapture.au3>
#EndRegion ;************ Includes ************
Global $iMinWidth, $iMaxWidth, $hwnd, $fRatio, $iMinHeight, $iMaxHeight, $hbmp, $hdcMem, $BITMAP
[/autoit] [autoit][/autoit] [autoit]Opt("GUIOnEventMode", 1) ; 0=ausgeschaltet, 1=OnEvent Modus aktiviert
[/autoit] [autoit][/autoit] [autoit]Global $bild_name = "C:\Windows\Web\Wallpaper\Windows\img0.jpg"
[/autoit] [autoit][/autoit] [autoit]_bild_in_gui("Bild123", $bild_name, 500, 200, 700)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]Func _bild_in_gui($title_func, $bild_func, $iGUI_WidthInitial, $iMinWidth_func, $iMaxWidth_func)
Local $array_bildergroesse[3]
$iMinWidth = $iMinWidth_func
$iMaxWidth = $iMaxWidth_func
$BITMAP = "LONG bmType;" & "LONG bmWidth;" & "LONG bmHeight;" & "LONG bmWidthBytes;" & "WORD bmPlanes;" & "WORD bmBitsPixel;" & "PTR bmBits;"
[/autoit] [autoit][/autoit] [autoit];~ Global Const $HWND_DESKTOP = _WinAPI_GetDesktopWindow()
;~ $fRatio = _WinAPI_GetClientWidth($HWND_DESKTOP) / _WinAPI_GetClientHeight($HWND_DESKTOP)
$array_bildergroesse = _bildgroesse2($bild_func)
$fRatio = $array_bildergroesse[1] / $array_bildergroesse[2]
GUIRegisterMsg($WM_CREATE, "OnCreate")
GUIRegisterMsg($WM_ERASEBKGND, "OnEraseBkGnd")
GUIRegisterMsg($WM_SIZING, "WM_SIZING")
GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")
$hwnd = GUICreate($title_func, $iGUI_WidthInitial, Floor($iGUI_WidthInitial / $fRatio), -1, -1, $WS_OVERLAPPEDWINDOW)
GUISetState(@SW_SHOW, $hwnd)
GUISetOnEvent($GUI_EVENT_CLOSE, "_bild_in_gui_beenden")
[/autoit] [autoit][/autoit] [autoit]$fRatio = _WinAPI_GetWindowWidth($hwnd) / _WinAPI_GetWindowHeight($hwnd)
[/autoit] [autoit][/autoit] [autoit];fehlende min. und max. Wert ermitteln
$iMinHeight = $iMinWidth / $fRatio ;min. Höhe anhand der min. Breite und des Seitenverhältnisse berechnen
$iMaxHeight = $iMaxWidth / $fRatio ;max. Höhe anhand der max. Breite und des Seitenverhältnisse berechnen
If $iMaxHeight > @DesktopHeight Then ;max. Höhe größer als der Bildschirm >>> neue max. Breite ermitteln
$iMaxHeight = @DesktopHeight
$iMaxWidth = $iMaxHeight * $fRatio
EndIf
;Schleife
While 1
Sleep(10)
WEnd
EndFunc ;==>_bild_in_gui
Func OnCreate($hwnd, $message, $wParam, $lParam)
Local $hdc
;~ $hbmp = _ScreenCapture_Capture()
;~ If (Not $hbmp) Then ConsoleWrite(StringFormat("_WinAPI_LoadImage fehlgeschlagen!\n")); error handling here
$hdc = _WinAPI_GetDC($HWND_DESKTOP)
$hdcMem = _WinAPI_CreateCompatibleDC($hdc)
_WinAPI_ReleaseDC($HWND_DESKTOP, $hdc)
[/autoit] [autoit][/autoit] [autoit]If (Not $hdcMem) Then ConsoleWrite(StringFormat("_WinAPI_CreateCompatibleDC fehlgeschlagen!\n")) ; error handling here
[/autoit] [autoit][/autoit] [autoit]Return $GUI_RUNDEFMSG
EndFunc ;==>OnCreate
Func OnEraseBkGnd($hwnd, $message, $wParam, $lParam)
Local $rcClient
Local $hObjOld
Local $rcRight, $rcBottom
Local $bmWidth, $bmHeight
Local $bm = DllStructCreate($BITMAP)
If (Not $hbmp) Then Return 1
[/autoit] [autoit][/autoit] [autoit]; get the window's client area
$rcClient = _WinAPI_GetClientRect($hwnd)
$rcRight = DllStructGetData($rcClient, "Right")
$rcBottom = DllStructGetData($rcClient, "Bottom")
; get the bitmap dimensions
_WinAPI_GetObject($hbmp, DllStructGetSize($bm), DllStructGetPtr($bm))
; select the bitmap into the memory DC
$hObjOld = _WinAPI_SelectObject($hdcMem, $hbmp)
$bmWidth = DllStructGetData($bm, "bmWidth")
$bmHeight = DllStructGetData($bm, "bmHeight")
DllCall("gdi32.dll", "INT", "SetStretchBltMode", "HANDLE", $wParam, "INT", 4)
[/autoit] [autoit][/autoit] [autoit]StretchBlt($wParam, 0, 0, $rcRight, $rcBottom, $hdcMem, 0, 0, $bmWidth, $bmHeight, $SRCCOPY)
[/autoit] [autoit][/autoit] [autoit]_WinAPI_SelectObject($hdcMem, $hObjOld)
[/autoit] [autoit][/autoit] [autoit]Return 1
EndFunc ;==>OnEraseBkGnd
Func StretchBlt($hdcDest, $nXOriginDest, $nYOriginDest, $nWidthDest, $nHeightDest, $hdcSrc, $nXOriginSrc, $nYOriginSrc, $nWidthSrc, $nHeightSrc, $dwRop)
Local $aRes = DllCall("gdi32.dll", "BOOL", "StretchBlt", "HANDLE", $hdcDest, "INT", $nXOriginDest, "INT", $nYOriginDest, "INT", $nWidthDest, "INT", $nHeightDest, "HANDLE", $hdcSrc, "INT", $nXOriginSrc, "INT", $nYOriginSrc, "INT", $nWidthSrc, "INT", $nHeightSrc, "DWORD", $dwRop)
Return $aRes[0]
EndFunc ;==>StretchBlt
Func WM_GETMINMAXINFO($hwnd, $Msg, $wParam, $lParam)
Local $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
DllStructSetData($minmaxinfo, 7, $iMinWidth) ; min X
DllStructSetData($minmaxinfo, 8, $iMinHeight) ; min Y
DllStructSetData($minmaxinfo, 9, $iMaxWidth) ; max X
DllStructSetData($minmaxinfo, 10, $iMaxHeight) ; max Y
Return "GUI_RUNDEFMSG"
EndFunc ;==>WM_GETMINMAXINFO
Func WM_SIZING($hwnd, $iMsg, $wParam, $lParam)
Local $tRect_Cur = DllStructCreate("int[4]", $lParam)
Local $left = DllStructGetData($tRect_Cur, 1, 1)
Local $top = DllStructGetData($tRect_Cur, 1, 2)
Local $right = DllStructGetData($tRect_Cur, 1, 3)
Local $bottom = DllStructGetData($tRect_Cur, 1, 4)
Switch $wParam ;drag side or corner
Case 1, 2, 4, 7
Local $iNewY = Int(($right - $left) / $fRatio)
DllStructSetData($tRect_Cur, 1, $top + $iNewY, 4)
Case Else
Local $iNewX = Int(($bottom - $top) * $fRatio)
DllStructSetData($tRect_Cur, 1, $left + $iNewX, 3)
EndSwitch
Return "GUI_RUNDEFMSG"
EndFunc ;==>WM_SIZING
Func _bild_in_gui_beenden()
; free resources
_WinAPI_DeleteObject($hbmp)
_WinAPI_DeleteDC($hdcMem)
GUIDelete($hwnd)
EndFunc ;==>_bild_in_gui_beenden
Func _bildgroesse2($bildgroesse_pfad_dateiname)
Local $array_bilder_1[3], $hImage3
; Initialisiert (startet) Microsoft Windows GDI+
_GDIPlus_Startup()
; Lädt ein Bild
$hImage3 = _GDIPlus_ImageLoadFromFile($bildgroesse_pfad_dateiname)
; Erzeugt eine Kopie einer 24 bit Bitmap
$array_bilder_1[1] = _GDIPlus_ImageGetWidth($hImage3)
$array_bilder_1[2] = _GDIPlus_ImageGetHeight($hImage3)
; Ressourcen freigeben
_GDIPlus_ImageDispose($hImage3)
; Gibt die durch Microsoft Windows GDI+ verwendeten Ressourcen wieder frei
_GDIPlus_Shutdown()
Return $array_bilder_1
EndFunc ;==>_bildgroesse
So, habe es nun noch so geändert, dass das Seitenverhältnis bei der min. und max. Größe auch immer beibehalten wird.
#Region ;************ Includes ************
#Include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ScreenCapture.au3>
#EndRegion ;************ Includes ************
Global $iGUI_WidthInitial = 800, $fRatio, $iMinWidth = 200, $iMinHeight, $iMaxWidth = 1300, $iMaxHeight
Global $hbmp, $hdcMem
Opt("GUIOnEventMode", 1) ; 0=ausgeschaltet, 1=OnEvent Modus aktiviert
[/autoit] [autoit][/autoit] [autoit]Global Const $BITMAP = "LONG bmType;" & "LONG bmWidth;" & "LONG bmHeight;" & "LONG bmWidthBytes;" & "WORD bmPlanes;" & "WORD bmBitsPixel;" & "PTR bmBits;"
Global Const $HWND_DESKTOP = _WinAPI_GetDesktopWindow()
$fRatio = _WinAPI_GetClientWidth($HWND_DESKTOP) / _WinAPI_GetClientHeight($HWND_DESKTOP)
[/autoit] [autoit][/autoit] [autoit]GUIRegisterMsg($WM_CREATE, "OnCreate")
GUIRegisterMsg($WM_ERASEBKGND, "OnEraseBkGnd")
GUIRegisterMsg($WM_SIZING, "WM_SIZING")
GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")
Global $hwnd = GUICreate("Test", $iGUI_WidthInitial, Floor($iGUI_WidthInitial / $fRatio), -1, -1, $WS_OVERLAPPEDWINDOW)
GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "_beenden")
[/autoit] [autoit][/autoit] [autoit]$fRatio = _WinAPI_GetWindowWidth($hwnd) / _WinAPI_GetWindowHeight($hwnd)
[/autoit] [autoit][/autoit] [autoit];fehlende min. und max. Wert ermitteln
$iMinHeight = $iMinWidth / $fRatio ;min. Höhe anhand der min. Breite und des Seitenverhältnisse berechnen
$iMaxHeight = $iMaxWidth / $fRatio ;max. Höhe anhand der max. Breite und des Seitenverhältnisse berechnen
If $iMaxHeight > @DesktopHeight Then ;max. Höhe größer als der Bildschirm >>> neue max. Breite ermitteln
$iMaxHeight = @DesktopHeight
$iMaxWidth = $iMaxHeight * $fRatio
EndIf
;Schleife
While 1
Sleep(10)
WEnd
Func OnCreate($hwnd, $message, $wParam, $lParam)
Local $hdc
$hbmp = _ScreenCapture_Capture()
[/autoit] [autoit][/autoit] [autoit]If (Not $hbmp) Then ConsoleWrite(StringFormat("_WinAPI_LoadImage fehlgeschlagen!\n")); error handling here
[/autoit] [autoit][/autoit] [autoit]$hdc = _WinAPI_GetDC($HWND_DESKTOP)
$hdcMem = _WinAPI_CreateCompatibleDC($hdc)
_WinAPI_ReleaseDC($HWND_DESKTOP, $hdc)
[/autoit] [autoit][/autoit] [autoit]If (Not $hdcMem) Then ConsoleWrite(StringFormat("_WinAPI_CreateCompatibleDC fehlgeschlagen!\n")) ; error handling here
[/autoit] [autoit][/autoit] [autoit]Return $GUI_RUNDEFMSG
EndFunc ;==>OnCreate
Func OnEraseBkGnd($hwnd, $message, $wParam, $lParam)
Local $rcClient
Local $hObjOld
Local $rcRight, $rcBottom
Local $bmWidth, $bmHeight
Local $bm = DllStructCreate($BITMAP)
If (Not $hbmp) Then Return 1
[/autoit] [autoit][/autoit] [autoit]; get the window's client area
$rcClient = _WinAPI_GetClientRect($hwnd)
$rcRight = DllStructGetData($rcClient, "Right")
$rcBottom = DllStructGetData($rcClient, "Bottom")
; get the bitmap dimensions
_WinAPI_GetObject($hbmp, DllStructGetSize($bm), DllStructGetPtr($bm))
; select the bitmap into the memory DC
$hObjOld = _WinAPI_SelectObject($hdcMem, $hbmp)
$bmWidth = DllStructGetData($bm, "bmWidth")
$bmHeight = DllStructGetData($bm, "bmHeight")
DllCall("gdi32.dll", "INT", "SetStretchBltMode", "HANDLE", $wParam, "INT", 4)
[/autoit] [autoit][/autoit] [autoit]StretchBlt($wParam, 0, 0, $rcRight, $rcBottom, $hdcMem, 0, 0, $bmWidth, $bmHeight, $SRCCOPY)
[/autoit] [autoit][/autoit] [autoit]_WinAPI_SelectObject($hdcMem, $hObjOld)
[/autoit] [autoit][/autoit] [autoit]Return 1
EndFunc ;==>OnEraseBkGnd
Func StretchBlt($hdcDest, $nXOriginDest, $nYOriginDest, $nWidthDest, $nHeightDest, $hdcSrc, $nXOriginSrc, $nYOriginSrc, $nWidthSrc, $nHeightSrc, $dwRop)
Local $aRes = DllCall("gdi32.dll", "BOOL", "StretchBlt", "HANDLE", $hdcDest, "INT", $nXOriginDest, "INT", $nYOriginDest, "INT", $nWidthDest, "INT", $nHeightDest, "HANDLE", $hdcSrc, "INT", $nXOriginSrc, "INT", $nYOriginSrc, "INT", $nWidthSrc, "INT", $nHeightSrc, "DWORD", $dwRop)
Return $aRes[0]
EndFunc ;==>StretchBlt
Func WM_GETMINMAXINFO($hwnd, $Msg, $wParam, $lParam)
Local $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
DllStructSetData($minmaxinfo, 7, $iMinWidth) ; min X
DllStructSetData($minmaxinfo, 8, $iMinHeight) ; min Y
DllStructSetData($minmaxinfo, 9, $iMaxWidth) ; max X
DllStructSetData($minmaxinfo, 10, $iMaxHeight) ; max Y
Return "GUI_RUNDEFMSG"
EndFunc ;==>WM_GETMINMAXINFO
Func WM_SIZING($hwnd, $iMsg, $wParam, $lParam)
Local $tRect_Cur = DllStructCreate("int[4]", $lParam)
Local $left = DllStructGetData($tRect_Cur, 1, 1)
Local $top = DllStructGetData($tRect_Cur, 1, 2)
Local $right = DllStructGetData($tRect_Cur, 1, 3)
Local $bottom = DllStructGetData($tRect_Cur, 1, 4)
Switch $wParam ;drag side or corner
Case 1, 2, 4, 7
Local $iNewY = Int(($right - $left) / $fRatio)
DllStructSetData($tRect_Cur, 1, $top + $iNewY, 4)
Case Else
Local $iNewX = Int(($bottom - $top) * $fRatio)
DllStructSetData($tRect_Cur, 1, $left + $iNewX, 3)
EndSwitch
Return "GUI_RUNDEFMSG"
EndFunc ;==>WM_SIZING
Func _beenden()
; free resources
_WinAPI_DeleteObject($hbmp)
_WinAPI_DeleteDC($hdcMem)
Exit
EndFunc ;==>_beenden
Hm, stimmt das Verhältnis ändert sich ständig.
Hat dies was mit dem Rahmen der GUI zu tun.
Wird der nicht berücksichtigt?
Wow, das sieht nochmal besser aus.
Danke schonmal ihr beiden ![]()
#region ;************ Includes ************
#include <ScreenCapture.au3>;~~~
#include <WinAPI.au3>;~~~
#include <WindowsConstants.au3>;~~~
#include <GUIConstantsEx.au3>;~~~
#include <Constants.au3>
#endregion ;************ Includes ************
Global $array_bilder_1[3], $breite = 800
Global $hbmp, $hdcMem
; --- $BITMAP
Global Const $BITMAP = _
"LONG bmType;" & _
"LONG bmWidth;" & _
"LONG bmHeight;" & _
"LONG bmWidthBytes;" & _
"WORD bmPlanes;" & _
"WORD bmBitsPixel;" & _
"PTR bmBits;"
Global Const $HWND_DESKTOP = 0
Global $sImagePath = @TempDir & "\" & "bild.bmp"
_ScreenCapture_Capture($sImagePath)
_GDIPlus_Startup()
Global $hImage = _GDIPlus_ImageLoadFromFile($sImagePath)
$array_bilder_1[1] = _GDIPlus_ImageGetWidth($hImage)
$array_bilder_1[2] = _GDIPlus_ImageGetHeight($hImage)
Global $seitenverhaeltnis = $array_bilder_1[1] / $array_bilder_1[2]
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
_AuMain()
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]Func _AuMain()
Local $hwnd
GUIRegisterMsg($WM_CREATE, "OnCreate")
GUIRegisterMsg($WM_ERASEBKGND, "OnEraseBkGnd")
GUIRegisterMsg($WM_SIZING, "WM_SIZING")
GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")
$hwnd = GUICreate("Test", $breite, $breite / $seitenverhaeltnis, -1, -1, $WS_OVERLAPPEDWINDOW)
[/autoit] [autoit][/autoit] [autoit]Global $aWS = WinGetClientSize($hwnd)
Global Const $ratio = $aWS[1] / $aWS[0]
Global $breite_min = 0
Global $breite_max = 9300
Global $hoehe_min = 0
Global $hoehe_max = 9300
GUISetState(@SW_SHOW, $hwnd)
[/autoit] [autoit][/autoit] [autoit]While (True)
Switch GUIGetMsg(False)
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
; free resources
_WinAPI_DeleteObject($hbmp)
_WinAPI_DeleteDC($hdcMem)
Return 0
EndFunc ;==>_AuMain
Func OnCreate($hwnd, $message, $wParam, $lParam)
Local $hdc
$hbmp = _WinAPI_LoadImage(0, $sImagePath, $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE)
[/autoit] [autoit][/autoit] [autoit]If (Not $hbmp) Then
; error handling here
ConsoleWrite(StringFormat("_WinAPI_LoadImage fehlgeschlagen!\n"))
EndIf
$hdc = _WinAPI_GetDC($HWND_DESKTOP)
$hdcMem = _WinAPI_CreateCompatibleDC($hdc)
_WinAPI_ReleaseDC($HWND_DESKTOP, $hdc)
[/autoit] [autoit][/autoit] [autoit]If (Not $hdcMem) Then
; error handling here
ConsoleWrite(StringFormat("_WinAPI_CreateCompatibleDC fehlgeschlagen!\n"))
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>OnCreate
Func OnEraseBkGnd($hwnd, $message, $wParam, $lParam)
Local $rcClient
Local $hObjOld
Local $rcRight, $rcBottom
Local $bmWidth, $bmHeight
Local $bm = DllStructCreate($BITMAP)
If (Not $hbmp) Then
Return 1
EndIf
; get the window's client area
$rcClient = _WinAPI_GetClientRect($hwnd)
$rcRight = DllStructGetData($rcClient, "Right")
$rcBottom = DllStructGetData($rcClient, "Bottom")
; get the bitmap dimensions
_WinAPI_GetObject($hbmp, DllStructGetSize($bm), DllStructGetPtr($bm))
; select the bitmap into the memory DC
$hObjOld = _WinAPI_SelectObject($hdcMem, $hbmp)
$bmWidth = DllStructGetData($bm, "bmWidth")
$bmHeight = DllStructGetData($bm, "bmHeight")
DllCall("gdi32.dll", "INT", "SetStretchBltMode", "HANDLE", $wParam, "INT", 4)
[/autoit] [autoit][/autoit] [autoit]StretchBlt( _
$wParam, 0, 0, $rcRight, $rcBottom, _
$hdcMem, 0, 0, $bmWidth, $bmHeight, _
$SRCCOPY _
)
_WinAPI_SelectObject($hdcMem, $hObjOld)
[/autoit] [autoit][/autoit] [autoit]Return 1
EndFunc ;==>OnEraseBkGnd
Func StretchBlt($hdcDest, $nXOriginDest, $nYOriginDest, $nWidthDest, $nHeightDest, $hdcSrc, $nXOriginSrc, $nYOriginSrc, $nWidthSrc, $nHeightSrc, $dwRop)
Local $aRes = DllCall("gdi32.dll", "BOOL", "StretchBlt", _
"HANDLE", $hdcDest, _
"INT", $nXOriginDest, _
"INT", $nYOriginDest, _
"INT", $nWidthDest, _
"INT", $nHeightDest, _
"HANDLE", $hdcSrc, _
"INT", $nXOriginSrc, _
"INT", $nYOriginSrc, _
"INT", $nWidthSrc, _
"INT", $nHeightSrc, _
"DWORD", $dwRop)
Return $aRes[0]
EndFunc ;==>StretchBlt
Func WM_GETMINMAXINFO($hwnd, $Msg, $wParam, $lParam)
Local $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
DllStructSetData($minmaxinfo, 7, $breite_min) ; min X
DllStructSetData($minmaxinfo, 8, $hoehe_min) ; min Y
DllStructSetData($minmaxinfo, 9, $breite_max) ; max X
DllStructSetData($minmaxinfo, 10, $hoehe_max) ; max Y
Return "GUI_RUNDEFMSG"
EndFunc ;==>WM_GETMINMAXINFO
Func WM_SIZING($hwnd, $iMsg, $wParam, $lParam)
Local $sRect = DllStructCreate("Int[4]", $lParam)
Local $left = DllStructGetData($sRect, 1, 1)
Local $top = DllStructGetData($sRect, 1, 2)
Local $right = DllStructGetData($sRect, 1, 3)
Local $bottom = DllStructGetData($sRect, 1, 4)
Switch $wParam ;drag side or corner
Case 1, 2, 4, 7
Local $iNewY = Int(($right - $left) * $ratio)
DllStructSetData($sRect, 1, DllStructGetData($sRect, 1, 2) + $iNewY, 4)
Case Else
Local $iNewX = Int(($bottom - $top) / $ratio)
DllStructSetData($sRect, 1, DllStructGetData($sRect, 1, 1) + $iNewX, 3)
EndSwitch
Return "GUI_RUNDEFMSG"
EndFunc ;==>WM_SIZING
2 Kleinere Problemchen habe ich.
Wenn die Gui zum ändern der Größe unten rechts angeklickt wird, so springt diese etwas in die Breite.
Wenn die Gui ganz klein gezogen wird, stimmt das Seitenverhältnis nicht mehr.
Ok, danke.
Bin dank dir nun deutlich weitergekommen.
Den Tip mit GDI habe ich auch umgesetzt.
#region ;************ Includes ************
#include <eigen_bilder.au3>
#include <WindowsConstants.au3>
#include <ScreenCapture.au3>
#include <GUIConstantsEx.au3>
#endregion ;************ Includes ************
Global $breite_min, $breite_max, $hoehe_min, $hoehe_max, $array_bilder_1[3], $hBitmap_quelle, $hGfxCtxt, $hHBitmap, $hImage, $breite = 800
[/autoit] [autoit][/autoit] [autoit]Global $bild = @TempDir & "\" & "bild.jpg"
_ScreenCapture_Capture($bild)
_GDIPlus_Startup()
Global $hImage2 = _GDIPlus_ImageLoadFromFile($bild)
$array_bilder_1[1] = _GDIPlus_ImageGetWidth($hImage2)
$array_bilder_1[2] = _GDIPlus_ImageGetHeight($hImage2)
_GDIPlus_ImageDispose($hImage2)
_GDIPlus_Shutdown()
Global $seitenverhaeltnis = $array_bilder_1[1] / $array_bilder_1[2]
Global $hGui = GUICreate("Test", $breite, $breite / $seitenverhaeltnis, -1, -1, $WS_OVERLAPPEDWINDOW, $WS_EX_COMPOSITED)
Global $pic = GUICtrlCreatePic("", 0, 0, $breite, $breite / $seitenverhaeltnis)
_GDIPlus_Startup()
_bild()
GUISetState()
Func _bild()
$hImage = _GDIPlus_ImageLoadFromFile($bild)
Local $win = WinGetPos("Test", "")
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $win[2], "int", $win[3], "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
$hBitmap_quelle = $aResult[6]
$hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap_quelle)
DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hGfxCtxt, "int", 7)
_GDIPlus_GraphicsDrawImageRect($hGfxCtxt, $hImage, 0, 0, $win[2], $win[3])
$hHBitmap = _GDIPlus_BitmapCreateDIBFromBitmap($hBitmap_quelle)
_WinAPI_DeleteObject(GUICtrlSendMsg($pic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap))
GUICtrlSetPos($pic, Default, Default, $win[2], $win[3])
EndFunc ;==>_bild
Global $aWS = WinGetPos($hGui)
Global Const $ratio = $aWS[3] / $aWS[2]
$breite_min = 0
$breite_max = 9300
$hoehe_min = 0
$hoehe_max = 9300
_bild()
GUIRegisterMsg($WM_SIZE, "_bild")
GUIRegisterMsg($WM_SIZING, "WM_SIZING")
GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
Sleep(10)
WEnd
_GDIPlus_ImageDispose($hImage)
_GDIPlus_BitmapDispose($hBitmap_quelle)
_GDIPlus_GraphicsDispose($hGfxCtxt)
_WinAPI_DeleteObject(GUICtrlSendMsg($pic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap))
_GDIPlus_Shutdown()
Func WM_GETMINMAXINFO($hWnd, $Msg, $wParam, $lParam)
Local $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
DllStructSetData($minmaxinfo, 7, $breite_min) ; min X
DllStructSetData($minmaxinfo, 8, $hoehe_min) ; min Y
DllStructSetData($minmaxinfo, 9, $breite_max) ; max X
DllStructSetData($minmaxinfo, 10, $hoehe_max) ; max Y
Return "GUI_RUNDEFMSG"
EndFunc ;==>WM_GETMINMAXINFO
Func WM_SIZING($hWnd, $iMsg, $wParam, $lParam)
Local $sRect = DllStructCreate("Int[4]", $lParam)
Local $left = DllStructGetData($sRect, 1, 1)
Local $top = DllStructGetData($sRect, 1, 2)
Local $right = DllStructGetData($sRect, 1, 3)
Local $bottom = DllStructGetData($sRect, 1, 4)
Switch $wParam ;drag side or corner
Case 1, 2, 4, 7
Local $iNewY = Int(($right - $left) * $ratio)
DllStructSetData($sRect, 1, DllStructGetData($sRect, 1, 2) + $iNewY, 4)
Case Else
Local $iNewX = Int(($bottom - $top) / $ratio)
DllStructSetData($sRect, 1, DllStructGetData($sRect, 1, 1) + $iNewX, 3)
EndSwitch
Return "GUI_RUNDEFMSG"
EndFunc ;==>WM_SIZING
Leider wird nicht das komplette Bild dargestellt.
Je nachdem wie groß ich die GUI mache fehlt mal mehr mal weniger.
Wie kann ich es sicherstellen, dass immer genau das komplette Bild sichtbar ist ![]()
Hi,
ich würde gerne mit der Maus die GUI vergrößern.
Dabei soll während dem vergrößern sofort das Bild sich an die GUI anpassen.
Geht das?
#Region ;************ Includes ************
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ScreenCapture.au3>
#EndRegion ;************ Includes ************
Global $iMinWidth, $iMaxWidth, $hwnd, $fRatio, $iMinHeight, $iMaxHeight, $hbmp, $hdcMem, $BITMAP
[/autoit] [autoit][/autoit] [autoit]Opt("GUIOnEventMode", 1) ; 0=ausgeschaltet, 1=OnEvent Modus aktiviert
[/autoit] [autoit][/autoit] [autoit]Global $bild_name = "C:\Windows\Web\Wallpaper\Windows\img0.jpg"
[/autoit] [autoit][/autoit] [autoit]_bild_in_gui("Bild123", $bild_name, 500, 200, 700)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]Func _bild_in_gui($title_func, $bild_func, $iGUI_WidthInitial, $iMinWidth_func, $iMaxWidth_func)
Local $array_bildergroesse[3]
$iMinWidth = $iMinWidth_func
$iMaxWidth = $iMaxWidth_func
$BITMAP = "LONG bmType;" & "LONG bmWidth;" & "LONG bmHeight;" & "LONG bmWidthBytes;" & "WORD bmPlanes;" & "WORD bmBitsPixel;" & "PTR bmBits;"
[/autoit] [autoit][/autoit] [autoit];~ Global Const $HWND_DESKTOP = _WinAPI_GetDesktopWindow()
;~ $fRatio = _WinAPI_GetClientWidth($HWND_DESKTOP) / _WinAPI_GetClientHeight($HWND_DESKTOP)
$array_bildergroesse = _bildgroesse2($bild_func)
$fRatio = $array_bildergroesse[1] / $array_bildergroesse[2]
GUIRegisterMsg($WM_CREATE, "OnCreate")
GUIRegisterMsg($WM_ERASEBKGND, "OnEraseBkGnd")
GUIRegisterMsg($WM_SIZING, "WM_SIZING")
GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")
$hwnd = GUICreate($title_func, $iGUI_WidthInitial, Floor($iGUI_WidthInitial / $fRatio), -1, -1, $WS_OVERLAPPEDWINDOW)
GUISetState(@SW_SHOW, $hwnd)
GUISetOnEvent($GUI_EVENT_CLOSE, "_bild_in_gui_beenden")
[/autoit] [autoit][/autoit] [autoit]$fRatio = _WinAPI_GetWindowWidth($hwnd) / _WinAPI_GetWindowHeight($hwnd)
[/autoit] [autoit][/autoit] [autoit];fehlende min. und max. Wert ermitteln
$iMinHeight = $iMinWidth / $fRatio ;min. Höhe anhand der min. Breite und des Seitenverhältnisse berechnen
$iMaxHeight = $iMaxWidth / $fRatio ;max. Höhe anhand der max. Breite und des Seitenverhältnisse berechnen
If $iMaxHeight > @DesktopHeight Then ;max. Höhe größer als der Bildschirm >>> neue max. Breite ermitteln
$iMaxHeight = @DesktopHeight
$iMaxWidth = $iMaxHeight * $fRatio
EndIf
;Schleife
While 1
Sleep(10)
WEnd
EndFunc ;==>_bild_in_gui
Func OnCreate($hwnd, $message, $wParam, $lParam)
Local $hdc
;~ $hbmp = _ScreenCapture_Capture()
;~ If (Not $hbmp) Then ConsoleWrite(StringFormat("_WinAPI_LoadImage fehlgeschlagen!\n")); error handling here
$hdc = _WinAPI_GetDC($HWND_DESKTOP)
$hdcMem = _WinAPI_CreateCompatibleDC($hdc)
_WinAPI_ReleaseDC($HWND_DESKTOP, $hdc)
[/autoit] [autoit][/autoit] [autoit]If (Not $hdcMem) Then ConsoleWrite(StringFormat("_WinAPI_CreateCompatibleDC fehlgeschlagen!\n")) ; error handling here
[/autoit] [autoit][/autoit] [autoit]Return $GUI_RUNDEFMSG
EndFunc ;==>OnCreate
Func OnEraseBkGnd($hwnd, $message, $wParam, $lParam)
Local $rcClient
Local $hObjOld
Local $rcRight, $rcBottom
Local $bmWidth, $bmHeight
Local $bm = DllStructCreate($BITMAP)
If (Not $hbmp) Then Return 1
[/autoit] [autoit][/autoit] [autoit]; get the window's client area
$rcClient = _WinAPI_GetClientRect($hwnd)
$rcRight = DllStructGetData($rcClient, "Right")
$rcBottom = DllStructGetData($rcClient, "Bottom")
; get the bitmap dimensions
_WinAPI_GetObject($hbmp, DllStructGetSize($bm), DllStructGetPtr($bm))
; select the bitmap into the memory DC
$hObjOld = _WinAPI_SelectObject($hdcMem, $hbmp)
$bmWidth = DllStructGetData($bm, "bmWidth")
$bmHeight = DllStructGetData($bm, "bmHeight")
DllCall("gdi32.dll", "INT", "SetStretchBltMode", "HANDLE", $wParam, "INT", 4)
[/autoit] [autoit][/autoit] [autoit]StretchBlt($wParam, 0, 0, $rcRight, $rcBottom, $hdcMem, 0, 0, $bmWidth, $bmHeight, $SRCCOPY)
[/autoit] [autoit][/autoit] [autoit]_WinAPI_SelectObject($hdcMem, $hObjOld)
[/autoit] [autoit][/autoit] [autoit]Return 1
EndFunc ;==>OnEraseBkGnd
Func StretchBlt($hdcDest, $nXOriginDest, $nYOriginDest, $nWidthDest, $nHeightDest, $hdcSrc, $nXOriginSrc, $nYOriginSrc, $nWidthSrc, $nHeightSrc, $dwRop)
Local $aRes = DllCall("gdi32.dll", "BOOL", "StretchBlt", "HANDLE", $hdcDest, "INT", $nXOriginDest, "INT", $nYOriginDest, "INT", $nWidthDest, "INT", $nHeightDest, "HANDLE", $hdcSrc, "INT", $nXOriginSrc, "INT", $nYOriginSrc, "INT", $nWidthSrc, "INT", $nHeightSrc, "DWORD", $dwRop)
Return $aRes[0]
EndFunc ;==>StretchBlt
Func WM_GETMINMAXINFO($hwnd, $Msg, $wParam, $lParam)
Local $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
DllStructSetData($minmaxinfo, 7, $iMinWidth) ; min X
DllStructSetData($minmaxinfo, 8, $iMinHeight) ; min Y
DllStructSetData($minmaxinfo, 9, $iMaxWidth) ; max X
DllStructSetData($minmaxinfo, 10, $iMaxHeight) ; max Y
Return "GUI_RUNDEFMSG"
EndFunc ;==>WM_GETMINMAXINFO
Func WM_SIZING($hwnd, $iMsg, $wParam, $lParam)
Local $tRect_Cur = DllStructCreate("int[4]", $lParam)
Local $left = DllStructGetData($tRect_Cur, 1, 1)
Local $top = DllStructGetData($tRect_Cur, 1, 2)
Local $right = DllStructGetData($tRect_Cur, 1, 3)
Local $bottom = DllStructGetData($tRect_Cur, 1, 4)
Switch $wParam ;drag side or corner
Case 1, 2, 4, 7
Local $iNewY = Int(($right - $left) / $fRatio)
DllStructSetData($tRect_Cur, 1, $top + $iNewY, 4)
Case Else
Local $iNewX = Int(($bottom - $top) * $fRatio)
DllStructSetData($tRect_Cur, 1, $left + $iNewX, 3)
EndSwitch
Return "GUI_RUNDEFMSG"
EndFunc ;==>WM_SIZING
Func _bild_in_gui_beenden()
; free resources
_WinAPI_DeleteObject($hbmp)
_WinAPI_DeleteDC($hdcMem)
GUIDelete($hwnd)
EndFunc ;==>_bild_in_gui_beenden
Func _bildgroesse2($bildgroesse_pfad_dateiname)
Local $array_bilder_1[3], $hImage3
; Initialisiert (startet) Microsoft Windows GDI+
_GDIPlus_Startup()
; Lädt ein Bild
$hImage3 = _GDIPlus_ImageLoadFromFile($bildgroesse_pfad_dateiname)
; Erzeugt eine Kopie einer 24 bit Bitmap
$array_bilder_1[1] = _GDIPlus_ImageGetWidth($hImage3)
$array_bilder_1[2] = _GDIPlus_ImageGetHeight($hImage3)
; Ressourcen freigeben
_GDIPlus_ImageDispose($hImage3)
; Gibt die durch Microsoft Windows GDI+ verwendeten Ressourcen wieder frei
_GDIPlus_Shutdown()
Return $array_bilder_1
EndFunc ;==>_bildgroesse