官方找的 测试有效 test.jpg 滚轮缩放
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <winapi.au3>
_GDIPlus_Startup()
Local $msg
Global Const $STM_SETIMAGE = 0x0172
Global Const $IMAGE_BITMAP = 0
$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\test.jpg')
$iX_ImageDisplay = _GDIPlus_ImageGetWidth($hImage)
$iY_ImageDisplay = _GDIPlus_ImageGetHeight($hImage)
ConsoleWrite($iX_ImageDisplay & " x " & $iY_ImageDisplay & @CRLF)
$iFactor_ImageDisplay = 1
If $iX_ImageDisplay > @DesktopWidth Or $iY_ImageDisplay > @DesktopHeight Then
$iX_ImageDisplay = $iX_ImageDisplay * (@DesktopHeight / $iY_ImageDisplay)
$iFactor_ImageDisplay = @DesktopHeight / $iY_ImageDisplay
$iY_ImageDisplay = @DesktopHeight
If $iX_ImageDisplay > @DesktopWidth Then
$iY_ImageDisplay = $iY_ImageDisplay * (@DesktopWidth / $iX_ImageDisplay)
$iFactor_ImageDisplay = @DesktopWidth / $iX_ImageDisplay
$iX_ImageDisplay = @DesktopWidth
EndIf
EndIf
$iX_ImageDisplay = Int($iX_ImageDisplay)
$iY_ImageDisplay = Int($iY_ImageDisplay)
$gui_image_display = GUICreate("My GUI", $iX_ImageDisplay, $iY_ImageDisplay, Default, Default, $WS_OVERLAPPEDWINDOW); will create a dialog box that when displayed is centered
$pic_image_display = GUICtrlCreatePic("", 0, 0, $iX_ImageDisplay, $iY_ImageDisplay)
;If $iFactor_ImageDisplay <> 1 Then
; $hGraphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($pic_image_display))
; _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iX_ImageDisplay, $iY_ImageDisplay)
ConsoleWrite($iX_ImageDisplay & @TAB & $iY_ImageDisplay & @CRLF)
;EndIf
$hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
_WinAPI_DeleteObject(GUICtrlSendMsg($pic_image_display, $STM_SETIMAGE, $IMAGE_BITMAP, $hBMP))
;$aBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", GUICtrlGetHandle($pic_image_display), "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBMP)
;_WinAPI_RedrawWindow($gui_image_display, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME))
;If $aBmp[0] <> 0 Then _WinAPI_DeleteObject($aBmp[0])
_GDIPlus_ImageDispose($hImage)
_WinAPI_DeleteObject($hBMP)
;If $iFactor_ImageDisplay <> 1 Then
; _GDIPlus_GraphicsDispose($hGraphic)
;EndIf
_GDIPlus_Shutdown()
GUICtrlSetPos($pic_image_display, 0, 0, $iX_ImageDisplay, $iY_ImageDisplay)
GUIRegisterMsg(522, "_ResizePic"); WM_MOUSEWHEEL
GUISetState(@SW_SHOW); will display an empty dialog box
; Run the GUI until the dialog is closed
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()
Func _ResizePic($hWnd, $iMsg, $wParam, $lParam)
If BitShift($wParam, 16) > 0 Then
$iX_ImageDisplay *= 1.1
$iY_ImageDisplay *= 1.1
Else
$iX_ImageDisplay /= 1.1
$iY_ImageDisplay /= 1.1
EndIf
GUICtrlSetPos($pic_image_display, 0, 0, $iX_ImageDisplay, $iY_ImageDisplay)
EndFunc ;==>_ResizePic
|