三月 8, 2009
HtmlScreenCapture
可以將 HTML 內容(或指定網址)快照成圖檔。(Provides the ability to capture HTML content into a bitmap. [#])
- 要參考 C:\Program Files\Windows Live\Writer\WindowsLive.Writer.Api.dll
程式碼:
using System;
using System.Collections.Generic;
using System.Text;
using WindowsLive.Writer.Api;
class Program
{
static void Main(string[] args)
{
// 從指定網址截圖
WindowsLive.Writer.Api.HtmlScreenCapture capture =
new HtmlScreenCapture(new Uri("http://tw.yahoo.com"), 1024/*寬度*/);
System.Drawing.Bitmap bmp = capture.CaptureHtml(5000/*timeoutMs*/);
bmp.Save(@"C:\1.png", System.Drawing.Imaging.ImageFormat.Png);
// 從 html 內容截圖
WindowsLive.Writer.Api.HtmlScreenCapture capture2 = new HtmlScreenCapture(
"<h1>中文測試</h1><p>一些<b>文字</b>"+
"和一個<a href='http://klcin.tw/net'>連結</a></p>", 200);
System.Drawing.Bitmap bmp2 = capture2.CaptureHtml(5000);
bmp2.Save(@"C:\2.png", System.Drawing.Imaging.ImageFormat.Png);
} // Main
} // class
輸出結果:


參考資料:
十二月 6, 2008
前言
專案中有個程式負責透過 ACDSee 列印(ProcessStartInfo.Verb=”Print”)各種圖檔。但 ACDSee 在列印時會出現讓使用者設定格式、頁首頁尾、印表機選項的視窗出現,要按下「列印(P)」之後才會真的開始列印,所以程式必須在開始工作時偵測 ACDSee 的狀態並且按下列印鈕。
方法如下:
- hWnd = FindWindow(null,”ACDSee – 列印”); // 尋找 ACDSee 的列印視窗
- SetForegroundWindow(hWnd); // 將視窗帶到前景
- SendKeys.SendWait(“{ENTER}”); // 送出 ENTER 鍵按列印鈕
事前測試都OK,但安裝到客戶的機器上卻經常發生沒有自動按列印鈕而卡住的問題。原以為是被其它程式干擾{ENTER}的發送,但奇怪的是同事在現場怎麼測試都無法重現問題,一離開不久客戶就反應問題又發生了。
最後,細心的同事發現是因為機器一段時間沒人操作就會被鎖住(lock),流程卡住的問題就開始了!
推測:當系統 lock 時,畫面看不到 ACDSee 的視窗(但 FindWindow 可以找到)所以 SendKey 無法送到正確的視窗。
繼續閱讀 »
十一月 30, 2008
使用 Windows Live Writer Backup (2.0.0.22) 備份 Windows Live Writer (14.0.5025.904) 時發生如下的錯誤,雖然最後顯示備份成功,但並沒有任何檔案產生。
System.Diagnostics.Debug.WriteLine(exception.ToString())
System.NullReferenceException: 並未將物件參考設定為物件的執行個體
於 CabLib.Compress.OnUpdateStatus(kCurStatus pk_CurStatus, Void* p_Param)
於 CCompressT<CCompress>.FCIUpdateStatus(UInt32 typeStatus, UInt32 cb1, UInt32 cb2, Void* pv)
於 CCompressT<CCompress>.FlushCabinet(CCompressT<CCompress>* , Int32 b_CreateNewCabinetFile, Void* pParam)
於 CCompressT<CCompress>.DestroyFCIContext(CCompressT<CCompress>* )
於 CCompress.{dtor}(CCompress* )
於 ___CxxCallUnwindDtor(IntPtr pDtor, Void* pThis)
於 CabLib.Compress.CompressFileList(ArrayList i_FileList, String s_CabFile, Int32 s32_SplitSize)
於 CabLib.Compress.CompressFolder(String s_Folder, String s_CabFile, String s_Filter, Int32 s32_SplitSize)
於 LiveWriterBackup.BackupRestore.doCompression(String filen)
於是使用工具去研究 Windows Live Writer Backup 的錯誤所在及其備份原理。
繼續閱讀 »