|
楼主 |
发表于 2019-10-26 20:34:52
|
显示全部楼层
本帖最后由 anythinging 于 2019-10-26 20:36 编辑
这个是A版的显示图片代码,需要按esc退出,如果想按任意键退出的话,尝试了不同的地方,不知将GUIRegisterMsg($WM_KEYDOWN, "KEY")加在哪里可以实现。
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
Opt('GUIOnEventMode', 1)
Global $PicFile = 'D:\SYSTEM\DESKTOP\wallpaper\1834-105.jpg' ;---- 图片文件路径
Global $BackColor = 0xE9E9E9 ;---- 背景色
GUIRegisterMsg($WM_KEYDOWN, "KEY")
_PicFullScreenShow($PicFile, $BackColor)
While 1
Sleep(1000)
WEnd
Func _PicFullScreenShow($PicFile, $BackColor = 0)
;============== 全屏显示图片文件(缩放:仅缩小尺寸超出的图片)
;$PicFile - 图片文件路径
;$BackColor - 填充背景色
Local $hGui = GUICreate('PhotoBrowser@afan', @DesktopWidth, @DesktopHeight, -1, 0, 0x80000000, 0x00000008)
;$WS_POPUP = 0x80000000 ;$WS_EX_TOPMOST = 0x00000008
GUISetBkColor($BackColor)
GUISetOnEvent(-3, '_Exit')
__ImageToPicControls($PicFile, GUICtrlCreatePic('', 0, 0))
If @Error Then Exit MsgBox(48, '错误', $PicFile & ' 非图片格式')
GUISetState()
EndFunc ;==>_PicFullScreenShow
Func __ImageToPicControls($PicFilePath, $PicControls)
;=============== 将图片设置到控件
;$PicFilePath - 图片文件路径
;$PicControls - 图片控件ID
Local $hImage, $ImageWidth, $ImageHeight
;---- 载入图片
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($PicFilePath)
$ImageWidth = _GDIPlus_ImageGetWidth($hImage)
$ImageHeight = _GDIPlus_ImageGetHeight($hImage)
If $ImageWidth * $ImageHeight = 0 Then
_GDIPlus_Shutdown()
Return SetError(1)
EndIf
;---- 计算图片高宽比及居中偏移
Local $PicWidth = @DesktopWidth, $PicHeight = @DesktopHeight
Local $PicCnAspectRatio = $PicHeight / $PicWidth
Local $ImgAspectRatio = $ImageHeight / $ImageWidth
Local $iOffset_X = 0, $iOffset_Y = 0, $hBMP, $hObject
If $ImageWidth > $PicWidth Or $ImageHeight > $PicHeight Then
If $ImgAspectRatio > $PicCnAspectRatio Then
$ImageHeight = $PicHeight
$ImageWidth = Round(1 / $ImgAspectRatio * $ImageHeight)
$iOffset_X = ($PicWidth - $ImageWidth) / 2
Else
$ImageWidth = $PicWidth
$ImageHeight = Round($ImgAspectRatio * $ImageWidth)
$iOffset_Y = ($PicHeight - $ImageHeight) / 2
EndIf
Else
$iOffset_X = ($PicWidth - $ImageWidth) / 2
$iOffset_Y = ($PicHeight - $ImageHeight) / 2
EndIf
;---- 将图像设置到控件
$hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$hObject = GUICtrlSendMsg($PicControls, 0x0172, 0, $hBMP)
;---- $STM_SETIMAGE = 0x0172, $IMAGE_BITMAP = 0
_WinAPI_DeleteObject($hObject)
_GDIPlus_ImageDispose($hImage)
_WinAPI_DeleteObject($hBMP)
_GDIPlus_Shutdown()
GUICtrlSetPos($PicControls, $iOffset_X - 1, $iOffset_Y - 1, $ImageWidth, $ImageHeight)
EndFunc ;==>__ImageToPicControls
Func _Exit()
GUIDelete()
Exit
EndFunc ;==>_Exit
Func KEY($hWnd, $Msg, $wParam, $lParam)
Exit
EndFunc ;==>KEY
恳请指点,谢谢!
|
|