那片叶子 发表于 2011-12-19 22:41:59

PNG如何切换PNG图片?

#include <GDIPlus.au3>
#include <GuiComboBox.au3>
#include <File.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <ButtonConstants.au3>
#include <Sound.au3>
#include <Date.au3>
Opt("MustDeclareVars", 0)
Global Const $AC_SRC_ALPHA = 1
_GDIPlus_Startup()
$Src = @scriptdir&"\beijing.png"
$hImage =_GDIPlus_ImageLoadFromFile($Src)
$width =_GDIPlus_ImageGetWidth ($hImage)
$height = _GDIPlus_ImageGetHeight($hImage)
$GUI = GUICreate("beijing", $width, $height, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
SetBitMap($GUI, $hImage, 0)
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
GUISetState()
WinSetOnTop($gui,"",1)
for $i = 0 to 255 step 10
SetBitMap($GUI, $hImage, $i)
next

_WinAPI_DeleteObject($hImage)
_GDIPlus_Shutdown()
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
if ($hWnd = $GUI) 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)
EndFunc
While 1
$msg = GUIGetMsg()
    Select
                Case $msg = $GUI_EVENT_CLOSE
               Exit
EndSelect
WEnd上面这个代码是显示PNG的 ,比如我安个按钮把显示的PNG换成PNG2 !
代码怎么加?  急....

happytc 发表于 2011-12-20 00:11:51

回复 1# 那片叶子

哈,好久以前写的代码,你看看神仙妹妹:美女


#NoTrayIcon
#Include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Memory.au3>
#include <String.au3>
#include <GDIPlus.au3>

Global $SocketID

_SlidePicture()

Func _SlidePicture()
      Local $hImage, $iWidth, $iHeight, $hGui
      Local $sLink = "myarticle.enet.com.cn", $sPic = "/images/2007/0917/1189986155220/"
      
      Opt("GUIOnEventMode", 1)
      $hGui = GUICreate("Slide Picture", -1, -1, -1, -1, -1, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW))
      GUISetState()
      WinSetOnTop($hGui, "", 1)
      GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_GuiOnEvent", $hGUI)
      
      For $i = 1 To 6
                _GDIPlus_Startup()
                $hImage = _ImageFromNet($sLink, $sPic & $i & ".jpg")
                $iWidth = _GDIPlus_ImageGetWidth($hImage)
                $iHeight = _GDIPlus_ImageGetHeight($hImage)
               
                WinMove($hGUI, "", -1, -1, $iWidth, $iHeight)
                For $j = 0 to 255 step 1
                        _SetGuiBitmap($hGui, $hImage, $j)
                        Sleep(10)
                Next
               
                For $j = 255 to 0 step -1
                        _SetGuiBitmap($hGui, $hImage, $j)
                        Sleep(10)
                Next
                _GDIPlus_ImageDispose($hImage)
                _GDIPlus_Shutdown()
      Next
      GUIDelete($hGUI)
EndFunc

Func _ImageFromNet($sHost, $sSource)
      Local $sIp, $sData, $sSocket, $sRecvHeader = "", $sRecvBin = "0x", $aRet
      Local $iBytes, $mBitmap, $iLength, $hData, $pData, $tMem, $aResult
      
    TCPStartup()
    $sIp = TCPNameToIP($sHost)
    $sData = "GET " & $sSource & " HTTP/1.1" & @Crlf & "Host: " & $sHost & @Crlf & @CRLF
    $sSocket = TCPConnect ($sIp, 80)
    TCPSend ($sSocket, $sData)
    If @error Then Return Seterror(1, 1, 1)

    Do
      $sRecvHeader = TCPRecv($sSocket, 1)
    Until $sRecvHeader <> ""
      
    Do
      $sRecvHeader &= TCPRecv($sSocket, 1)
    Until StringInStr($sRecvHeader, @Crlf & @Crlf)
      
    $aRet = _StringBetween($sRecvHeader, 'Content-Length: ', @Crlf )
    If IsArray($aRet) Then
                $iBytes = $aRet      
                Do
                        $sRecvBin &= StringTrimLeft(TCPRecv($sSocket, 1024, 1 ), 2)
                Until BinaryLen(Binary($sRecvBin)) >= $iBytes
               
                TCPCloseSocket($sSocket)
                TCPShutdown()
                $mBitmap = Binary($sRecvBin)
                $iLength =BinaryLen($mBitmap)
                $hData = _MemGlobalAlloc ($iLength, $GMEM_MOVEABLE)
                $pData = _MemGlobalLock ($hData)
                $tMem =DllStructCreate ( "byte[" & $iLength & "]", $pData )
                DllStructSetData ($tMem, 1, $mBitmap)
                _MemGlobalUnlock ($hData)
                $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "hwnd", $pData, "int", True, "ptr*", 0)
                If @error Then Return SetError(@error, @extended, 0)
                $aResult = DllCall ($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $aResult, "int*", 0)
                If @error Then Return SetError (@error, @extended, 0)
                Return $aResult
      Else
      TCPCloseSocket($SocketID)
      TCPShutdown( )
      Return Seterror(1, 1, 1)
    EndIf
EndFunc

Func _SetGuiBitmap($hGUI, $hImage, $iTrans)
    Local $hDC, $hCDC, $hBitmap, $hObj, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
   
      $hDC = _WinAPI_GetDC(0)
    $hCDC = _WinAPI_CreateCompatibleDC($hDC)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $hObj = _WinAPI_SelectObject($hCDC, $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" , $iTrans)
    DllStructSetData ($tBlend, "Format", 1)
   _WinAPI_UpdateLayeredWindow($hGUI, $hDC, 0, $pSize, $hCDC, $pSource, 0, $pBlend, $ULW_ALPHA)
   _WinAPI_ReleaseDC(0, $hDC)
   _WinAPI_SelectObject($hCDC, $hObj)
   _WinAPI_DeleteObject($hBitmap)
   _WinAPI_DeleteDC($hCDC)
EndFunc

Func _GuiOnEvent()
      ConsoleWrite("Hit Left key!" & @CRLF)
EndFunc

komaau3 发表于 2011-12-20 05:32:20

LS牛人啊 会玩!!!!!

那片叶子 发表于 2011-12-20 10:22:48

回复 2# happytc


    谢谢二楼的!~

5735988 发表于 2011-12-20 16:28:11

怀着学习的态度,顶顶更健康!有好多都不懂呢
页: [1]
查看完整版本: PNG如何切换PNG图片?