[已解决]GUIGetCursorInfo 为何无法实现效果
本帖最后由 duyan 于 2011-4-11 00:13 编辑#include <GUIConstantsEx.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Dim $CLA = 0
Dim $CLA2 = 0
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 320, 280, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Tab1 = GUICtrlCreateTab(8, 16, 289, 193)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
GUICtrlSetState(-1,$GUI_SHOW)
$Graphic = GUICtrlCreateGraphic(110, 120, 100, 30, $WS_BORDER)
$TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
$TabSheet3 = GUICtrlCreateTabItem("TabSheet3")
$TabSheet4 = GUICtrlCreateTabItem("TabSheet4")
GUICtrlCreateTabItem("")
$Graphic2 = GUICtrlCreateGraphic(110, 230, 100, 30, $WS_BORDER)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
GetPos()
GetPos2()
Sleep(100)
WEnd
Func Form1Close()
Exit
EndFunc
Func GetPos()
Dim $a = GUIGetCursorInfo($Form1)
If $a = $Graphic And $CLA = 0 Then
GUICtrlSetBkColor($Graphic, 0x9CD560)
$CLA = 1
ElseIf $a <> $Graphic And $CLA = 1 Then
GUICtrlSetBkColor($Graphic, 0xFFFFFF)
$CLA = 0
EndIf
EndFunc ;==>GetPos
Func GetPos2()
Dim $a = GUIGetCursorInfo($Form1)
If $a = $Graphic2 And $CLA2 = 0 Then
GUICtrlSetBkColor($Graphic2, 0x9CD560)
$CLA2 = 1
ElseIf $a <> $Graphic2 And $CLA2 = 1 Then
GUICtrlSetBkColor($Graphic2, 0xFFFFFF)
$CLA2 = 0
EndIf
EndFunc ;==>GetPos 我想请教2个问题:
1.这段代码运行后,当鼠标移过下面的 Graphic 时可以变色,但移过上面的就是在 Tab 里面的 Graphic 时却没有效果,请问是哪里错了?
2.如果我不想让鼠标移过时变色,而是想让鼠标点击 Graphic 时变色,这段代码该如何改?
谢谢! 看下GUIGETCURSORINFO返回的值不就知道了…第二个问题,graphic控件可以点击,看帮助 不好意思,我是新手,楼上能就第一个问题说得具体点吗?非常感谢您及时的回复! Tab 里面的 Graphic 背景色确实不能这么set
改用Label,2个问题一并解决如下#include <GUIConstantsEx.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Dim $CLA = 0, $CLA2 = 1, $color =
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 320, 280, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Tab1 = GUICtrlCreateTab(8, 16, 289, 193)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
$Graphic = GUICtrlCreateLabel('悬停', 110, 120, 100, 30, 0x201 + 0x00800000)
$TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
$TabSheet3 = GUICtrlCreateTabItem("TabSheet3")
$TabSheet4 = GUICtrlCreateTabItem("TabSheet4")
GUICtrlCreateTabItem("")
$Graphic2 = GUICtrlCreateLabel('点击', 110, 230, 100, 30, 0x201 + 0x00800000)
GUICtrlSetOnEvent(-1, "_click")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
GetPos()
Sleep(100)
WEnd
Func Form1Close()
Exit
EndFunc ;==>Form1Close
Func GetPos()
Local $a = GUIGetCursorInfo($Form1)
If $a = $Graphic And $CLA = 0 Then
GUICtrlSetBkColor($Graphic, 0x9CD560)
$CLA = 1
ElseIf $a <> $Graphic And $CLA = 1 Then
GUICtrlSetBkColor($Graphic, 0xFFFFFF)
$CLA = 0
EndIf
EndFunc ;==>GetPos
Func _click()
$CLA2 = Abs($CLA2 - 1)
GUICtrlSetBkColor($Graphic2, $color[$CLA2])
EndFunc ;==>_click
试过了,问题圆满解决。非常感谢楼上的鼎力帮助!
页:
[1]