找回密码
 加入
搜索
查看: 4876|回复: 4

[GUI管理] 如何在屏幕中显示一张PNG透明图片【GDI相关】

  [复制链接]
发表于 2010-11-9 16:08:13 | 显示全部楼层 |阅读模式
悬赏30金钱已解决
本帖最后由 tryhi 于 2010-11-9 16:26 编辑

有点类似于此贴http://www.autoitx.com/forum.php ... 2&highlight=png,看不到窗口出现,仅仅在在屏幕上显示一张图片,此贴的源码看了几天仍无所获,源码实在太长不懂筛选。
#include <GDIPlus.au3>
#include <WinAPI.au3>
_GDIPlus_Startup()
$NormalImage = _GDIPlus_ImageLoadFromFile("normal.png");新建图像文件的句柄
$GC = _GDIPlus_ImageGetGraphicsContext($NormalImage)
$newBmp = _GDIPlus_BitmapCreateFromGraphics(118, 53, $GC)
$newGC = _GDIPlus_ImageGetGraphicsContext($newBmp)
_GDIPlus_GraphicsDrawImageRect($newGC, $NormalImage, 0, 0, 118, 53)
While 1
        Sleep(100)
WEnd
为何以上代码不会显示出normal.png图片呢

最佳答案

查看完整内容

[au3]#include #include #include Global Const $AC_SRC_ALPHA = 1 _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile("normal.png") $width = _GDIPlus_ImageGetWidth($hImage) $height = _GDIPlus_ImageGetHeight($hImage) $gui = GUICreate("", $width, $height, -1, -1, $WS_POPUP, $WS_EX_LAYERED, GUICreate("")) SetBitmap($gui, $hImage, 255) GUISetState() WinSetOnTop($gui, "", 1) Sleep(10000) Func SetB ...

评分

参与人数 1金钱 +90 贡献 +20 收起 理由
漫反射 + 90 + 20

查看全部评分

发表于 2010-11-9 16:08:14 | 显示全部楼层
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
Global Const $AC_SRC_ALPHA = 1
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile("normal.png")
$width = _GDIPlus_ImageGetWidth($hImage)
$height = _GDIPlus_ImageGetHeight($hImage)
$gui = GUICreate("", $width, $height, -1, -1, $WS_POPUP, $WS_EX_LAYERED, GUICreate(""))
SetBitmap($gui, $hImage, 255)
GUISetState()
WinSetOnTop($gui, "", 1)
Sleep(10000)

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

评分

参与人数 3金钱 +80 贡献 +5 收起 理由
沐月狐 + 20 搜了好久才在这里学到了
anythinging + 30
tryhi + 30 + 5 多谢

查看全部评分

发表于 2010-11-10 00:40:25 | 显示全部楼层
看看这贴,应该自己能搞定 http://www.autoitx.com/forum.php?mod=viewthread&tid=13262
简单的说,就是先
_GDIPlus_Startup()
然后 GUICreate("png gui", $width, $height, -1, -1, $WS_POPUP, $WS_EX_LAYERED) ;创建一个透明的窗口
然后用上贴中包含的一个函数 SetBitmap() 加载png图片即可

评分

参与人数 1金钱 +24 贡献 +2 收起 理由
tryhi + 24 + 2 多谢指点

查看全部评分

发表于 2010-11-10 10:49:12 | 显示全部楼层
本帖最后由 gapkiller 于 2010-11-10 11:12 编辑


#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#Include <WinAPI.au3>

Global $hGUI, $hImage, $hGraphic, $hImage1

; Create GUI
$hGUI = GUICreate("Show PNG", 250, 250)

; Load PNG image
_GDIPlus_StartUp()
$hImage   = _GDIPlus_ImageLoadFromFile("normal.png")
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)

GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
GUISetState()

; Loop until user exits
do
until GUIGetMsg() = $GUI_EVENT_CLOSE

; Clean up resources
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_ShutDown()

; Draw PNG image
Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
    Return $GUI_RUNDEFMSG
EndFunc

评分

参与人数 1金钱 +20 贡献 +1 收起 理由
tryhi + 20 + 1 可惜效果不是我要的

查看全部评分

发表于 2010-11-10 13:09:51 | 显示全部楼层
借用楼上的代码表述下,但鼠标穿透是个大问题。
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#Include <WinAPI.au3>
 
Global $hGUI, $hImage, $hGraphic, $hImage1
 
; Create GUI
$hGUI = GUICreate("Show PNG", 250, 250,100,200,$WS_POPUP, BitOR($WS_EX_LAYERED,$WS_EX_TOPMOST))
 GUIctrlSetBkColor(-1,0xABCDEF)
; Load PNG image
_GDIPlus_StartUp()
$hImage   = _GDIPlus_ImageLoadFromFile("normal.png")
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)

_WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF, 200)
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
GUISetState()
 
; Loop until user exits
do
        
until GUIGetMsg() = $GUI_EVENT_CLOSE
 
; Clean up resources
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_ShutDown()
 
; Draw PNG image
Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
    Return $GUI_RUNDEFMSG
EndFunc

评分

参与人数 1贡献 +2 收起 理由
tryhi + 2 非常感谢关注,真的

查看全部评分

您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-12-23 19:06 , Processed in 0.078120 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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