如何设置鼠标触动标签时字体的颜色
本帖最后由 依旧漂泊 于 2015-11-8 12:41 编辑请问如何设置鼠标在触动标签时字体的颜色,触动就变色。
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 442, 192, 124)
$Label1 = GUICtrlCreateLabel("如何设置鼠标触摸标签时字体的颜色【带手型效果】", 120, 96, 280, 17)
$Label2 = GUICtrlCreateLabel("标签2", 120, 150, 280, 17)
GUICtrlSetCursor($Label1, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd #include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 442, 192, 124)
$Label1 = GUICtrlCreateLabel("如何设置鼠标触摸标签时字体的颜色【带手型效果】", 120, 96, 280, 17)
GUICtrlSetCursor(-1, 16)
GUICtrlSetCursor($Label1, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Label1
$color = _get_color()
GUICtrlSetColor($Label1, $color)
EndSwitch
WEnd
Func _get_color()
Local $x, $y, $z
$x = Random(0, 255, 1)
$y = Random(0, 255, 1)
$z = Random(0, 255, 1)
Return Number($x & $y & $z)
EndFunc 本帖最后由 llllllxllllll 于 2015-11-7 20:46 编辑
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 442, 192, 124)
$Label1 = GUICtrlCreateLabel("如何设置鼠标触摸标签时字体的颜色【带手型效果】", 120, 96, 280, 17)
GUICtrlSetCursor($Label1, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$pd=1
While 1
$nMsg = GUIGetMsg()
$ID = GUIGetCursorInfo($Form1)
If Not @error Then
If $ID = $Label1 And $pd = 1 Then
GUICtrlSetColor($Label1, 0xFF0033)
$pd = 0
ElseIf $ID <> $Label1 And $pd = 0 Then
GUICtrlSetColor($Label1, 0x000000)
$pd= 1
EndIf
EndIf
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Label1
MsgBox(0, 0, "你点了标签")
EndSwitch
WEnd
按照A版的代码改了下,不知是否是你想要的效果
http://www.autoitx.com/forum.php?mod=viewthread&tid=11137&highlight=%CA%F3%B1%EA%D0%FC%CD%A3 学习了,谢谢分享! 回复 3# llllllxllllll
A版换ID了?{:face (114):} 回复 5# xyold1
此A非彼A。。。 代码不错帮顶{:face (394):} 学习了,谢谢分享! 学习了,谢谢分享! 本帖最后由 298311657 于 2015-11-20 20:15 编辑
使用_WinAPI_SetWindowLong子类化控件,然后为控件添加WM_MOUSEHOVER或WM_MOUSELEAVE,正常情况下消息并不会响应,可以使用_WinAPI_TrackMouseEvent处理一下。
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <WinAPISys.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 442, 192, 124)
$Label1 = GUICtrlCreateLabel("如何设置鼠标触摸标签时字体的颜色【带手型效果】", 120, 96, 280, 17, BitOR($SS_NOTIFY, $SS_LEFT))
$wStaticProcNew = DllCallbackRegister("_MyStaticProc", "int", "hwnd;uint;uint;dword")
$wStaticProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle(-1), $GWL_WNDPROC, DllCallbackGetPtr($wStaticProcNew))
$Label2 = GUICtrlCreateLabel("标签2", 120, 150, 280, 17)
$wStaticProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle(-1), $GWL_WNDPROC, DllCallbackGetPtr($wStaticProcNew))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _MyStaticProc($hWnd, $uiMsg, $wParam, $lParam)
Switch $uiMsg
Case $WM_LBUTTONDOWN;左键点击
MsgBox(0,"", "点击的控件id:" & _WinAPI_GetDlgCtrlID($hWnd))
Case $WM_MOUSEHOVER;鼠标悬停
GUICtrlSetColor(_WinAPI_GetDlgCtrlID($hWnd), 0xFF0000)
Case $WM_MOUSELEAVE;鼠标离开
GUICtrlSetColor(_WinAPI_GetDlgCtrlID($hWnd), 0x000000)
Case $WM_MOUSEMOVE;鼠标移动
_WinAPI_TrackMouseEvent($hWnd, BitOR($TME_HOVER, $TME_LEAVE)) ;//MOUSELEAVE|MOUSEHOVER消息由此函数触发
Case $WM_SETCURSOR;设置光标
GUICtrlSetCursor(_WinAPI_GetDlgCtrlID($hWnd), 0)
EndSwitch
Return _WinAPI_CallWindowProc($wStaticProcOld, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc
学习了,谢谢
页:
[1]