找回密码
 加入
搜索
查看: 4300|回复: 7

[图形处理] 图标替换不支持GIF 和 PNG(已解决)

  [复制链接]
发表于 2012-6-4 16:44:57 | 显示全部楼层 |阅读模式
本帖最后由 iori2882 于 2012-6-4 17:26 编辑

用系统自带的函数只支持ICO格式
GUICtrlSetImage(-1,"1.ico")

   论坛的几位会员发的替换图标的代码好像支持BMP或JPG的,就是没有支持GIF或PNG的,好像只有GIF或PNG的支持通明背景,其他的都不行


   第一个图标是用BMP的 后面白了一块,第二个是用ICO格式的 第三个是默认图标 有没有能支持GIF或PNG的换图标代码呢?

本帖子中包含更多资源

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

×
发表于 2012-6-4 16:49:34 | 显示全部楼层
3m曾经发过PNG的,你搜下论坛。
3mile

评分

参与人数 1金钱 +30 贡献 +2 收起 理由
iori2882 + 30 + 2

查看全部评分

 楼主| 发表于 2012-6-4 16:58:37 | 显示全部楼层
3m曾经发过PNG的,你搜下论坛。
3mile
haijie1223 发表于 2012-6-4 16:49


恩 找到了 ,3mile兄弟 还没放源码呢!!!!!!!
发表于 2012-6-4 17:11:45 | 显示全部楼层
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <ButtonConstants.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>
#include <EditConstants.au3>
#include <ListViewConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("控件变化测试", 392, 265)
GUISetBkColor(0x000000)
$Button1 = GUICtrlCreateButton("显示图片", 8, 24, 40, 35)
$Button2 = GUICtrlCreateButton("显示图片", 8, 70, 40, 35)
$Button3 = GUICtrlCreateButton("显示编辑", 8, 115, 40, 35)
$Button4 = GUICtrlCreateButton("隐藏控件", 8, 161, 40, 35)
$Button5 = GUICtrlCreateButton("退出测试", 8, 207, 40, 35)
$Pic1 = GUICtrlCreatePic("F:\图片\2.jpg", 110, 24, 260, 220)
GUICtrlSetPos($Pic1, 110,24,260,20)
$Pic2 = GUICtrlCreatePic("F:\图片\11.jpg", 110, 24, 260, 220)
_ControlChange($Form1, $Pic2, 1, 100,5)
$Edit1 = GUICtrlCreateEdit("文本编辑框", 110, 24, 135, 217)
GUICtrlSetPos($Edit1, 110,24,1,217)
GUICtrlSetState($Pic1,$GUI_HIDE)
GUICtrlSetState($Pic2,$GUI_HIDE)
GUICtrlSetState($Edit1,$GUI_HIDE)
_GUICtrlButton_SetImageList($Button1, _Ico(165, True))
_GUICtrlButton_SetImageList($Button2, _Ico(166, True))
_GUICtrlButton_SetImageList($Button3, _Ico(134, True))
_GUICtrlButton_SetImageList($Button4, _Ico(146, True))
_GUICtrlButton_SetImageList($Button5, _Ico(217, True))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
        $nMsg = GUIGetMsg()
        $mous = GUIGetCursorInfo($Form1)
        If $nMsg = $GUI_EVENT_CLOSE Then
                Exit        
        ElseIf $mous[4] = $Button1 Then                
                _ControlChange($Form1, $Button1, 0, 30, 3, 0, 0, 1, 0)
                While $mous[4] = $Button1
                        If GUIGetMsg() = $Button1 Then 
                                If GUICtrlGetState($Pic2)<>96 Then
                                        _ControlChange($Form1, $Pic2, 1, 100,5)
                                        GUICtrlSetState($Pic2,$GUI_HIDE)
                                EndIf
                                If GUICtrlGetState($Edit1)<>96 Then
                                        _ControlChange($Form1, $Edit1, 1, 135,5,0,0,1,0)
                                        GUICtrlSetState($Edit1,$GUI_HIDE)
                                EndIf
                                If GUICtrlGetState($Pic1)=96 Then
                                        GUICtrlSetState($Pic1,$GUI_SHOW)
                                        _ControlChange($Form1, $Pic1, 0, 100,5,0,0,0)
                                ElseIf GUICtrlGetState($Pic1)<>96 Then
                                        _ControlChange($Form1, $Pic1, 1, 100,5,0,0,0)
                                        GUICtrlSetState($Pic1,$GUI_HIDE)
                                EndIf
                        EndIf
                        $mous = GUIGetCursorInfo($Form1)
                WEnd
                _ControlChange($Form1, $Button1, 1, 30, 3, 0, 0, 1, 0)
        ElseIf $mous[4] = $Button2 Then
                _ControlChange($Form1, $Button2, 0, 30, 3, 0, 0, 1, 0)                
                While $mous[4] = $Button2
                        If GUIGetMsg() = $Button2 Then 
                                If GUICtrlGetState($Pic1)<>96 Then
                                        _ControlChange($Form1, $Pic1, 1, 100,5,0,0,0)
                                        GUICtrlSetState($Pic1,$GUI_HIDE)
                                EndIf
                                If GUICtrlGetState($Edit1)<>96 Then
                                        _ControlChange($Form1, $Edit1, 1, 135,5,0,0,1,0)
                                        GUICtrlSetState($Edit1,$GUI_HIDE)
                                EndIf
                                If GUICtrlGetState($Pic2)=96 Then
                                        GUICtrlSetState($Pic2,$GUI_SHOW)
                                        _ControlChange($Form1, $Pic2, 0, 100,5)
                                ElseIf GUICtrlGetState($Pic2)<>96 Then
                                        _ControlChange($Form1, $Pic2, 1, 100,5)
                                        GUICtrlSetState($Pic2,$GUI_HIDE)
                                EndIf                                
                        EndIf
                        $mous = GUIGetCursorInfo($Form1)
                WEnd
                _ControlChange($Form1, $Button2, 1, 30, 3, 0, 0, 1, 0)
        ElseIf $mous[4] = $Button3 Then
                _ControlChange($Form1, $Button3, 0, 30, 3, 0, 0, 1, 0)                
                While $mous[4] = $Button3
                        If GUIGetMsg() = $Button3 Then 
                                If GUICtrlGetState($Pic1)<>96 Then
                                        _ControlChange($Form1, $Pic1, 1, 100,5,0,0,0)
                                        GUICtrlSetState($Pic1,$GUI_HIDE)
                                EndIf
                                If GUICtrlGetState($Pic2)<>96 Then
                                        _ControlChange($Form1, $Pic2, 1, 100,5)
                                        GUICtrlSetState($Pic2,$GUI_HIDE)
                                EndIf
                                If GUICtrlGetState($Edit1)=96 Then
                                        GUICtrlSetState($Edit1,$GUI_SHOW)
                                        _ControlChange($Form1, $Edit1, 0, 135,5,0,0,1,0)
                                ElseIf GUICtrlGetState($Edit1)<>96 Then
                                        _ControlChange($Form1, $Edit1, 1, 135,5,0,0,1,0)
                                        GUICtrlSetState($Edit1,$GUI_HIDE)
                                EndIf
                        EndIf
                        $mous = GUIGetCursorInfo($Form1)
                WEnd
                _ControlChange($Form1, $Button3, 1, 30, 3, 0, 0, 1, 0)        
        ElseIf $mous[4] = $Button4 Then
                _ControlChange($Form1, $Button4, 0, 30, 3, 0, 0, 1, 0)                
                While $mous[4] = $Button4
                        If GUIGetMsg() = $Button4 Then 
                                If GUICtrlGetState($Pic1)<>96 Then
                                        GUICtrlSetState($Pic1,$GUI_HIDE)
                                        _ControlChange($Form1, $Pic1, 1, 100,5,0,0,0)                                        
                                EndIf
                                If GUICtrlGetState($Pic2)<>96 Then
                                        GUICtrlSetState($Pic2,$GUI_HIDE)
                                        _ControlChange($Form1, $Pic2, 1, 100,5)                                        
                                EndIf
                                If GUICtrlGetState($Edit1)<>96 Then
                                        GUICtrlSetState($Edit1,$GUI_HIDE)
                                        _ControlChange($Form1, $Edit1, 1, 135,5,0,0,1,0)
                                EndIf
                        EndIf
                        $mous = GUIGetCursorInfo($Form1)
                WEnd
                _ControlChange($Form1, $Button4, 1, 30, 3, 0, 0, 1, 0)        
        ElseIf $mous[4] = $Button5 Then
                _ControlChange($Form1, $Button5, 0, 30, 3, 0, 0, 1, 0)                
                While $mous[4] = $Button5
                        If GUIGetMsg() = $Button5 Then Exit
                        $mous = GUIGetCursorInfo($Form1)
                WEnd
                _ControlChange($Form1, $Button5, 1, 30, 3, 0, 0, 1, 0)        
        EndIf
