qq342252004
发表于 2011-2-10 08:07:08
本帖最后由 qq342252004 于 2011-2-10 09:59 编辑
有点乱
将就用一下巴
xxoojoeooxx 发表于 2011-2-9 23:40 http://www.autoitx.com/images/common/back.gif
还有个问题,如何响应按钮?
将就着用,希望以后有更完美的解决方法。
haijie1223
发表于 2011-2-10 11:20:34
都是高手看到眼花为止
lhylm
发表于 2011-2-10 12:38:25
回复 9# 水木子
老大,你提供的代码不能实现普通状态和鼠标悬停状态!!!!
lhylm
发表于 2011-2-10 12:48:03
回复 15# xxoojoeooxx
我感觉很复杂啊,简单点就好!!几个按钮就这么过代码...
nicel
发表于 2011-2-10 13:14:28
新手来学学的
xxoojoeooxx
发表于 2011-2-10 19:23:50
回复 16# qq342252004
41行
If $Pos=1 Then
;假如说按下也要换图改这
;_GDIPLus_GraphicsDrawImageRect($Pic, $hImage1, $P[$i], $P[$i], $P[$i], $P[$i])
;_GDIPlus_GraphicsDrawString($Pic,$P[$i],$P[$i]+$P[$i], $P[$i]+$P[$i])
$P[$i] = 1
;按钮按下响应动作
;加这
Else
_GDIPLus_GraphicsDrawImageRect($Pic, $hImage1, $P[$i], $P[$i], $P[$i], $P[$i])
_GDIPlus_GraphicsDrawString($Pic,$P[$i],$P[$i]+$P[$i], $P[$i]+$P[$i])
$P[$i] = 1
Endif
这几行的注解符号删掉
qq342252004
发表于 2011-2-11 10:26:14
#Include <WinAPI.au3>
#Include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $ButtunCount=10 ;按钮数量
Global $P[$ButtunCount+1]
Local $Pi[$ButtunCount]
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
_GDIPlus_StartUp ()
$hImage1 = _GDIPlus_ImageLoadFromFile ("001.png")
$hImage2 = _GDIPlus_ImageLoadFromFile ("002.png")
$hImage3 = _GDIPlus_ImageLoadFromFile ("003.png")
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 450, 450)
;GUICtrlCreatePicB(文本,文本左侧,文本顶部,接下来就是GUICtrlCreatePic原来的参数
$Pi = GUICtrlCreatePicB("1",5,5,"", 16, 24, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("2",5,5,"", 243, 24, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("3",5,5,"", 16, 82, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("4",5,5,"", 243, 82, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("5",5,5,"", 16, 140, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("6",5,5,"", 243, 140, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("7",5,5,"", 16, 198, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("8",5,5,"", 243, 198, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("9",5,5,"", 16, 256, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("0",5,5,"", 243, 256, 180, 36,$WS_CLIPSIBLINGS)
$Pic = _GDIPlus_GraphicsCreateFromHWND ($Form1)
_WinAPI_InvalidateRect(WinGetHandle($Form1))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
$Pos = GUIGetCursorInfo($Form1)
For $i=1 To $P ;$P 为GUICtrlCreatePicB建立按钮的数量 $i为按钮编号
If $Pos = $Pi[$i-1]And $P[$i] = 0 Then
If $Pos=1 Then
;假如说按下也要换图改这
;按下了没有换为$hImage3的图片?
_GDIPLus_GraphicsDrawImageRect($Pic, $hImage3, $P[$i], $P[$i], $P[$i], $P[$i])
_GDIPlus_GraphicsDrawString($Pic,$P[$i],$P[$i]+$P[$i], $P[$i]+$P[$i])
$P[$i] = 1
;按钮按下响应动作
;加这
MsgBox(0,'','按下了没有响应动作?')
Else
_GDIPLus_GraphicsDrawImageRect($Pic, $hImage2, $P[$i], $P[$i], $P[$i], $P[$i])
_GDIPlus_GraphicsDrawString($Pic,$P[$i],$P[$i]+$P[$i], $P[$i]+$P[$i])
$P[$i] = 1
Endif
ElseIf $Pos <> $Pi[$i-1] And $P[$i]= 1 Then
_GDIPLus_GraphicsDrawImageRect($Pic, $hImage1,$P[$i], $P[$i], $P[$i], $P[$i])
_GDIPlus_GraphicsDrawString($Pic,$P[$i],$P[$i]+$P[$i], $P[$i]+$P[$i])
$P[$i] = 0
EndIf
Next
WEnd
_GDIPlus_GraphicsDispose ($Pic)
_GDIPlus_ImageDispose ($hImage1)
_GDIPlus_ImageDispose ($hImage2)
_GDIPlus_ImageDispose ($hImage3)
_GDIPlus_ShutDown ()
Func MY_WM_PAINT($hWnd, $msg, $wParam, $lParam)
_WinAPI_RedrawWindow($Form1, 0, 0, $RDW_UPDATENOW)
For $i=1 To $P
_GDIPLus_GraphicsDrawImageRect($Pic, $hImage1, $P[$i], $P[$i], $P[$i], $P[$i])
_GDIPlus_GraphicsDrawString($Pic,$P[$i],$P[$i]+$P[$i], $P[$i]+$P[$i])
Next
_WinAPI_RedrawWindow($Form1, 0, 0, $RDW_VALIDATE)
Return $GUI_RUNDEFMSG
EndFunc ;==>MY_WM_PAINT
Func GUICtrlCreatePicB($txt,$tx,$ty,$pic,$x,$y,$w=-1,$h=-1,$sy=-1,$ex=-1)
$P+=1 ;按钮数量
$P[$P]=$x ;左侧
$P[$P]=$y ;顶部
$P[$P]=$w ;宽度
$P[$P]=$h ;高度
$P[$P]=0 ;Hover
$P[$P]=$txt ;文本
$P[$P]=$tx ;文本左侧
$P[$P]=$ty ;文本顶部
Return GUICtrlCreatePic($pic,$x,$y,$w,$h,$sy,$ex)
EndFunc
xxoojoeooxx
发表于 2011-2-11 20:47:51
回复 22# qq342252004
判斷的地方出了些問題{:face (396):}
#Include <WinAPI.au3>
#Include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $ButtunCount=10 ;按钮数量
Global $P[$ButtunCount+1]
Local $Pi[$ButtunCount]
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
_GDIPlus_StartUp ()
$hImage1 = _GDIPlus_ImageLoadFromFile ("001.png")
$hImage2 = _GDIPlus_ImageLoadFromFile ("002.png")
$hImage3 = _GDIPlus_ImageLoadFromFile ("003.png")
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 450, 450)
;GUICtrlCreatePicB(文本,文本左侧,文本顶部,接下来就是GUICtrlCreatePic原来的参数
$Pi = GUICtrlCreatePicB("1",5,5,"", 16, 24, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("2",5,5,"", 243, 24, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("3",5,5,"", 16, 82, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("4",5,5,"", 243, 82, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("5",5,5,"", 16, 140, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("6",5,5,"", 243, 140, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("7",5,5,"", 16, 198, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("8",5,5,"", 243, 198, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("9",5,5,"", 16, 256, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("0",5,5,"", 243, 256, 180, 36,$WS_CLIPSIBLINGS)
$Pic = _GDIPlus_GraphicsCreateFromHWND ($Form1)
_WinAPI_InvalidateRect(WinGetHandle($Form1))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
$Pos = GUIGetCursorInfo($Form1)
For $i=1 To $P ;$P 为GUICtrlCreatePicB建立按钮的数量 $i为按钮编号
If $Pos = $Pi[$i-1]Then
If $Pos=1 And $P[$i] <> 2 Then
_GDIPLus_GraphicsDrawImageRect($Pic, $hImage3, $P[$i], $P[$i], $P[$i], $P[$i])
_GDIPlus_GraphicsDrawString($Pic,$P[$i],$P[$i]+$P[$i], $P[$i]+$P[$i])
$P[$i] = 2
MsgBox(0,'','按下了没有响应动作?')
Elseif $Pos=0 And $P[$i] <> 1 Then
_GDIPLus_GraphicsDrawImageRect($Pic, $hImage2, $P[$i], $P[$i], $P[$i], $P[$i])
_GDIPlus_GraphicsDrawString($Pic,$P[$i],$P[$i]+$P[$i], $P[$i]+$P[$i])
$P[$i] = 1
Endif
ElseIf $Pos <> $Pi[$i-1] And $P[$i]= 1 Then
_GDIPLus_GraphicsDrawImageRect($Pic, $hImage1,$P[$i], $P[$i], $P[$i], $P[$i])
_GDIPlus_GraphicsDrawString($Pic,$P[$i],$P[$i]+$P[$i], $P[$i]+$P[$i])
$P[$i] = 0
EndIf
Next
WEnd
_GDIPlus_GraphicsDispose ($Pic)
_GDIPlus_ImageDispose ($hImage1)
_GDIPlus_ImageDispose ($hImage2)
_GDIPlus_ImageDispose ($hImage3)
_GDIPlus_ShutDown ()
Func MY_WM_PAINT($hWnd, $msg, $wParam, $lParam)
_WinAPI_RedrawWindow($Form1, 0, 0, $RDW_UPDATENOW)
For $i=1 To $P
_GDIPLus_GraphicsDrawImageRect($Pic, $hImage1, $P[$i], $P[$i], $P[$i], $P[$i])
_GDIPlus_GraphicsDrawString($Pic,$P[$i],$P[$i]+$P[$i], $P[$i]+$P[$i])
Next
_WinAPI_RedrawWindow($Form1, 0, 0, $RDW_VALIDATE)
Return $GUI_RUNDEFMSG
EndFunc ;==>MY_WM_PAINT
Func GUICtrlCreatePicB($txt,$tx,$ty,$pic,$x,$y,$w=-1,$h=-1,$sy=-1,$ex=-1)
$P+=1 ;按钮数量
$P[$P]=$x ;左侧
$P[$P]=$y ;顶部
$P[$P]=$w ;宽度
$P[$P]=$h ;高度
$P[$P]=0 ;Hover
$P[$P]=$txt ;文本
$P[$P]=$tx ;文本左侧
$P[$P]=$ty ;文本顶部
Return GUICtrlCreatePic($pic,$x,$y,$w,$h,$sy,$ex)
EndFunc
qq342252004
发表于 2011-2-12 09:37:24
回复qq342252004
判斷的地方出了些問題
xxoojoeooxx 发表于 2011-2-11 20:47 http://www.autoitx.com/images/common/back.gif
如何读取按钮的文本?
qq342252004
发表于 2011-2-12 09:58:30
本帖最后由 qq342252004 于 2011-2-12 10:14 编辑
#Include <WinAPI.au3>
#Include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $ButtunCount=10 ;按钮数量
Global $P[$ButtunCount+1]
Local $Pi[$ButtunCount]
Global $dstxt=""
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
_GDIPlus_StartUp ()
$hImage1 = _GDIPlus_ImageLoadFromFile ("001.png")
$hImage2 = _GDIPlus_ImageLoadFromFile ("002.png")
$hImage3 = _GDIPlus_ImageLoadFromFile ("003.png")
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 450, 450)
;GUICtrlCreatePicB(文本,文本左侧,文本顶部,接下来就是GUICtrlCreatePic原来的参数
$Pi = GUICtrlCreatePicB("按钮1",5,5,"", 16, 24, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("按钮2",5,5,"", 243, 24, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("按钮3",5,5,"", 16, 82, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("按钮4",5,5,"", 243, 82, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("按钮5",5,5,"", 16, 140, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("按钮6",5,5,"", 243, 140, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("按钮7",5,5,"", 16, 198, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("按钮8",5,5,"", 243, 198, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("按钮9",5,5,"", 16, 256, 180, 36,$WS_CLIPSIBLINGS)
$Pi = GUICtrlCreatePicB("按钮10",5,5,"", 243, 256, 180, 36,$WS_CLIPSIBLINGS)
$Pic = _GDIPlus_GraphicsCreateFromHWND ($Form1)
_WinAPI_InvalidateRect(WinGetHandle($Form1))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
$Pos = GUIGetCursorInfo($Form1)
For $i=1 To $P ;$P 为GUICtrlCreatePicB建立按钮的数量 $i为按钮编号
If $Pos = $Pi[$i-1]Then
If $Pos=1 And $P[$i] <> 2 Then
_GDIPLus_GraphicsDrawImageRect($Pic, $hImage3, $P[$i], $P[$i], $P[$i], $P[$i])
_GDIPlus_GraphicsDrawString($Pic,$P[$i],$P[$i]+$P[$i], $P[$i]+$P[$i])
$P[$i] = 2
$dstxt1 = StringSplit($dstxt, '|', 2)
MsgBox(0,'第'&$Pi[$i-1]-2&'个','按钮的文本:'&$dstxt1[$i-1])
Elseif $Pos=0 And $P[$i] <> 1 Then
_GDIPLus_GraphicsDrawImageRect($Pic, $hImage2, $P[$i], $P[$i], $P[$i], $P[$i])
_GDIPlus_GraphicsDrawString($Pic,$P[$i],$P[$i]+$P[$i], $P[$i]+$P[$i])
$P[$i] = 1
Endif
ElseIf $Pos <> $Pi[$i-1] And $P[$i]= 1 Then
_GDIPLus_GraphicsDrawImageRect($Pic, $hImage1,$P[$i], $P[$i], $P[$i], $P[$i])
_GDIPlus_GraphicsDrawString($Pic,$P[$i],$P[$i]+$P[$i], $P[$i]+$P[$i])
$P[$i] = 0
EndIf
Next
WEnd
_GDIPlus_GraphicsDispose ($Pic)
_GDIPlus_ImageDispose ($hImage1)
_GDIPlus_ImageDispose ($hImage2)
_GDIPlus_ImageDispose ($hImage3)
_GDIPlus_ShutDown ()
Func MY_WM_PAINT($hWnd, $msg, $wParam, $lParam)
_WinAPI_RedrawWindow($Form1, 0, 0, $RDW_UPDATENOW)
For $i=1 To $P
_GDIPLus_GraphicsDrawImageRect($Pic, $hImage1, $P[$i], $P[$i], $P[$i], $P[$i])
_GDIPlus_GraphicsDrawString($Pic,$P[$i],$P[$i]+$P[$i], $P[$i]+$P[$i])
Next
_WinAPI_RedrawWindow($Form1, 0, 0, $RDW_VALIDATE)
Return $GUI_RUNDEFMSG
EndFunc ;==>MY_WM_PAINT
Func GUICtrlCreatePicB($txt,$tx,$ty,$pic,$x,$y,$w=-1,$h=-1,$sy=-1,$ex=-1)
$P+=1 ;按钮数量
$P[$P]=$x ;左侧
$P[$P]=$y ;顶部
$P[$P]=$w ;宽度
$P[$P]=$h ;高度
$P[$P]=0 ;Hover
$P[$P]=$txt ;文本
$dstxt&=$txt&"|"
$P[$P]=$tx ;文本左侧
$P[$P]=$ty ;文本顶部
Return GUICtrlCreatePic($pic,$x,$y,$w,$h,$sy,$ex)
EndFuncxxoojoeooxx 这个图片按钮上显示文字的问题得到了解决,接下来的问题我已以短消息发给你了,希望你能帮到我!
menfan1
发表于 2011-2-12 10:49:19
不错,学习一下,呵呵
wsfda
发表于 2011-2-12 16:23:04
美工不错,学习了
村牛
发表于 2011-2-13 02:00:24
好家伙 很给力
myang
发表于 2011-2-13 13:06:43
好家伙 很给力
guang19831217
发表于 2011-2-13 17:28:17
很厉害,按钮都看晕了。