简易预览取色

  1. CoordMode, Mouse, Screen
  2. CoordMode, Pixel, Screen
  3. SetSystemCursor("IDC_Cross")
  4. Loop
  5. {
  6. if (GetKeyState("LControl")&&BackgroundColor<>""){
  7. Clipboard:=Format("0x{:06x}",BackgroundColor)
  8. }Else if GetKeyState("Esc"){
  9. RestoreCursors(),ToolTip
  10. ExitApp
  11. }
  12. MouseGetPos xpos, ypos
  13. PixelGetColor BackgroundColor, xpos, ypos, RGB
  14. grayLevel:= GetgrayLevel(BackgroundColor)
  15. TextColor:=grayLevel>192?0x000000:0xffffff
  16. ToolTip, % "Hex:" BackgroundColor "`n灰度值:" grayLevel "`nLControl:复制至剪切版`nEsc:退出"
  17. WinGet, hWnd, ID, ahk_class tooltips_class32
  18. WinSet, ExStyle, +0x00000020, ahk_id %hWnd%
  19. ToolTipStyle(hWnd,{Background:BackgroundColor,Text:TextColor})
  20. }
  21. GetgrayLevel(Color){
  22. Color:=InStr(Color,"#")?SubStr(Format("0x{:06x}",SubStr(Color,2)),3):SubStr(Format("0x{:06x}",Color),3)
  23. tarr:=[Format("{:d}","0x" SubStr(Color,1,2)),Format("{:d}","0x" SubStr(Color,3,2)),Format("{:d}","0x" SubStr(Color,5,2))]
  24. Return Floor(tarr[1] * 0.299 + tarr[2] * 0.587 + tarr[3] * 0.114)
  25. }
  26. RestoreCursors()
  27. {
  28. SPI_SETCURSORS := 0x57
  29. DllCall( "SystemParametersInfo", UInt,SPI_SETCURSORS, UInt,0, UInt,0, UInt,0 )
  30. }
  31. /*
  32. Cursor鼠标状态类型:
  33. IDC_ARROW 常规箭头形
  34. IDC_IBEAM "工"字形文本插入
  35. IDC_WAIT 沙漏形
  36. IDC_CROSS 十字形精确定位
  37. IDC_UPARROW 上箭头
  38. IDC_SIZE 隐藏指针
  39. IDC_ICON 使用指定光标文件
  40. IDC_SIZENWSE 左上角右下角大小调整
  41. IDC_SIZENESW 左下角右上角大小调整
  42. IDC_SIZEWE 水平调整
  43. IDC_SIZENS 垂直调整
  44. IDC_SIZEALL 选中并移动
  45. IDC_NO 不可用
  46. IDC_HAND 小手形状
  47. IDC_APPSTARTING 系统忙
  48. IDC_HELP 帮助
  49. */
  50. SetSystemCursor( Cursor = "", cx = 0, cy = 0 )
  51. {
  52. BlankCursor := 0, SystemCursor := 0, FileCursor := 0 ; init
  53. SystemCursors = 32512IDC_ARROW,32513IDC_IBEAM,32514IDC_WAIT,32515IDC_CROSS
  54. ,32516IDC_UPARROW,32640IDC_SIZE,32641IDC_ICON,32642IDC_SIZENWSE
  55. ,32643IDC_SIZENESW,32644IDC_SIZEWE,32645IDC_SIZENS,32646IDC_SIZEALL
  56. ,32648IDC_NO,32649IDC_HAND,32650IDC_APPSTARTING,32651IDC_HELP
  57. If Cursor = ; empty, so create blank cursor
  58. {
  59. VarSetCapacity( AndMask, 32*4, 0xFF ), VarSetCapacity( XorMask, 32*4, 0 )
  60. BlankCursor = 1 ; flag for later
  61. }
  62. Else If SubStr( Cursor,1,4 ) = "IDC_" ; load system cursor
  63. {
  64. Loop, Parse, SystemCursors, `,
  65. {
  66. CursorName := SubStr( A_Loopfield, 6, 15 ) ; get the cursor name, no trailing space with substr
  67. CursorID := SubStr( A_Loopfield, 1, 5 ) ; get the cursor id
  68. SystemCursor = 1
  69. If ( CursorName = Cursor )
  70. {
  71. CursorHandle := DllCall( "LoadCursor", Uint,0, Int,CursorID )
  72. Break
  73. }
  74. }
  75. If CursorHandle = ; invalid cursor name given
  76. {
  77. Msgbox,, SetCursor, Error: Invalid cursor name
  78. CursorHandle = Error
  79. }
  80. }
  81. Else If FileExist( Cursor )
  82. {
  83. SplitPath, Cursor,,, Ext ; auto-detect type
  84. If Ext = ico
  85. uType := 0x1
  86. Else If Ext in cur,ani
  87. uType := 0x2
  88. Else ; invalid file ext
  89. {
  90. Msgbox,, SetCursor, Error: Invalid file type
  91. CursorHandle = Error
  92. }
  93. FileCursor = 1
  94. }
  95. Else
  96. {
  97. Msgbox,, SetCursor, Error: Invalid file path or cursor name
  98. CursorHandle = Error ; raise for later
  99. }
  100. If CursorHandle != Error
  101. {
  102. Loop, Parse, SystemCursors, `,
  103. {
  104. If BlankCursor = 1
  105. {
  106. Type = BlankCursor
  107. %Type%%A_Index% := DllCall( "CreateCursor"
  108. , Uint,0, Int,0, Int,0, Int,32, Int,32, Uint,&AndMask, Uint,&XorMask )
  109. CursorHandle := DllCall( "CopyImage", Uint,%Type%%A_Index%, Uint,0x2, Int,0, Int,0, Int,0 )
  110. DllCall( "SetSystemCursor", Uint,CursorHandle, Int,SubStr( A_Loopfield, 1, 5 ) )
  111. }
  112. Else If SystemCursor = 1
  113. {
  114. Type = SystemCursor
  115. CursorHandle := DllCall( "LoadCursor", Uint,0, Int,CursorID )
  116. %Type%%A_Index% := DllCall( "CopyImage"
  117. , Uint,CursorHandle, Uint,0x2, Int,cx, Int,cy, Uint,0 )
  118. CursorHandle := DllCall( "CopyImage", Uint,%Type%%A_Index%, Uint,0x2, Int,0, Int,0, Int,0 )
  119. DllCall( "SetSystemCursor", Uint,CursorHandle, Int,SubStr( A_Loopfield, 1, 5 ) )
  120. }
  121. Else If FileCursor = 1
  122. {
  123. Type = FileCursor
  124. %Type%%A_Index% := DllCall( "LoadImageA"
  125. , UInt,0, Str,Cursor, UInt,uType, Int,cx, Int,cy, UInt,0x10 )
  126. DllCall( "SetSystemCursor", Uint,%Type%%A_Index%, Int,SubStr( A_Loopfield, 1, 5 ) )
  127. }
  128. }
  129. }
  130. }
  131. ToolTipStyle(hwnd:="",Options:=""){
  132. static bc:="", tc:="", htext:=0, hfont:=0
  133. If IsObject(Options){
  134. For key,value In Options
  135. %key%:=value
  136. If (Background<>"")
  137. bc:=((Background&255)<<16)+(((Background>>8)&255)<<8)+(Background>>16)
  138. If (Text<>"")
  139. tc:=((Text&255)<<16)+(((Text>>8)&255)<<8)+(Text>>16)
  140. If (Font||Size){
  141. If !htext {
  142. Gui _TTG: Add, Text, +hwndhtext
  143. Gui _TTG: +hwndhgui +0x40000000
  144. }
  145. Gui _TTG: Font, %Size%, %Font%
  146. GuiControl _TTG: Font, %htext%
  147. hfont:=DllCall("SendMessage", "Ptr", htext, "Uint", 0x31, "Ptr", 0, "Ptr", 0)
  148. }
  149. }
  150. If (hwnd&&(bc||tc||hfont)){
  151. DllCall("UxTheme.dll\SetWindowTheme", "ptr", hwnd, "Ptr", 0, "UintP", 0)
  152. If (bc)
  153. DllCall("SendMessage", "Ptr", hwnd, "Uint", 1043, "Ptr", bc, "Ptr", 0)
  154. If (tc)
  155. DllCall("SendMessage", "Ptr", hwnd, "Uint", 1044, "Ptr", tc, "Ptr", 0)
  156. If (hfont)
  157. DllCall("SendMessage", "Ptr", hwnd, "Uint", 0x30, "Ptr", hfont, "Ptr", 0)
  158. }
  159. }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
其他应用教程案例

超级命令【super-command】

2021-12-16 22:02:50

其他应用教程

[分享]visual studio 制作Mcode机器码

2021-12-21 16:23:19

3 条回复 A文章作者 M管理员
欢迎您,新朋友,感谢参与互动!
  1. hexuren

    有参考价值,我最近也在搞这一块

    • 蜜獾哥

      显示用btt ,btt可以背景色与字体色反色显示有个灰度计算公式 hex转rgb后
      Graylevel=0.299*R+0.587*G+0.144*B Graylevel值以192为分界 判断深浅色后可以在btt背景为取色值后 字体色根据Graylevel值决定是显示深黑还是深白

  2. mp911

    谢谢大佬分享

个人中心
购物车
优惠劵
私信列表
搜索