這裏顯示兩個版本的差異處。
Both sides previous revision 前次修改 下次修改 | 前次修改 | ||
programming:c_sharp [2009/03/11 22:04] wenpei |
programming:c_sharp [2011/04/09 00:02] (目前版本) wenpei 畫面截圖 |
||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== 在 C# 中抓取指定視窗的畫面截圖 ====== | ||
+ | Ref: http://dan.zzhc.org/post/3617137304/capture-window-with-c-sharp | ||
+ | |||
+ | <code> | ||
+ | /* 引入 Win32 API 中的 User32.DLL | ||
+ | * 需要加上 using System.Runtime.InteropServices; | ||
+ | */ | ||
+ | [DllImport("user32.dll")] | ||
+ | public static extern Boolean GetWindowRect(IntPtr hWnd, ref Rectangle bounds); | ||
+ | |||
+ | public void CaptureWindow () { | ||
+ | /* 取得目標視窗的 Handle | ||
+ | * 需要加上 using System.Diagnostics; | ||
+ | */ | ||
+ | Process[] process = Process.GetProcessesByName("notepad"); | ||
+ | |||
+ | /* 取得該視窗的大小與位置 */ | ||
+ | Rectangle bounds; | ||
+ | GetWindowRect(process[0].MainWindowHandle, ref bounds); | ||
+ | |||
+ | /* 抓取截圖 */ | ||
+ | Bitmap screenshot = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb); | ||
+ | Graphics gfx = Graphics.FromImage(screenshot); | ||
+ | gfx.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy); | ||
+ | |||
+ | /* 利用 PictureBox 顯示出來 */ | ||
+ | imageView.Image = (Image) screenshot; | ||
+ | imageView.Update(); | ||
+ | } | ||
+ | |||
+ | </code> | ||
+ | |||
+ | ====== Techotopia: C# Essentials ====== | ||
+ | http://www.techotopia.com/index.php/C_Sharp_Essentials | ||
+ | |||
====== 在背景中下載檔案 ====== | ====== 在背景中下載檔案 ====== | ||
http://msdn2.microsoft.com/zh-tw/library/ms229675(VS.80).aspx | http://msdn2.microsoft.com/zh-tw/library/ms229675(VS.80).aspx | ||
行 16: | 行 51: | ||
====== C# 4.0 新特性:動態型別、選用參數、具名參數 ====== | ====== C# 4.0 新特性:動態型別、選用參數、具名參數 ====== | ||
http://blog.miniasp.com/post/2009/02/CSharp-40-New-Features-Dynamic-Lookup-and-Named-and-Optional-Arguments.aspx | http://blog.miniasp.com/post/2009/02/CSharp-40-New-Features-Dynamic-Lookup-and-Named-and-Optional-Arguments.aspx | ||
+ | |||
+ | ====== 以 C# 撰寫多執行緒 (Multi-threading) 相關學習資源整理 ====== | ||
+ | http://blog.miniasp.com/post/2009/03/Multi-Threading-in-CSharp-Learning-Resources.aspx | ||
+ | |||
+ | ====== 在 C# 中抓取指定視窗的畫面截圖 ====== | ||
+ | http://dan.zzhc.org/post/3617137304/capture-window-with-c-sharp | ||
+ | |||
+ | <code> | ||
+ | /* 引入 Win32 API 中的 User32.DLL | ||
+ | * 需要加上 using System.Runtime.InteropServices; | ||
+ | */ | ||
+ | [DllImport("user32.dll")] | ||
+ | public static extern Boolean GetWindowRect(IntPtr hWnd, ref Rectangle bounds); | ||
+ | |||
+ | public void CaptureWindow () { | ||
+ | /* 取得目標視窗的 Handle | ||
+ | * 需要加上 using System.Diagnostics; | ||
+ | */ | ||
+ | Process[] process = Process.GetProcessesByName("notepad"); | ||
+ | |||
+ | /* 取得該視窗的大小與位置 */ | ||
+ | Rectangle bounds; | ||
+ | GetWindowRect(process[0].MainWindowHandle, ref bounds); | ||
+ | |||
+ | /* 抓取截圖 */ | ||
+ | Bitmap screenshot = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb); | ||
+ | Graphics gfx = Graphics.FromImage(screenshot); | ||
+ | gfx.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy); | ||
+ | |||
+ | /* 利用 PictureBox 顯示出來 */ | ||
+ | imageView.Image = (Image) screenshot; | ||
+ | imageView.Update(); | ||
+ | } | ||
+ | </code> | ||
====== .NET Reflector ====== | ====== .NET Reflector ====== |