找回密码
 加入
搜索
查看: 2404|回复: 1

关于PNG+滚动文字的问题

[复制链接]
发表于 2009-5-17 11:11:23 | 显示全部楼层 |阅读模式
请问一下兄弟们。 关于PNG图片+ 滚动文字组合的问题。。
当然提问的问题。 用AU3是可以实现的 但实现的时候会出现一些问题。。那就是文字在滚动的时候不停的闪 。 有时连PNG背景图片在在闪。。 郁闷死。。 试了很多办法都没有用。。

发源码给兄弟们看看。

; Special thanks to GaryFrost for updating this to work with AutoIt v3.2.12.0!

#NoTrayIcon
#include <GDIPlus.au3>; this is where the magic happens, people
#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)
$title = "";设置需要显示公告的激活窗口的窗口名
Global Const $AC_SRC_ALPHA = 1
;~ Global Const $ULW_ALPHA         = 2
Global $old_string = "", $runthis = ""
Global $launchDir = @DesktopDir

; Load PNG file as GDI bitmap
_GDIPlus_Startup()
$pngSrc = @ScriptDir & "\LaunchySkin.png"
$hImage = _GDIPlus_ImageLoadFromFile($pngSrc)

; Extract image width and height from PNG
$width = _GDIPlus_ImageGetWidth($hImage)
$height = _GDIPlus_ImageGetHeight($hImage)
        If _soundPos("myMusic") = _soundLength("myMusic") then
            _soundClose("myMusic")
            _soundOpen("daoxiang.mp3", "myMusic")
        EndIf
        _soundPlay("myMusic")
; Create layered window
$GUI = GUICreate("lod3n launcher", $width, $height, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
SetBitmap($GUI, $hImage, 0)
; Register notification messages
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
GUISetState()
WinSetOnTop($GUI, "", 1)
;fade in png background
For $i = 0 To 255 Step 10
    SetBitmap($GUI, $hImage, $i)
Next


; create child MDI gui window to hold controls
; this part could use some work - there is some flicker sometimes...
$controlGui = GUICreate("ControlGUI", $width, $height, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $GUI)

; child window transparency is required to accomplish the full effect, so $WS_EX_LAYERED above, and
; I think the way this works is the transparent window color is based on the image you set here:
GUICtrlCreatePic(@ScriptDir & "\grey.gif", 0, 0, $width, $height)
GUICtrlSetState(-1, $GUI_DISABLE)

; just a text label
;GUICtrlCreateLabel("正在播放 周杰伦-稻香", 50,20, 120, 50)

$neirong2 = "正在播放 周杰伦-稻香";定义neirong2为公告内容2
$Label1 = GUICtrlCreateLabel($neirong2, 50,300, 120, 30);需要移动的控件

GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1, 0xFFFFFF)


GUICtrlSetCursor (-1, 0)
_ReduceMemory(@AutoItPID);释放内存
GUISetState()
_ReduceMemory(@AutoItPID);释放内存
$num = 0;这个数控制公告滚动的时间
$b = 1;这个数控制滚动的距离

While $num <= 600
        If $b = 650 Then $b = 1
        Sleep(15);控制刷新速度
        If WinActive($title) = 1 Then
                ControlMove("ControlGUI", "", $Label1, 580 - $b, 30)
                $b += 1;检测指定窗口是否激活,如果激活则 b 函数自加
        Else
                WinSetState("ControlGUI", "", @SW_HIDE);指定窗口未激活时,隐藏公告栏
                WinWaitActive($title);等待指定窗口被激活
                WinSetState("ControlGUI", "", @SW_SHOW);指定窗口激活后,显示公告栏
        EndIf
        If $b=650 Then _ReduceMemory(@AutoItPID);释放内存
        $num = $num + 1
        WEnd
       
       
;While 1
;   $msg = GUIGetMsg()
  ;  Select
   ;     Case $msg = $GUI_EVENT_CLOSE
    ;        ExitLoop
      
    ;EndSelect
;WEnd





GUIDelete($controlGui)
;fade out png background
For $i = 255 To 0 Step -10
    SetBitmap($GUI, $hImage, $i)
Next

; Release resources
_WinAPI_DeleteObject($hImage)
_GDIPlus_Shutdown()



Func GoAutoComplete()
    _GUICtrlComboBox_AutoComplete($Combo)
EndFunc   ;==>GoAutoComplete

; ====================================================================================================

; Handle the WM_NCHITTEST for the layered window so it can be dragged by clicking anywhere on the image.
; ====================================================================================================

Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    If ($hWnd = $GUI) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc   ;==>WM_NCHITTEST

; ====================================================================================================

; SetBitMap
; ====================================================================================================

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   ;==>SetBitmap


; I don't like AutoIt's built in ShellExec. I'd rather do the DLL call myself.
Func _ShellExecute($sCmd, $sArg = "", $sFolder = "", $rState = @SW_SHOWNORMAL)
    $aRet = DllCall("shell32.dll", "long", "ShellExecute", _
            "hwnd", 0, _
            "string", "", _
            "string", $sCmd, _
            "string", $sArg, _
            "string", $sFolder, _
            "int", $rState)
    If @error Then Return 0

    $RetVal = $aRet[0]
    If $RetVal > 32 Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc   ;==>_ShellExecute




Func _ReduceMemory($i_PID = -1);内存释放函数
        If $i_PID <> -1 Then
                Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
                Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
                DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
        Else
                Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
        EndIf

        Return $ai_Return[0]
        EndFunc   ;==>_ReduceMemory

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2009-5-17 15:58:22 | 显示全部楼层
对此问题感兴趣,也有类似迷惑
谁来解答下
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-12-25 13:46 , Processed in 0.079345 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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