(圖片來源︰techcn)
什麼是線框圖?為什麼要劃線框圖?
假如要儲存的檔案名稱,包含特殊字元會造成無法儲存,只需透過 Path.InvalidPathChars 即可查出特殊字元,就可去除瞜。
foreach (char c in Path.InvalidPathChars) DatName = "檔案名稱".Replace(c.ToString(), "").Trim();
透過 Graphics 中的 CopyFromScreen 即可達到複製螢幕功能!
全螢幕擷取到檔案:
Bitmap myImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); Graphics g = Graphics.FromImage(myImage); g.CopyFromScreen(new Point(0,0), new Point(0, 0), new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)); IntPtr dc1 = g.GetHdc(); g.ReleaseHdc(dc1); myImage.Save(@"c:\screen.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
帶入 Process ID 取得使用者名稱:
public string GetProcessOwner(int processId) { string query = "Select * From Win32_Process Where ProcessID = " + processId; ManagementObjectSearcher searcher = new ManagementObjectSearcher(query); ManagementObjectCollection processList = searcher.Get(); foreach (ManagementObject obj in processList) { string[] argList = new string[] { string.Empty, string.Empty }; int returnVal = Convert.ToInt32(obj.InvokeMethod("GetOwner", argList)); if (returnVal == 0) { // return DOMAIN\user return argList[1] + "\\" + argList[0]; } } return "NO OWNER"; }
方式一:效率較快!
/// <summary> /// 加密 /// </summary> /// <param name="original">字串</param> /// <returns>回傳加密結果</returns> public string Encrypt(string Str) { MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); byte[] bytes = md5.ComputeHash(Encoding.Default.GetBytes(Str)); return BitConverter.ToString(bytes).Replace("-", string.Empty); }
首先下載 FreeImage:
本地下載:FreeImage
官方下載:http://freeimage.sourceforge.net/
將 FreeImageNET.dll 加入參考,即可開始利用 FreeImage 讀寫圖檔。
//讀出PCX圖檔到Image FREE_IMAGE_FORMAT FIF = FREE_IMAGE_FORMAT.FIF_PCX; Image IMG = FreeImage.LoadBitmap("檔案路徑", FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref FIF); //讀出BMP圖檔到Image FREE_IMAGE_FORMAT FIF = FREE_IMAGE_FORMAT.FIF_BMP; Image IMG = FreeImage.LoadBitmap("檔案路徑", FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref FIF);
官方有提供 Sample 喔,自己研究吧!
.Net 已經內建控制滑鼠位置的指令:
Cursor.Position = new Point(30, 60); //X Y軸位置
如果要點擊滑鼠就需要透過WinAPI才能達到:
首先建立一個Class:
using System.Threading; using System.Runtime.InteropServices; using System; namespace Test { static public class Mouse { [DllImport("user32.dll", SetLastError = true)] public static extern Int32 SendInput(Int32 cInputs, ref INPUT pInputs, Int32 cbSize); [StructLayout(LayoutKind.Explicit, Pack = 1, Size = 28)] public struct INPUT { [FieldOffset(0)] public INPUTTYPE dwType; [FieldOffset(4)] public MOUSEINPUT mi; [FieldOffset(4)] public KEYBOARDINPUT ki; [FieldOffset(4)] public HARDWAREINPUT hi; } [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct MOUSEINPUT { public Int32 dx; public Int32 dy; public Int32 mouseData; public MOUSEFLAG dwFlags; public Int32 time; public IntPtr dwExtraInfo; } [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct KEYBOARDINPUT { public Int16 wVk; public Int16 wScan; public KEYBOARDFLAG dwFlags; public Int32 time; public IntPtr dwExtraInfo; } [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct HARDWAREINPUT { public Int32 uMsg; public Int16 wParamL; public Int16 wParamH; } public enum INPUTTYPE : int { Mouse = 0, Keyboard = 1, Hardware = 2 } [Flags()] public enum MOUSEFLAG : int { MOVE = 0x1, LEFTDOWN = 0x2, LEFTUP = 0x4, RIGHTDOWN = 0x8, RIGHTUP = 0x10, MIDDLEDOWN = 0x20, MIDDLEUP = 0x40, XDOWN = 0x80, XUP = 0x100, VIRTUALDESK = 0x400, WHEEL = 0x800, ABSOLUTE = 0x8000 } [Flags()] public enum KEYBOARDFLAG : int { EXTENDEDKEY = 1, KEYUP = 2, UNICODE = 4, SCANCODE = 8 } } }
利用 SendKeys.Send 即可 輸入文字 或 發送某個按鍵。
SendKeys.Send("文字"); //發送文字 SendKeys.Send("{ENTER}"); //發送Enter按鍵
當使用 SevenZipSharp 出現 Can not load 7-zip library or internal COM error
只需加入以下這行,指定 DLL 位置即可!
SevenZipCompressor.SetLibraryPath(Server.MapPath("~/bin/7z.dll"));
常常在試用軟體嗎?試用完後留下一堆暫存檔,清除不掉嗎?
IObit Uninstaller 是一套移除應用程式的工具,當使用「新增移除程式」移除我們不想再用的應用程式失敗時,便可使用IObit Uninstaller。
除了移除應用程式,應用程式未清除的的資料夾、個人資料夾及登錄檔也會一併移除,另外,採用分頁的方式呈現電腦裡的應用程式清單,像最近常使用的軟體、大型的軟體、最近安裝的軟體等。
軟體特色
•可一次移除多個應用程式。
•可一鍵解除IE瀏覽器的Toolbars。
•提供標準和進階移除功能,進階移除可協助使用者,在移除應用程式時,將Windows Registry及硬碟殘留下來的相關檔案或資料夾,一併移除。
•提供強制移除功能。
軟體下載:http://www.iobit.com/advanceduninstaller.html