找回密码
 加入
搜索
查看: 4378|回复: 10

[GUI管理] 如何设置鼠标触动标签时字体的颜色

  [复制链接]
发表于 2015-11-7 14:52:02 | 显示全部楼层 |阅读模式
本帖最后由 依旧漂泊 于 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

评分

参与人数 1金钱 -10 收起 理由
afan -10

查看全部评分

发表于 2015-11-7 20:43:04 | 显示全部楼层
#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
发表于 2015-11-7 20:44:06 | 显示全部楼层
本帖最后由 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[4] = $Label1 And $pd = 1 Then
                        GUICtrlSetColor($Label1, 0xFF0033)
                        $pd = 0
                ElseIf $ID[4] <> $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
发表于 2015-11-7 21:39:50 | 显示全部楼层
学习了,谢谢分享!
发表于 2015-11-7 23:06:13 | 显示全部楼层
回复 3# llllllxllllll

A版换ID了?
发表于 2015-11-9 12:37:29 | 显示全部楼层
回复 5# xyold1


    此A非彼A。。。
发表于 2015-11-10 19:52:28 | 显示全部楼层
代码不错帮顶
发表于 2015-11-14 10:31:20 | 显示全部楼层
学习了,谢谢分享!
发表于 2015-11-18 01:15:32 | 显示全部楼层
学习了,谢谢分享!
发表于 2015-11-20 20:10:30 | 显示全部楼层
本帖最后由 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
发表于 2016-12-7 00:20:02 | 显示全部楼层
学习了,谢谢
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-23 14:16 , Processed in 0.080803 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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