本帖最后由 蜘蛛抱蛋 于 2011-3-9 16:49 编辑
目的是解决这篇帖子提到的闪烁问题。这是官网上找到的一段代码
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#Include <GDIPlus.au3>
#include <WinAPI.au3>
Global $sFile = @ScriptDir & "\Splash.png"
Global $hGui, $iW, $iH, $hBmp
_GDIPlus_Startup()
$hImage1 = _GDIPlus_ImageLoadFromFile($sFile)
$iW = _GDIPlus_ImageGetWidth($hImage1)
$iH = _GDIPlus_ImageGetHeight($hImage1)
$hGUI = GUICreate("", $iW, $iH, -1, -1, $WS_POPUP, BitOr($WS_EX_LAYERED, $WS_EX_TOPMOST))
GUISetState()
;Add the text to a new image
$hBmp = _ImageDrawText($hImage1, "Text drawn on image", 100, 200, 0xFFFFFF)
;fade in png image
For $i = 0 To 255 Step 1
SetBitmap($hGUI, $hBmp, $i)
Next
;Finished with the new text written image delete it
_WinAPI_DeleteObject($hBmp)
Sleep(2000)
;Since the original png is still open lets dribble some more text..
$hBmp = _ImageDrawText($hImage1, "Once upon a time....", 0, 0, 0xFF0000, 16, 2, "Impact")
SetBitmap($hGUI, $hBmp, 255)
_WinAPI_DeleteObject($hBmp)
Sleep(2000)
$hBmp = _ImageDrawText($hImage1, "Long long ago....", 0, 60, 0x00FF00, 16, 1, "Tahoma")
SetBitmap($hGUI, $hBmp, 255)
_WinAPI_DeleteObject($hBmp)
Sleep(2000)
$hBmp = _ImageDrawText($hImage1, "When I was young and in my prime....", 0, 80, 0x0000FF, 9, 3, "Arial")
SetBitmap($hGUI, $hBmp, 255)
_WinAPI_DeleteObject($hBmp)
Sleep(2000)
$hBmp = _ImageDrawText($hImage1, "Wait....", 60, 120, 0x00FFFF, 20, 0, "Arial")
SetBitmap($hGUI, $hBmp, 255)
_WinAPI_DeleteObject($hBmp)
Sleep(2000)
$hBmp = _ImageDrawText($hImage1, "Scratch that part....", 20, 130, 0x00FF00, 12, 8, "Comic Sans MS")
SetBitmap($hGUI, $hBmp, 255)
_WinAPI_DeleteObject($hBmp)
Sleep(2000)
$hBmp = _ImageDrawText($hImage1, "To Be Continued...." & @LF & "NOT!", 50, 160, 0xFFFF00, 12, 4, "Impact")
SetBitmap($hGUI, $hBmp, 255)
_WinAPI_DeleteObject($hBmp)
Sleep(2000)
;set the original non texted png image back to the window
SetBitmap($hGUI, $hImage1, 255)
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE, $GUI_EVENT_PRIMARYDOWN, $GUI_EVENT_PRIMARYUP
_GDIPlus_ImageDispose($hImage1)
_GDIPlus_Shutdown()
Exit
EndSwitch
Wend
; $hImage = The handle to your open image file
; $sText = Sting of text to draw on the picture
; $iX = X postion the text will be drawn at
; $iY = Y position the text will be drawn at
; $iRGB = the RGB color to draw the text (0x000000 to 0xffffff)
; $iSize = The size of the font
; $iStyle = 0 None (Default)
; 1 Bold
; 2 Italic
; 4 Underline
; 8 Strikethrough
; (Add together for combination, eg: 3 = Bold + Italic)
; $sFont = Name of font to use
Func _ImageDrawText($hImage, $sText, $iX = 0, $iY = 0, $iRGB = 0x000000, $iSize = 9, $iStyle = 0, $sFont = "Arial")
Local $w, $h, $hGraphic1, $hBitmap, $hGraphic2, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $aInfo
$w = _GDIPlus_ImageGetWidth($hImage)
$h = _GDIPlus_ImageGetHeight($hImage)
;Create a new bitmap, this way the original opened png is left unchanged
$hGraphic1 = _GDIPlus_GraphicsCreateFromHWND(_WinAPI_GetDesktopWindow())
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($w, $h, $hGraphic1)
$hGraphic2 = _GDIPlus_ImageGetGraphicsContext($hBitmap)
; Draw the original opened png into my newly created bitmap
_GDIPlus_GraphicsDrawImageRect($hGraphic2, $hImage, 0, 0, $w, $h)
;Create the font
$hBrush = _GDIPlus_BrushCreateSolid ("0xFF" & Hex($iRGB, 6))
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate ($sFont)
$hFont = _GDIPlus_FontCreate ($hFamily, $iSize, $iStyle)
$tLayout = _GDIPlus_RectFCreate ($iX, $iY, 0, 0)
$aInfo = _GDIPlus_GraphicsMeasureString ($hGraphic2, $sText, $hFont, $tLayout, $hFormat)
;Draw the font onto the new bitmap
_GDIPlus_GraphicsDrawStringEx ($hGraphic2, $sText, $hFont, $aInfo[0], $hFormat, $hBrush)
;Cleanup the no longer needed resources
_GDIPlus_FontDispose ($hFont)
_GDIPlus_FontFamilyDispose ($hFamily)
_GDIPlus_StringFormatDispose ($hFormat)
_GDIPlus_BrushDispose ($hBrush)
_GDIPlus_GraphicsDispose ($hGraphic2)
_GDIPlus_GraphicsDispose ($hGraphic1)
;Return the new bitmap
Return $hBitmap
EndFunc
Func SetBitmap($hGUI, $hImage, $iOpacity)
Local Const $AC_SRC_ALPHA = 1
Local Const $ULW_ALPHA = 2
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
各位有更巧的办法吗?
========================
算了,大家别回复了,关帖 |