<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>sks blog &#187; C#</title>
	<atom:link href="http://sks.s201.xrea.com/blog/archives/tag/c/feed" rel="self" type="application/rss+xml" />
	<link>http://sks.s201.xrea.com/blog</link>
	<description>気になったこと、役に立ちそうだなと思ったことなどを公開しています。</description>
	<lastBuildDate>Sun, 19 Apr 2009 06:55:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ContextMenuStripをタスクバー上に表示する</title>
		<link>http://sks.s201.xrea.com/blog/archives/469</link>
		<comments>http://sks.s201.xrea.com/blog/archives/469#comments</comments>
		<pubDate>Fri, 27 Oct 2006 19:38:23 +0000</pubDate>
		<dc:creator>shuichi</dc:creator>
				<category><![CDATA[その他]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[プログラミング]]></category>
		<category><![CDATA[小技]]></category>

		<guid isPermaLink="false">http://sks.s201.xrea.com/blog/archives/469</guid>
		<description><![CDATA[
.NET Framework 2.0では.NET Framework 1.xのContextMenuの代わりにContextMenuStripというコントロールが追加されました。このContextMenuStripは多 [...]]]></description>
			<content:encoded><![CDATA[<p>
.NET Framework 2.0では.NET Framework 1.xのContextMenuの代わりにContextMenuStripというコントロールが追加されました。このContextMenuStripは多機能で便利ですが、タスクバー上に表示させようとするとうまく表示できません(タスクバーに重ならないように表示される)。SHAppBarMessageでデスクトップツールバーを作成したときなどは困るんじゃないかと。ということでContextMenuStripをタスクバー上に表示させるためにいろいろと調べてみました。
</p>
<p>
最初に注目したのはNotifyIcon。NotifyIconにContextMenuStripを設定すると正常にタスクバー上に表示されます。MSIL逆アセンブラでNotifyIconを覗いてみると、ContextMenuStripのShowInTaskbarというプライベートメソッドを呼び出していることが分かります。とりあえず、
</p>
<pre>
contextMenuStrip.GetType().InvokeMember(
    "ShowInTaskbar",
    System.Reflection.BindingFlags.NonPublic |
    System.Reflection.BindingFlags.InvokeMethod |
    System.Reflection.BindingFlags.Instance,
    null,
    contextMenuStrip,
    new Object[] { Cursor.Position.X, Cursor.Position.Y } );
</pre>
<p>
とすることでcontextMenuStripをタスクバー上に表示させることができました。
</p>
<p>
ただし、この方法では何故かメニューが常にマウスポインタの右上に表示されるようです。いまいちスッキリしないのでShowInTaskbarメソッドの中をさらに覗いてみると、ToolStripDropDownにWorkingAreaConstrainedプロパティが存在するらしい。強制的に作業領域に表示させるという意味なので、
</p>
<pre>
contextMenuStrip.GetType().InvokeMember(
    "WorkingAreaConstrained",
    System.Reflection.BindingFlags.NonPublic |
    System.Reflection.BindingFlags.SetProperty |
    System.Reflection.BindingFlags.Instance,
    null,
    contextMenuStrip,
    new Object[] { false } );
contextMenuStrip.Show( Cursor.Position );
</pre>
<p>
としてみるとうまく表示させることができました。ただし、メニューが表示されるとWorkingAreaConstrainedがtrueに設定されるようなので、表示させる前に毎回WorkingAreaConstrainedをfalseに設定しないと駄目なようです。
</p>
<p>
これらの方法は本来アクセスできないメソッドやプロパティに強引にアクセスしているわけで、実際はこのような方法は好ましくありません。とりあえずこのような方法もあるというだけです。</p>
]]></content:encoded>
			<wfw:commentRss>http://sks.s201.xrea.com/blog/archives/469/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iTunes COM SDK</title>
		<link>http://sks.s201.xrea.com/blog/archives/423</link>
		<comments>http://sks.s201.xrea.com/blog/archives/423#comments</comments>
		<pubDate>Mon, 05 Jun 2006 18:02:25 +0000</pubDate>
		<dc:creator>shuichi</dc:creator>
				<category><![CDATA[その他]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[iTunes]]></category>
		<category><![CDATA[プログラミング]]></category>

		<guid isPermaLink="false">http://sks.s201.xrea.com/blog/archives/423</guid>
		<description><![CDATA[
半年くらい前にiTunes COM for Windows SDKというものがあることを知りました。COMを扱えるプログラミング言語からiTunesをコントロールすることができます。ということでC#からも簡単にiTun [...]]]></description>
			<content:encoded><![CDATA[<p>
半年くらい前に<a href="http://developer.apple.com/sdk/itunescomsdk.html">iTunes COM for Windows SDK</a>というものがあることを知りました。COMを扱えるプログラミング言語からiTunesをコントロールすることができます。ということでC#からも簡単にiTunesをコントロールすることができるみたいです。ただ、これを使って何を作ればいいのか…ネタが思いつかない。ちなみに<a href="http://www.blogpeople.net/loves-music.html">BlogPeople loves Music &#8211; AutoPlay</a>というイントロ再生するためのソフトがあるんですけど、これもiTunesをCOMインターフェース経由でコントロールしているんだと思います。</p>
]]></content:encoded>
			<wfw:commentRss>http://sks.s201.xrea.com/blog/archives/423/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>プログラミングに最適なフォントConsolasが提供開始</title>
		<link>http://sks.s201.xrea.com/blog/archives/409</link>
		<comments>http://sks.s201.xrea.com/blog/archives/409#comments</comments>
		<pubDate>Mon, 22 May 2006 02:52:18 +0000</pubDate>
		<dc:creator>shuichi</dc:creator>
				<category><![CDATA[その他]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Vista]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[ソフトウェア]]></category>
		<category><![CDATA[フォント]]></category>

		<guid isPermaLink="false">http://sks.s201.xrea.com/blog/archives/409</guid>
		<description><![CDATA[
ConsolasがMicrosoftのサイトからConsolas Font Pack for Microsoft Visual Studio 2005としてダウンロードできるようになりました。ConsolasとはWin [...]]]></description>
			<content:encoded><![CDATA[<p>
ConsolasがMicrosoftのサイトから<a href = "http://www.microsoft.com/downloads/details.aspx?familyid=22e69ae4-7e40-4807-8a86-b3d36fab68d3&#038;displaylang=en" title = "Consolas Font Pack for Microsoft Visual Studio 2005">Consolas Font Pack for Microsoft Visual Studio 2005</a>としてダウンロードできるようになりました。ConsolasとはWindows Vista用の新フォントです。他にも日本語表示用のMeiryoなどが有名ですが、Consolasは英数字用の等幅フォントです。ということでプログラミング用に最適だと思いますよ。
</p>
<p>
ちなみに、このフォントはVisual Studio 2005の正規ライセンスユーザーに対して提供されているみたいです。私は一応Visual Studio 2005を持っているんですけど、持っていない人は無料の<a href = "http://www.microsoft.com/japan/msdn/vstudio/express/" title = "Visual Studio 2005 Express Edition">Visual Studio 2005 Express Edition</a>をインストールすればO.K.なんでしょうか?ちなみにダウンロードされるインストーラを実行するとフォントがインストールされるのと同時にVisual Studio 2005のテキストエディタのフォントがConsolasに自動的に設定されました。下の図はVisual C# Express Editionで表示してみたところ。
</p>
<p>
<img id="image410" src="/blog/wp-content/consolas.png" alt="Consolas" /></p>
]]></content:encoded>
			<wfw:commentRss>http://sks.s201.xrea.com/blog/archives/409/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.NETのWildcard(ワイルドカード)クラス</title>
		<link>http://sks.s201.xrea.com/blog/archives/44</link>
		<comments>http://sks.s201.xrea.com/blog/archives/44#comments</comments>
		<pubDate>Fri, 16 Sep 2005 08:00:45 +0000</pubDate>
		<dc:creator>shuichi</dc:creator>
				<category><![CDATA[その他]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[プログラミング]]></category>

		<guid isPermaLink="false">http://sks.s201.xrea.com/blog/archives/44</guid>
		<description><![CDATA[ファイル名を指定するときなどに用いるワイルドカードを.NETで扱う方法がCode ProjectのConverting Wildcards to Regexesにあります。タイトルのとおりワイルドカードを正規表現に変換し [...]]]></description>
			<content:encoded><![CDATA[<p>ファイル名を指定するときなどに用いるワイルドカードを.NETで扱う方法がCode Projectの<a href="http://www.codeproject.com/useritems/WildcardToRegex.asp">Converting Wildcards to Regexes</a>にあります。タイトルのとおりワイルドカードを正規表現に変換しているだけですけど、このようにWildcardクラスを定義するとワイルドカードを直感的に扱えますね。</p>
<p>そういえばファイル検索やウェブ検索で正規表現を扱えたらなぁってたまに思うんですけど、デスクトップ検索アプリケーションなどで対応しているものありますかね。</p>
]]></content:encoded>
			<wfw:commentRss>http://sks.s201.xrea.com/blog/archives/44/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C#用のBigIntegerクラス</title>
		<link>http://sks.s201.xrea.com/blog/archives/47</link>
		<comments>http://sks.s201.xrea.com/blog/archives/47#comments</comments>
		<pubDate>Sat, 10 Sep 2005 13:46:56 +0000</pubDate>
		<dc:creator>shuichi</dc:creator>
				<category><![CDATA[その他]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[プログラミング]]></category>

		<guid isPermaLink="false">http://sks.s201.xrea.com/blog/archives/47</guid>
		<description><![CDATA[Javaには任意精度の整数演算を行うことができるBigIntegerクラスがありますが、これのC#版をThe Code Project &#8211; C# BigInteger Classで見つけました(かなり今更感が [...]]]></description>
			<content:encoded><![CDATA[<p>Javaには任意精度の整数演算を行うことができるBigIntegerクラスがありますが、これのC#版を<a href="http://www.codeproject.com/csharp/biginteger.asp">The Code Project &#8211; C# BigInteger Class</a>で見つけました(かなり今更感がありますが…)。実はJ#を使えばBigIntegerを使えるらしいのですが、やはりC#でも使えたほうがいいですよね。さらっとドキュメントを見て試してみたところなかなか使いやすい感じです。</p>
]]></content:encoded>
			<wfw:commentRss>http://sks.s201.xrea.com/blog/archives/47/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C#(.NET)におけるメッセージフック</title>
		<link>http://sks.s201.xrea.com/blog/archives/50</link>
		<comments>http://sks.s201.xrea.com/blog/archives/50#comments</comments>
		<pubDate>Sun, 04 Sep 2005 13:17:03 +0000</pubDate>
		<dc:creator>shuichi</dc:creator>
				<category><![CDATA[その他]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[プログラミング]]></category>
		<category><![CDATA[小技]]></category>

		<guid isPermaLink="false">http://sks.s201.xrea.com/blog/archives/50</guid>
		<description><![CDATA[昔にVisual Basicをやっていたころ色々と凝ったことをやろうとするとVisual Basicの標準機能では実現できないということが多くありました。こういう時はサブクラス化でメッセージをフックするのが最終手段だった [...]]]></description>
			<content:encoded><![CDATA[<p>昔にVisual Basicをやっていたころ色々と凝ったことをやろうとするとVisual Basicの標準機能では実現できないということが多くありました。こういう時はサブクラス化でメッセージをフックするのが最終手段だったのですが、まぁこれが面倒くさい。最初からVisual C++などで書いたほうが良かったと思うくらいでした。</p>
<p>で、C#やVisual Basic.NETなどの.NET対応の言語においてコントロールに送られてくるメッセージを受け取るには、コントロールのクラスを継承してWndProcをオーバーライドすればメッセージを処理することができます。継承のできなかったVisual Basicと比較するとかなり扱いやすくなっていると思います。</p>
<p>一応これで十分なのですが他にも方法があり、<a href="http://www.geocities.jp/eco21426/">Eco-Soft</a>さんの<a href="http://www.geocities.jp/eco21426/TipsNET/Miscellaneous.htm">コントロールのサブクラス化(フック)を行う</a>に書かれているように、Windows APIを用いる方法もあります(GCHandle.Allocがポイントなんですよね)。これはVisual Basicにおけるサブクラス化と同じ方法なんですけどね…。</p>
<p>また、さらに<a href="http://ant0x.udap.jp/">Memory of the future</a>さんの<a href="http://ant0x.udap.jp/tips/tips_NativeWindow.htm">NativeWindowクラスを用いたサブクラス化</a>を見て知ったのですが.NETのNativeWindowクラスを用いる方法があるようです。</p>
<p>自分のコントロールのメッセージを処理したい場合は継承してWndProcのオーバーライドでいいと思いますが、他のコントロールに送られてくるメッセージを拝借してこちら側で処理をしたい場合などにはNativeWindowクラスを用いる方法がいいかもしれませんね。</p>
]]></content:encoded>
			<wfw:commentRss>http://sks.s201.xrea.com/blog/archives/50/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Code ProjectやCodeGuruで面白いサンプルコードを見つける</title>
		<link>http://sks.s201.xrea.com/blog/archives/389</link>
		<comments>http://sks.s201.xrea.com/blog/archives/389#comments</comments>
		<pubDate>Mon, 15 Aug 2005 14:09:15 +0000</pubDate>
		<dc:creator>shuichi</dc:creator>
				<category><![CDATA[その他]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[プログラミング]]></category>

		<guid isPermaLink="false">http://sks.s201.xrea.com/blog/archives/389</guid>
		<description><![CDATA[お盆休み中は暇でしたので久しぶりにC#で遊んでいました。まぁ、C#初心者なのでコードを書いていると案の定つまずきます。.Net Framework SDKに付属しているドキュメントを読んでもよくわからないときには以下のサ [...]]]></description>
			<content:encoded><![CDATA[<p>お盆休み中は暇でしたので久しぶりにC#で遊んでいました。まぁ、C#初心者なのでコードを書いていると案の定つまずきます。.Net Framework SDKに付属しているドキュメントを読んでもよくわからないときには以下のサンプルコードやTipsが多数公開されている便利なサイトを。</p>
<ul>
<li><a href="http://www.atmarkit.co.jp/fdotnet/dotnettips/index/">@IT: .NET TIPS</a></li>
<li><a href="http://dobon.net/vb/dotnet/">DOBON.NET .NET Tips</a></li>
<li><a href="http://www.codeproject.com/">The Code Project</a></li>
<li><a href="http://www.codeguru.com/">CodeGuru</a></li>
<li><a href="http://www.devcity.net/">DevCity.NET</a></li>
<li><a href="http://www.c-sharpcorner.com/">C# Corner</a></li>
</ul>
<p>すべて有名なサイトですね…。The Code ProjectとCodeGuruは英語ですが、かなりおすすめです。適当に記事を見ていくだけでもなかなか面白いですよ。</p>
]]></content:encoded>
			<wfw:commentRss>http://sks.s201.xrea.com/blog/archives/389/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
