找回密码
 加入
搜索
查看: 5343|回复: 8

[图形处理] 请问图标按钮点击识别混乱如何处理?[已解决]

  [复制链接]
发表于 2013-2-6 21:34:07 | 显示全部楼层 |阅读模式
本帖最后由 chishingchan 于 2013-2-8 18:56 编辑
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>
#include <GuiImageList.au3>

Local $btn1Text, $btn1, $btn2Text, $btn2, $btn3Text, $btn3

GUICreate("软件安装器", 400, 400)
$hImage = _GUIImageList_Create(32, 32, 5, 3, 6)
_GUIImageList_AddIcon($hImage, "2345_k503106_haozip.exe", 0, True)
$btn1 = GUICtrlCreateButton("", 0, 0, 40, 40)
_GUICtrlButton_SetImageList($btn1, _GetImageListHandle("2345_k503106_haozip.exe", 0, True), 4)

_GUIImageList_AddIcon($hImage, "2345_k503106_haozip.exe", 0, True)
$btn2 = GUICtrlCreateButton("", 40, 0, 40, 40)
_GUICtrlButton_SetImageList($btn2, _GetImageListHandle("2345_k503106_haozip.exe", 0, True), 4)

_GUIImageList_AddIcon($hImage, "2345_k503106_haozip.exe", 0, True)
$btn3 = GUICtrlCreateButton("", 80, 0, 40, 40)
_GUICtrlButton_SetImageList($btn3, _GetImageListHandle("2345_k503106_haozip.exe", 0, True), 4)

GUISetState()

GUICtrlSetTip($btn1, "好压")
GUICtrlSetTip($btn2, "好压")
GUICtrlSetTip($btn3, "好压")

While 1
        Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                        ExitLoop
                Case $btn1
                        $btn1Text = _GUICtrlButton_GetText($btn1)
                        If $btn1Text = "安装" Then
                                _GUICtrlButton_SetText($btn1, "")
                                _GUICtrlButton_SetState($btn1)
                        EndIf
                        If $btn1Text = "" Then _GUICtrlButton_SetText($btn1, "安装")
                Case $btn2
                        $btn2Text = _GUICtrlButton_GetText($btn2)
                        If $btn2Text = "安装" Then
                                _GUICtrlButton_SetText($btn2, "")
                                _GUICtrlButton_SetState($btn2)
                        EndIf
                        If $btn2Text = "" Then _GUICtrlButton_SetText($btn2, "安装")
                Case $btn3
                        $btn3Text = _GUICtrlButton_GetText($btn3)
                        If $btn3Text = "安装" Then
                                _GUICtrlButton_SetText($btn3, "")
                                _GUICtrlButton_SetState($btn3)
                        EndIf
                        If $btn3Text = "" Then _GUICtrlButton_SetText($btn3, "安装")
        EndSwitch
WEnd

; 使用图像列表在按钮上设置一个图像并显示文本
Func _GetImageListHandle($sFile, $nIconID = 0, $fLarge = False)
        Local $iSize = 16
        If $fLarge Then $iSize = 32
        Local $hImage = _GUIImageList_Create($iSize, $iSize, 5, 3)
        If StringUpper(StringMid($sFile, StringLen($sFile) - 2)) = "BMP" Then
                _GUIImageList_AddBitmap($hImage, $sFile)
        Else
                _GUIImageList_AddIcon($hImage, $sFile, $nIconID, $fLarge)
        EndIf
        Return $hImage
EndFunc   ;==>_GetImageListHandle
目的:本人想制作一款软件自动安装器,过程中点击某个图标按钮显示安装,再点击即不显示安装。请问以上代码如何修正?谢谢!
 楼主| 发表于 2013-2-6 21:39:39 | 显示全部楼层

本帖子中包含更多资源

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

×
 楼主| 发表于 2013-2-7 19:41:16 | 显示全部楼层
没朋友愿意帮个忙吗?
发表于 2013-2-7 19:59:09 | 显示全部楼层
设个标记变量,初值=0,第一次点击后,设置=1,再次点击判断这个变量值,如果=1,则表示当前是再次点击
 楼主| 发表于 2013-2-8 08:28:55 | 显示全部楼层
回复 4# 131738


    帮人帮到底,送佛送到西!请帮忙修改源码,谢谢!
 楼主| 发表于 2013-2-8 13:27:25 | 显示全部楼层
以下代码解决了按钮文字混乱的情况,但是Case语句里用不了For语句循环,否则出现按钮文字迟钝感觉。但是如果按钮太多会觉得代码冗长,该怎么办?
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>
#include <GuiImageList.au3>

Local $btn[4], $btnText[4], $btnTF[4]

GUICreate("软件安装器", 400, 400)
$hImage = _GUIImageList_Create(32, 32, 5, 3, 6)
_GUIImageList_AddIcon($hImage, "2345_k503106_haozip.exe", 0, True)
$btn[1] = GUICtrlCreateButton("", 0, 0, 40, 40)
_GUICtrlButton_SetImageList($btn[1], _GetImageListHandle("2345_k503106_haozip.exe", 0, True), 4)

_GUIImageList_AddIcon($hImage, "2345_k503106_haozip.exe", 0, True)
$btn[2] = GUICtrlCreateButton("", 40, 0, 40, 40)
_GUICtrlButton_SetImageList($btn[2], _GetImageListHandle("2345_k503106_haozip.exe", 0, True), 4)

_GUIImageList_AddIcon($hImage, "2345_k503106_haozip.exe", 0, True)
$btn[3] = GUICtrlCreateButton("", 80, 0, 40, 40)
_GUICtrlButton_SetImageList($btn[3], _GetImageListHandle("2345_k503106_haozip.exe", 0, True), 4)

GUISetState()

GUICtrlSetTip($btn[1], "好压")
GUICtrlSetTip($btn[2], "好压")
GUICtrlSetTip($btn[3], "好压")

While 1
        Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                                ExitLoop
                Case $btn[1]
                        If $btnTF[1] = False Then
                                $btnTF[1] = True
                                _GUICtrlButton_SetText($btn[1], "安装")
                        Else
                                $btnTF[1] = False
                                _GUICtrlButton_SetText($btn[1], "")
                        EndIf
                Case $btn[2]
                        If $btnTF[2] = False Then
                                $btnTF[2] = True
                                _GUICtrlButton_SetText($btn[2], "安装")
                        Else
                                $btnTF[2] = False
                                _GUICtrlButton_SetText($btn[2], "")
                        EndIf
                Case $btn[3]
                        If $btnTF[3] = False Then
                                $btnTF[3] = True
                                _GUICtrlButton_SetText($btn[3], "安装")
                        Else
                                $btnTF[3] = False
                                _GUICtrlButton_SetText($btn[3], "")
                        EndIf
        EndSwitch
WEnd

; 使用图像列表在按钮上设置一个图像并显示文本
Func _GetImageListHandle($sFile, $nIconID = 0, $fLarge = False)
        Local $iSize = 16
        If $fLarge Then $iSize = 32
        Local $hImage = _GUIImageList_Create($iSize, $iSize, 5, 3)
        If StringUpper(StringMid($sFile, StringLen($sFile) - 2)) = "BMP" Then
                _GUIImageList_AddBitmap($hImage, $sFile)
        Else
                _GUIImageList_AddIcon($hImage, $sFile, $nIconID, $fLarge)
        EndIf
        Return $hImage
EndFunc   ;==>_GetImageListHandle
发表于 2013-2-10 22:51:47 | 显示全部楼层
学习了!!!!!
发表于 2017-5-25 10:30:02 | 显示全部楼层
谢谢楼主分享
发表于 2017-7-23 12:12:34 | 显示全部楼层
学习了!!!!!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-26 04:27 , Processed in 0.086361 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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