WEnd

Func _Ico($nIconID = 0, $fLarge = False, $sFile = "shell32.dll")
        Local $iSize = 16
        If $fLarge Then $iSize = 32

        Local $hImagetem = _GUIImageList_Create($iSize, $iSize, 5, 3)
        If StringUpper(StringMid($sFile, StringLen($sFile) - 2)) = "BMP" Then
                _GUIImageList_AddBitmap($hImagetem, $sFile)
        Else
                _GUIImageList_AddIcon($hImagetem, $sFile, $nIconID, $fLarge)
        EndIf
        Return $hImagetem
EndFunc   ;==>_Ico

Func _ControlChange($FormID, $controlID, $iStup = 0, $iMax = 10, $iStep = 2, $iXs = 1, $iYs = 1, $iWs = 1, $iHs = 1)
;~         控件变化动画效果
;~         _ControlChange (窗口标题/ID, 控件ID, 变化设置 0变大否则变小, 变化大小, 变化速度, X坐标变化, Y坐标变化,宽度变化,高度变化)
        $iPos = ControlGetPos($FormID, "", $controlID)
        $iX = $iPos[0]
        $iY = $iPos[1]
        $iW = $iPos[2]
        $iH = $iPos[3]
        If $iStup = 0 Then
                $iS1 = 1
                $iS2 = 1
        Else
                $iS1 = -1
                $iS2 = -1
        EndIf
        Dim $iXt = $iX, $iYt = $iY, $iWt = $iW, $iHt = $iH
        For $i = 1 To $iMax Step $iStep
                If $iXs = 1 Then $iXt = Execute($iX - $iS1 * $i)
                If $iYs = 1 Then $iYt = Execute($iY - $iS1 * $i)
                If $iWs = 1 Then $iWt = Execute($iW + $iS2 * 2 * $i)
                If $iHs = 1 Then $iHt = Execute($iH + $iS2 * 2 * $i)
                GUICtrlSetPos($controlID, $iXt, $iYt, $iWt, $iHt)
                Sleep(1)
        Next
EndFunc   
发表于 2012-6-4 17:13:11 | 显示全部楼层

#include "Icons.au3"
GUICreate("PNGTest", 300, 400)
$BUTTON = GUICtrlCreatePic("", 10, 10, 100, 100)
_SetImage($BUTTON, @ScriptDir & "\qq.png")
GUISetState()

While 1
        Switch GUIGetMsg()
                Case -3
                        Exit
        EndSwitch
WEnd

帮你找了个UDF,研究一下吧。png图片没有准备,自己找个测试吧。

本帖子中包含更多资源

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

×
发表于 2012-6-4 17:24:15 | 显示全部楼层
别人也有例子,多搜索论坛:
http://www.autoitx.com/forum.php ... 6&highlight=PNG
 楼主| 发表于 2012-6-4 17:26:23 | 显示全部楼层
别人也有例子,多搜索论坛:
haijie1223 发表于 2012-6-4 17:24


恩 搜索到了 谢谢你,我也找到了你发的一个例子,但是看不懂,那是我个人原因了,结贴了....
发表于 2012-6-4 20:21:09 | 显示全部楼层
回复 2# haijie1223


    发哥真厉害,随便说一句都有人给你加WW。!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-17 12:09 , Processed in 0.090703 second(s), 29 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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