Das hat was mit dem Repaint des Fensters zu tun. Die Version von name22 ist zwar länger, aber dafür "weicher" beim Resizen.
Machmal kommt es doch auf die Länge an...
Gruß,
UEZ ![]()
Das hat was mit dem Repaint des Fensters zu tun. Die Version von name22 ist zwar länger, aber dafür "weicher" beim Resizen.
Machmal kommt es doch auf die Länge an...
Gruß,
UEZ ![]()
Bitte nochmals um Rat zur Vervollständigkeit des Skript
[ offen ] Bildgröße laufend an GUI anpassen
Was genau versuchst du alles umzusetzen? Ich hab morgen vermutlich Zeit eines der Scripte hier entsprechend umzuschreiben (wenn ich das umsetzen kann was du willst ^^). Vielleicht hat aber bis dahin auch jemand anders die Lösung.
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
Sorry wenn das so ein langwieriger Prozess ist, aber das Script ist mittlerweile ein ziemlich unübersichtlicher Flickenteppich aus 3 komplett verschiedenen Coding-Stilen ^^.
Ich habe mal das eingebaut von dem ich glaube, dass du es eingebaut haben willst. Du kannst jetzt über die Funktion _LoadImage eine beliebige Bitmap am Scriptanfang (oder irgendwann im Scriptverlauf) laden und auch danach durch eine andere ersetzen.
#region ;************ Includes ************
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ScreenCapture.au3>
#include <Constants.au3>
#include <SendMessage.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", "", "Bitmap (*.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)
GUISetState()
_LoadImage($sPath_ImageInitial)
[/autoit] [autoit][/autoit] [autoit]GUISetOnEvent($GUI_EVENT_CLOSE, "_beenden")
[/autoit] [autoit][/autoit] [autoit];Schleife
While Sleep(1000)
WEnd
Func _LoadImage($sPath_Image)
Local $tRect = DllStructCreate($tagRECT)
Local $tBM = DllStructCreate($BITMAP)
If $hBmp Then _WinAPI_DeleteObject($hBmp)
[/autoit] [autoit][/autoit] [autoit]$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
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
Du musst das nicht über Dateien machen. Ich schreib dir das mal kurz um.
#region ;************ Includes ************
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ScreenCapture.au3>
#include <Constants.au3>
#include <SendMessage.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", "", "Images (*.jpeg;*.jpg;*.png;*.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)
GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "_beenden")
[/autoit] [autoit][/autoit] [autoit]_GDIPlus_Startup()
_LoadImage($sPath_ImageInitial)
;Schleife
While Sleep(1000)
WEnd
Func _LoadImage($sPath_Image)
Local $tRect = DllStructCreate($tagRECT)
Local $tBM = DllStructCreate($BITMAP)
Local $hImage = _GDIPlus_ImageLoadFromFile($sPath_Image)
If $hBmp Then _WinAPI_DeleteObject($hBmp)
[/autoit] [autoit][/autoit] [autoit]$hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage, 0)
_GDIPlus_ImageDispose($hImage)
_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)
_GDIPlus_Shutdown()
[/autoit] [autoit][/autoit] [autoit]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
Jetzt wird es über GDI+ geladen und dann wird im Speicher aus der GDI+ Bitmap eine mit GDI kompatible Bitmap erzeugt.
Oh man so einfach ![]()
Habe eben noch bemerkt, dass das Bild etwas verzerrt ist.
In der Höhe ist es gestaucht ![]()
Das ist vielleicht ne schwere Geburt... Jetzt aber:
#region ;************ Includes ************
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ScreenCapture.au3>
#include <Constants.au3>
#include <SendMessage.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", "", "Images (*.jpeg;*.jpg;*.png;*.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)
GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "_beenden")
[/autoit] [autoit][/autoit] [autoit]_GDIPlus_Startup()
_LoadImage($sPath_ImageInitial)
;Schleife
While Sleep(1000)
WEnd
Func _LoadImage($sPath_Image)
Local $tRect = DllStructCreate($tagRECT)
Local $tBM = DllStructCreate($BITMAP)
Local $hImage = _GDIPlus_ImageLoadFromFile($sPath_Image)
If $hBmp Then _WinAPI_DeleteObject($hBmp)
[/autoit] [autoit][/autoit] [autoit]$hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage, 0)
_GDIPlus_ImageDispose($hImage)
_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, _WinAPI_GetWindowLong($hWnd, $GWL_STYLE), _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)
_GDIPlus_Shutdown()
[/autoit] [autoit][/autoit] [autoit]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 komme weder mit den schwachsinnigen Fensterkoordinaten, noch mit AdjustWindowRectEx klar... ![]()
OK, passt, perfekt ![]()
Tausend Dank an alle die mitgeholfen haben ![]()
Damit gelöst ![]()
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
Das liegt daran, dass du das Script umgebaut hast, ohne es komplett zu verstehen.. Im Grunde brauchst du diesen Teil des Scripts gar nicht mehr wenn du das so machst...
Von dem Teil der am meisten Probleme bereitet hat, WM_SIZING etc., sehe ich auch nichts mehr. Wie wäre es wenn du uns sagst, was du konkret vorhast? Eine Bildschirmlupe habe ich mal aus Langeweile geschrieben, das ist kein großes Problem, aber es kann ja keiner wissen, dass du das willst.
Wie wäre es denn mit diesem Script als Basis für dein Vorhaben? Das dürfte wesentlich sauberer und performanter sein als der Flickenteppich der in diesem Thread entstanden ist.
#include <WinAPI.au3>
#include <Constants.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
; -Author: name22 (http://www.autoit.de)
[/autoit] [autoit][/autoit] [autoit]Opt("GUIOnEventMode")
[/autoit] [autoit][/autoit] [autoit]Global Const $iFlag = BitOR($SWP_NOSIZE, $SWP_NOZORDER), $tagMSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo"
Global $hWnd_Magnifier, $hWnd_Desktop, $hDC_Window, $hDC_Desktop
Global $hDll_GDI32 = DllOpen("gdi32.dll"), $hDll_User32 = DllOpen("user32.dll")
Global $iGUIWidth = 100
Global $iGUIHeight = 100
Global $iCaptureWidth = 50
Global $iCaptureHeight = 50
$hWnd_Magnifier = GUICreate("", $iGUIWidth, $iGUIHeight, -1, -1, $WS_POPUP, $WS_EX_TOPMOST)
GUISetState()
$hWnd_Desktop = _WinAPI_GetDesktopWindow()
$hDC_Window = _WinAPI_GetDC($hWnd_Magnifier)
$hDC_Desktop = _WinAPI_GetDC($hWnd_Desktop)
DllCall($hDll_GDI32, "INT", "SetStretchBltMode", "HANDLE", $hDC_Window, "INT", 3)
$hMouseProc = DllCallbackRegister("_MouseProc", "int", "int;ptr;ptr")
$hMouseHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hMouseProc), _WinAPI_GetModuleHandle(0), 0)
OnAutoItExitRegister("_Shutdown")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
HotKeySet("{ESC}", "_Exit")
_ReDraw(_WinAPI_GetMousePosX(), _WinAPI_GetMousePosY())
[/autoit] [autoit][/autoit] [autoit]While Sleep(1000)
WEnd
Func _MouseProc($nCode, $wParam, $lParam)
If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam)
Local $iEvent = BitAND($wParam, 0xFFFF)
If $iEvent = $WM_MOUSEMOVE Then
Local $tMHook = DllStructCreate($tagMSLLHOOKSTRUCT, $lParam)
_ReDraw(DllStructGetData($tMHook, "X"), DllStructGetData($tMHook, "Y"))
EndIf
Return _WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam)
EndFunc
Func _ReDraw($iX_Mouse, $iY_Mouse)
Local $iX_MouseTmp = $iX_Mouse
Local $iY_MouseTmp = $iY_Mouse
If $iX_MouseTmp < 0 Then $iX_MouseTmp = 0
If $iX_MouseTmp > 1920 - $iGUIWidth - $iCaptureWidth / 2 - 2 Then $iX_MouseTmp = 1920 - $iGUIWidth - $iCaptureWidth / 2 - 2
If $iY_MouseTmp < 0 Then $iY_MouseTmp = 0
If $iY_MouseTmp > 1080 - $iGUIHeight - $iCaptureHeight / 2 - 2 Then $iY_MouseTmp = 1080 - $iGUIHeight - $iCaptureHeight / 2 - 2
DllCall($hDll_User32, "BOOL", "SetWindowPos", "HWND", $hWnd_Magnifier, "HWND", 0, "INT", $iX_MouseTmp + $iCaptureWidth / 2 + 2, "INT", $iY_MouseTmp + $iCaptureHeight / 2 + 2, "INT", 0, "INT", 0, "UINT", $iFlag)
DllCall($hDll_GDI32, "INT", "StretchBlt", "HWND", $hDC_Window, "INT", 0, "INT", 0, "INT", $iGUIWidth, "INT", $iGUIHeight, "HWND", $hDC_Desktop, "INT", $iX_Mouse - $iCaptureWidth / 2, "INT", $iY_Mouse - $iCaptureHeight / 2, "INT", $iCaptureWidth, "INT", $iCaptureHeight, "DWORD", $SRCCOPY)
EndFunc ;==>_ReDraw
Func _Exit()
Exit
EndFunc ;==>_Exit
Func _Shutdown()
_WinAPI_UnhookWindowsHookEx($hMouseHook)
DllCallbackFree($hMouseProc)
_WinAPI_ReleaseDC($hWnd_Magnifier, $hDC_Window)
_WinAPI_ReleaseDC($hWnd_Desktop, $hDC_Desktop)
DllClose($hDll_GDI32)
DllClose($hDll_User32)
EndFunc
; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_StretchBlt
; Description....: Copies a bitmap from a source rectangle into a destination rectangle, stretching or compressing the bitmap
; to fit the dimensions of the destination rectangle, if necessary.
; Syntax.........: _WinAPI_StretchBlt ( $hDestDC, $iXDest, $iYDest, $iWidthDest, $iHeightDest, $hSrcDC, $iXSrc, $iYSrc, $iWidthSrc, $iHeightSrc, $iRop )
; Parameters.....: $hDestDC - Handle to the destination device context.
; $iXDest - The x-coordinate, in logical units, of the upper-left corner of the destination rectangle.
; $iYDest - The y-coordinate, in logical units, of the upper-left corner of the destination rectangle.
; $iWidthDest - The width, in logical units, of the destination rectangle.
; $iHeightDest - The height, in logical units, of the destination rectangle.
; $hSrcDC - Handle to the source device context.
; $iXSrc - The x-coordinate, in logical units, of the upper-left corner of the source rectangle.
; $iYSrc - The y-coordinate, in logical units, of the upper-left corner of the source rectangle.
; $iWidthSrc - The width, in logical units, of the source rectangle.
; $iHeightSrc - The height, in logical units, of the source rectangle.
; $iRop - The raster-operation code. These codes define how the color data for the source rectangle is
; to be combined with the color data for the destination rectangle to achieve the final color.
; This parameter must be 0 or one of the following values.
;
; $BLACKNESS
; $CAPTUREBLT
; $DSTINVERT
; $MERGECOPY
; $MERGEPAINT
; $NOMIRRORBITMAP
; $NOTSRCCOPY
; $NOTSRCERASE
; $PATCOPY
; $PATINVERT
; $PATPAINT
; $SRCAND
; $SRCCOPY
; $SRCERASE
; $SRCINVERT
; $SRCPAINT
; $WHITENESS
;
; Return values..: Success - 1.
; Failure - 0 and sets the @error flag to non-zero.
; Author.........: Yashied
; Modified.......:
; Remarks........: The system stretches or compresses the bitmap according to the stretching mode currently set in the
; destination device context.
; Related........:
; Link...........: @@MsdnLink@@ StretchBlt
; Example........: Yes
; ===============================================================================================================================
Func _WinAPI_StretchBlt($hDestDC, $iXDest, $iYDest, $iWidthDest, $iHeightDest, $hSrcDC, $iXSrc, $iYSrc, $iWidthSrc, $iHeightSrc, $iRop)
[/autoit] [autoit][/autoit] [autoit]Local $Ret = DllCall('gdi32.dll', 'int', 'StretchBlt', 'hwnd', $hDestDC, 'int', $iXDest, 'int', $iYDest, 'int', $iWidthDest, 'int', $iHeightDest, 'hwnd', $hSrcDC, 'int', $iXSrc, 'int', $iYSrc, 'int', $iWidthSrc, 'int', $iHeightSrc, 'dword', $iRop)
[/autoit] [autoit][/autoit] [autoit]If (@error) Or (Not $Ret[0]) Then
Return SetError(1, 0, 0)
EndIf
Return 1
EndFunc ;==>_WinAPI_StretchBlt
Ich habe damals einen Hook auf die Maus gesetzt um wirklich bei jeder Bewegung das Fenster zu aktualisieren. Mittlerweile bin ich mir nicht mehr so sicher, ob das eine gute Idee war (Mousehooks können nämlich die Mausbewegung verlangsamen wenn die Callback Funktion zu lange dauert).
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.
Tweaky Uff.. Du hast da was größeres vor, oder? Könntest du mir vielleicht erklären wie genau du dir das vorstellst? UEZ hat zwar schon festgestellt, dass alle Wege nach Rom führen, aber nicht alle Wege liefern ein gutes Endprodukt. Wenn du wir hier Schrittweise vorankriechen dann dauert das länger und es muss eine Menge korrigiert werden...
ZitatTeilweise verstehe ich das Skript.
Ich habe zum testenalles rausgeschmissen was nichts mit dem Fehler zu tun hat.
Ich wollte es einfacher machen, damit man den Fehler besser finden kann.
Ach so ^^. Wusste ich ja nicht, sorry.
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.
Und die Screenshots sollen mit der Lupe ausgewählt werden um sie dann in der saklierbaren GUI anzuzeigen? Wie genau sollen die ausgewählt werden, nur der Bereich der in dem Lupenfenster angezeigt wird?
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 ![]()
Die Funktion OnEraseBkGnd wird für jedes Fenster aufgerufen, dessen Hintergrund neu gemalt werden soll (WM_ERASEBKGND Message). Dann wird der Hintergrund dieses Fensters durch den Inhalt der Bitmap $hBmp ersetzt. Und was ist bei deinem Script in $hBmp? ![]()
Außerdem brauchst du das doch sowieso erst für das andere Fenster, weil du den Hintergrund der Lupe sowieso ständig mit einem Screenshot übermalst (das wäre sonst doppelt gemoppelt ^^).
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?
Registriere die Nachricht doch einfach erst sobald du sie brauchst... Aber wenn du es überprüfen willst, geht das mit dem $hWnd Parameter der OnEraseBkGnd Funktion. Der enthält immer das Handle zu dem Fenster von dem die Nachricht kommt.