标题: [问题求助] VBS 如何抓取屏幕某一点坐标的颜色值? [打印本页]
作者: ecogbc 时间: 2012-7-27 23:32 标题: VBS 如何抓取屏幕某一点坐标的颜色值?
本帖最后由 pcl_test 于 2017-4-16 16:42 编辑
VBS 如何抓取屏幕某一点坐标颜色?
作者: pcl_test 时间: 2017-4-16 16:42
本帖最后由 pcl_test 于 2017-4-27 08:29 编辑
- '运行后在屏幕任意位置点击即可
- Set ws = CreateObject("Wscript.Shell")
- Set fso = CreateObject("Scripting.FileSystemObject")
-
- If LCase(Right(WScript.FullName, 11)) = "wscript.exe" Then
- ws.run "cscript.exe -nologo """ & WSH.ScriptFullName & """", 0
- WSH.Quit
- End If
-
- Set tmp = fso.GetSpecialFolder(2)
- Set systemroot = fso.GetSpecialFolder(0)
- net = systemroot&"\Microsoft.NET\Framework"
- Call CreateCs
- Set SubFolders = fso.GetFolder(net).SubFolders
- For Each Folder In SubFolders
- If fso.FileExists(Folder&"\csc.exe") Then
- cscpath = Folder&"\csc.exe"
- Exit For
- End If
- Next
-
- If cscpath = "" Then
- Msgbox "未安装Microsoft .NET Framework 2.0及以上版本组件或是相关程序缺失!"
- WSH.Quit
- Else
- If not fso.FileExists(tmp&"\$GetPixelColor.exe") Then
- ws.Run cscpath&" /out:"""&tmp&"\$GetPixelColor.exe"" """&tmp&"\$GetPixelColor.cs""", 0, True
- End If
- End If
-
- Set oExec = ws.Exec(tmp&"\$GetPixelColor.exe")
- Msgbox oExec.StdOut.ReadAll '结果
-
- Function CreateCs
- Set cs = fso.CreateTextFile(tmp&"\$GetPixelColor.cs", 2)
- cs.Write _
- "using System;using System.Runtime.InteropServices;using System.Windows.Forms;" & vbCrLf & _
- "using System.Drawing;using System.Threading;" & vbCrLf & _
- "public class GetPixelColor {" & vbCrLf & _
- " [DllImport(""user32.dll"")]" & vbCrLf & _
- " private static extern IntPtr GetDC(IntPtr hwnd);" & vbCrLf & _
- " [DllImport(""gdi32.dll"")]" & vbCrLf & _
- " private static extern int GetPixel(IntPtr hdc, Point p);" & vbCrLf & _
- " public static void Main(string[] args){" & vbCrLf & _
- " while (true){if ((Control.MouseButtons & MouseButtons.Left) == MouseButtons.Left){" & vbCrLf & _
- " int x = Control.MousePosition.X, y = Control.MousePosition.Y;" & vbCrLf & _
- " Point p = new Point(x, y);IntPtr hdc = GetDC(IntPtr.Zero);" & vbCrLf & _
- " int c = GetPixel(hdc, p), r = (c & 0xFF);" & vbCrLf & _
- " int g = (c & 0xFF00)>>8, b = (c & 0xFF0000)>>16;" & vbCrLf & _
- " Console.WriteLine(""X:""+x+"" Y:""+y+""\r\nR:""+r+"" G:""+g+"" B:""+b+""\r\nHTML:""+" & vbCrLf & _
- " ColorTranslator.ToHtml(Color.FromArgb(r, g, b))+""\r\nHEX:""+c.ToString(""X6""));break;" & vbCrLf & _
- " }Thread.Sleep(100);" & vbCrLf & _
- "}}}"
- End Function
复制代码
作者: shuaige100 时间: 2017-8-31 11:30
我要点赞快乐咯
作者: segree 时间: 2023-5-19 18:57
牛逼牛逼,怎么这么好的帖子没人顶?
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |