找回密码
 加入
搜索
查看: 5993|回复: 11

[GUI管理] 在整个GUI窗口显示图片,图片2秒钟换一张,怎样实现点击每个图片执行命令呢

  [复制链接]
发表于 2011-10-26 20:49:50 | 显示全部楼层 |阅读模式
在整个GUI窗口显示图片,图片2秒钟换一张,怎样实现点击每个图片执行命令呢
源码如下:
#include <array.au3>
#include <file.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>


Local $path =@MyDocumentsDir&"\My Pictures\"
Local $xfile = _FileListToArray($path, "*.jpg")
Local $f, $shell, $s, $i

$win = GUICreate("")
$Form1 = GUICreate("Form1", 249, 352, @DesktopWidth-260, @DesktopHeight-515,0x80000000,0,$win)
$jpg = GUICtrlCreatePic("", -1, -1, 250, 353)

GUISetState()
While 1
For $i = 1 To UBound($xfile) - 1
        $file = $path& $xfile[$i]
$num=$xfile[$i]
        GUICtrlSetImage($jpg, $file)
        Sleep(2000)
Next
WEnd
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
     Case $jpg
      MsgBox(0,"",$num)
                  
        EndSwitch
WEnd
发表于 2011-10-26 22:02:25 | 显示全部楼层
要实现图片2秒钟换一张 应该用 AdlibRegister 函数
你的第1个循环要取消, 用AdlibRegister函数注册的函数替换掉
发表于 2011-10-26 22:06:28 | 显示全部楼层
本帖最后由 xwt620 于 2011-10-27 01:11 编辑

你的窗口控件不能响应啊,因为程序一直在第一个whlie 1里循环出不来了
#include <array.au3>
#include <file.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>


Global $path = @MyDocumentsDir & "\My Pictures"
Global $xfile = _FileListToArray($path, "*.jpg")
Global $f, $shell, $s, $i = 1, $num

$win = GUICreate("111", 400, 300)
$Form1 = GUICreate("Form1", 249, 352, @DesktopWidth - 260, @DesktopHeight - 515);,0x80000000,0,$win)
$jpg = GUICtrlCreatePic("", -1, -1, 250, 353)

GUISetState()
AdlibRegister("ShowImage", 2000)

Func ShowImage()
        If $i <= UBound($xfile) - 1 Then
                $file = $path & $xfile[$i]
                $num = $xfile[$i]
                GUICtrlSetImage($jpg, $file)
                $i += 1
        Else
                $i = 1
                $file = $path & $xfile[$i]
                $num = $xfile[$i]
                GUICtrlSetImage($jpg, $file)
                $i += 1
        EndIf
EndFunc   ;==>ShowImage

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $jpg
;~                         MsgBox(0, "", $num)
                                                AdlibUnRegister()
                        If $i <= UBound($xfile) - 1 Then
                                $file = $path & $xfile[$i]
                                $num = $xfile[$i]
                                GUICtrlSetImage($jpg, $file)
                                $i += 1
                        Else
                                $i = 1
                                $file = $path & $xfile[$i]
                                $num = $xfile[$i]
                                GUICtrlSetImage($jpg, $file)
                                $i += 1
                        EndIf
                        AdlibRegister("ShowImage", 2000)        EndSwitch
WEnd
 楼主| 发表于 2011-10-26 22:29:54 | 显示全部楼层
我也知道是第一个WHILE的问题,忘了还有这个AdlibRegister函数,谢谢楼上两位大哥了,
非常感谢:xwt620
 楼主| 发表于 2011-10-26 22:31:28 | 显示全部楼层
接触AU3很久了,GUI还是有很多不懂,真是惭愧啊
发表于 2011-10-26 22:35:12 | 显示全部楼层
本帖最后由 xms77 于 2011-10-26 22:36 编辑

回复 1# qzhid
#include <array.au3>
#include <file.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>


Local $path = @MyDocumentsDir & "\My Pictures"
Local $xfile = _FileListToArray($path, "*.jpg",1)
;_ArrayDisplay($xfile)
Local $i
Global $pic_info,$file,$Timer

Opt('GUIOnEventMode', 1) ;事件模式
HotKeySet("{Esc}","_Exit") ;按Esc键退出程序
$win = GUICreate("")
$Form1 = GUICreate("Form1", 249, 352, @DesktopWidth-260, @DesktopHeight-515,0x80000000,0,$win)
$jpg = GUICtrlCreatePic("", -1, -1, 250, 353)
GUICtrlSetOnEvent(-1, '_ShowPic')

GUISetState()
$i = 1
While 1
        If $i > $xfile[0] Then $i = 1
        If $Timer = 0 Then
                AdlibRegister("_Setpic",2000)
                $Timer = 1 
                $pic_info = $xfile[$i]
                $file = $path&""&$pic_info
                $i += 1
        EndIf
        Sleep(100)
WEnd

Func _Setpic()
        GUICtrlSetImage($jpg,$file)
        $Timer = 0         
EndFunc  ;==> _Setpic

Func _ShowPic()
        Switch @GUI_CtrlId
                        Case $jpg
                                MsgBox(0,"现在显示的图片名为", $pic_info,2)        
                EndSwitch
EndFunc  ;==> _ShowPic
        
Func _Exit()        
        Exit
EndFunc  ;==> _Exit
发表于 2011-10-26 22:45:21 | 显示全部楼层
回复 3# xwt620
怎么没有图片显示啊?
发表于 2011-10-26 23:00:33 | 显示全部楼层
回复 7# xms77


    $path = @MyDocumentsDir & "\My Pictures\"
说明 你的路径里没有图片
发表于 2011-10-27 08:14:09 | 显示全部楼层
回复 8# xwt620
我是使用的有图片的路径,非这个代码里的路径
发表于 2011-10-27 10:28:02 | 显示全部楼层
回复 7# xms77


    算了,我请你看神仙妹妹,好嘛!

#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[0]        
                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[3], "int*", 0)
                If @error Then Return SetError (@error, @extended, 0)
                Return $aResult[2]
        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

发表于 2011-10-27 10:32:55 | 显示全部楼层
_slidepicure()不错哈
发表于 2011-10-27 10:39:40 | 显示全部楼层
回复 10# happytc
哇,果然有神仙MM,是亦非MM吗?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-25 14:06 , Processed in 0.105124 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表