[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[问题求助] VBS 如何抓取屏幕某一点坐标的颜色值?

本帖最后由 pcl_test 于 2017-4-16 16:42 编辑

VBS 如何抓取屏幕某一点坐标颜色?

本帖最后由 pcl_test 于 2017-4-27 08:29 编辑
  1. '运行后在屏幕任意位置点击即可
  2. Set ws = CreateObject("Wscript.Shell")
  3. Set fso = CreateObject("Scripting.FileSystemObject")
  4. If LCase(Right(WScript.FullName, 11)) = "wscript.exe" Then
  5.     ws.run "cscript.exe -nologo """ & WSH.ScriptFullName & """", 0
  6.     WSH.Quit
  7. End If
  8. Set tmp = fso.GetSpecialFolder(2)
  9. Set systemroot = fso.GetSpecialFolder(0)
  10. net = systemroot&"\Microsoft.NET\Framework"
  11. Call CreateCs
  12. Set SubFolders = fso.GetFolder(net).SubFolders
  13. For Each Folder In SubFolders
  14.     If fso.FileExists(Folder&"\csc.exe") Then
  15.         cscpath = Folder&"\csc.exe"
  16.         Exit For
  17.     End If
  18. Next
  19. If cscpath = "" Then
  20.     Msgbox "未安装Microsoft .NET Framework 2.0及以上版本组件或是相关程序缺失!"
  21.     WSH.Quit
  22. Else
  23.     If not fso.FileExists(tmp&"\$GetPixelColor.exe") Then
  24.         ws.Run cscpath&" /out:"""&tmp&"\$GetPixelColor.exe"" """&tmp&"\$GetPixelColor.cs""", 0, True
  25.     End If
  26. End If
  27. Set oExec = ws.Exec(tmp&"\$GetPixelColor.exe")
  28. Msgbox oExec.StdOut.ReadAll '结果
  29. Function CreateCs
  30.     Set cs = fso.CreateTextFile(tmp&"\$GetPixelColor.cs", 2)
  31.     cs.Write _
  32.     "using System;using System.Runtime.InteropServices;using System.Windows.Forms;" & vbCrLf & _
  33.     "using System.Drawing;using System.Threading;" & vbCrLf & _
  34.     "public class GetPixelColor {" & vbCrLf & _
  35.     "   [DllImport(""user32.dll"")]" & vbCrLf & _
  36.     "   private static extern IntPtr GetDC(IntPtr hwnd);" & vbCrLf & _
  37.     "   [DllImport(""gdi32.dll"")]" & vbCrLf & _
  38.     "   private static extern int GetPixel(IntPtr hdc, Point p);" & vbCrLf & _
  39.     "   public static void Main(string[] args){" & vbCrLf & _
  40.     "        while (true){if ((Control.MouseButtons & MouseButtons.Left) == MouseButtons.Left){" & vbCrLf & _
  41.     "           int x = Control.MousePosition.X, y = Control.MousePosition.Y;" & vbCrLf & _
  42.     "           Point p = new Point(x, y);IntPtr hdc = GetDC(IntPtr.Zero);" & vbCrLf & _
  43.     "           int c = GetPixel(hdc, p), r = (c & 0xFF);" & vbCrLf & _
  44.     "           int g = (c & 0xFF00)>>8, b = (c & 0xFF0000)>>16;" & vbCrLf & _
  45.     "           Console.WriteLine(""X:""+x+"" Y:""+y+""\r\nR:""+r+"" G:""+g+"" B:""+b+""\r\nHTML:""+" & vbCrLf & _
  46.     "               ColorTranslator.ToHtml(Color.FromArgb(r, g, b))+""\r\nHEX:""+c.ToString(""X6""));break;" & vbCrLf & _
  47.     "           }Thread.Sleep(100);" & vbCrLf & _
  48.     "}}}"
  49. End Function
复制代码
1

评分人数

    • yu2n: 感谢分享技术 + 1

TOP

我要点赞快乐咯

TOP

牛逼牛逼,怎么这么好的帖子没人顶?

TOP

返回列表