| |
| 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 FunctionCOPY |