请问图标按钮点击识别混乱如何处理?[已解决]
本帖最后由 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
目的:本人想制作一款软件自动安装器,过程中点击某个图标按钮显示安装,再点击即不显示安装。请问以上代码如何修正?谢谢! 没朋友愿意帮个忙吗? 设个标记变量,初值=0,第一次点击后,设置=1,再次点击判断这个变量值,如果=1,则表示当前是再次点击 回复 4# 131738
帮人帮到底,送佛送到西!请帮忙修改源码,谢谢! 以下代码解决了按钮文字混乱的情况,但是Case语句里用不了For语句循环,否则出现按钮文字迟钝感觉。但是如果按钮太多会觉得代码冗长,该怎么办?#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>
#include <GuiImageList.au3>
Local $btn, $btnText, $btnTF
GUICreate("软件安装器", 400, 400)
$hImage = _GUIImageList_Create(32, 32, 5, 3, 6)
_GUIImageList_AddIcon($hImage, "2345_k503106_haozip.exe", 0, True)
$btn = GUICtrlCreateButton("", 0, 0, 40, 40)
_GUICtrlButton_SetImageList($btn, _GetImageListHandle("2345_k503106_haozip.exe", 0, True), 4)
_GUIImageList_AddIcon($hImage, "2345_k503106_haozip.exe", 0, True)
$btn = GUICtrlCreateButton("", 40, 0, 40, 40)
_GUICtrlButton_SetImageList($btn, _GetImageListHandle("2345_k503106_haozip.exe", 0, True), 4)
_GUIImageList_AddIcon($hImage, "2345_k503106_haozip.exe", 0, True)
$btn = GUICtrlCreateButton("", 80, 0, 40, 40)
_GUICtrlButton_SetImageList($btn, _GetImageListHandle("2345_k503106_haozip.exe", 0, True), 4)
GUISetState()
GUICtrlSetTip($btn, "好压")
GUICtrlSetTip($btn, "好压")
GUICtrlSetTip($btn, "好压")
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $btn
If $btnTF = False Then
$btnTF = True
_GUICtrlButton_SetText($btn, "安装")
Else
$btnTF = False
_GUICtrlButton_SetText($btn, "")
EndIf
Case $btn
If $btnTF = False Then
$btnTF = True
_GUICtrlButton_SetText($btn, "安装")
Else
$btnTF = False
_GUICtrlButton_SetText($btn, "")
EndIf
Case $btn
If $btnTF = False Then
$btnTF = True
_GUICtrlButton_SetText($btn, "安装")
Else
$btnTF = False
_GUICtrlButton_SetText($btn, "")
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 学习了!!!!! 谢谢楼主分享 学习了!!!!!
页:
[1]