Windows Live WriterプラグインからエントリのHTMLDocumentを取得する方法
publish notification hooksではpost内容を書き換えられないという前回のエントリに対して、JZ5さんからFeedBackを送りましょう、という指摘があったので実際にWindows Live Writer: Development – MSDN Forumsに送りに行ってみると、Solution: How to get an HTMLDocument object for the main post body from your plugin – MSDN Forumsという素敵なスレッドが。エントリのIHTMLDocument2オブジェクトを返してくれる_FindTridentFromControlメソッドと、それを呼び出すための_FindTridentFromLWParentというメソッドのコードスニペットが公開されている。_FindTridentFromLWParentメソッドは、SmartContentSource.CreateContentメソッドなどで渡される、System.Windows.Forms.IWin32Window型のdialogOwnerという引数を渡して呼び出せば良い。実際にSmartContentSourceプラグインの中で試用してみると、確かにIHTMLDocument2オブジェクトが取得できた。これは便利。
一方、publish notification hooksプラグインの中で、OnPrePublishメソッドに渡されるdialogOwnerを使ってFindTridentFromLWParentメソッドを呼び出す場合は工夫が必要。OnPrePublishメソッドで渡されるdialogOwnerは、Live Writerのメインウィンドウではなく、投稿中に表示されるプログレスウィンドウなので、_FindTridentFromLWParentメソッドの代わりに、
private IHTMLDocument2 _FindTridentFromProgressForm(IWin32Window progressForm) {
Form writerMainForm = ((Form)Form.FromHandle(progressForm.Handle)).Owner;
return _FindTridentFromControl(writerMainForm);
}
以上のようなメソッドを作って、FindTridentFromControlメソッドを呼び出す必要がある。
これまでWindowsLive.Writer.Api.IPostInfo.Contentsプロパティに収められている投稿内容を正規表現で書き換えようとしてきたのだが、IHTMLDocument2オブジェクトが扱えるならば、ずっとスマートに色々なことが出来るようになりそうだ。
Related Entries
Trackbacks : 1
- Trackback URL for this entry
- http://blog.sharplab.net/computer/cprograming/windowslivewriter/217/trackback/
Listed below are links to weblogs that reference this entry
- ピンバック from SharpLab. - WLW編集画面のHTMLDocumentを操作する上での障害 08-06-21 15:23:16 JST
-
[...] このまえ「Windows Live WriterプラグインからエントリのHTMLDocumentを取得する方法」というエントリでWLW編集画面のHTMLDocumentオブジェクトを取得する方法を紹介したけれども、その方法にはま [...]
publish notification hooksではpost内容を書き換えられない