「XAMLでキュゥべえ」ビルドしてみた
[XAMLでキュゥべえ - 赤坂玲音Blog 〜CODE SENSES〜]にあるものを使って、単純なアプリケーションをビルドしてみた。XAMLは、その言葉をときおり見かけはすれども、いじったことなかった。調査(調査ってほど大げさなものじゃないけど)をかねてやってみた。なので、ハローワールド*1に毛が生えたようなアプリケーションだ。
Windows 7 x64、Visual Studio 2010 Express(C# & C++)、Windows SDK 7.1が入っている環境、Windows XP SP3 x86、Visual Studio 2005 Express(C++)、Windows SDK 7.1が入っている環境で試した。たぶん、Visual Studioなくても、Windows SDK 7.1が入ってれば大丈夫だと思われる。
Windows SDK 7.1は"C:\Program Files\Microsoft SDKs\Windows\v7.1"にインストールされているとする。
[連載:XAMLの基礎知識 − @IT]の[第1回 Hello Worldとテキスト・エディタで始めるXAML − @IT]にあるサンプルを、だいぶん流用させてもらった。
- "win.xaml"、"app.xaml"、"qb.proj"というテキストファイルを作る。テキストファイルは文字コードUTF-8で保存する*2。それぞれのファイルの内容は後述。
- コマンドプロンプトを開く。
- "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.Cmd" を実行する*3。
- "msbuild" "qb.proj" を実行すると、"qb.exe" のできあがり。
"qb.proj"のToolsVersionは4.0とした。Visual StudioやWindows SDKの別ヴァージョンやらが入っていると、その環境の違いを考えてプロジェクト書かないといけない*4。単純なサンプルに、そんな面倒なことを考えたくないので、4.0に決めうち。
ソースコード、プロジェクトファイル
win.xaml
<?xml version="1.0" encoding="UTF-8"?> <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Title="Face of QB." Width="640" Height="480" > <Canvas> <Ellipse Fill="#FFB23A77" Stroke="Black" Width="120" Height="120" Canvas.Left="33" Canvas.Top="92" /> <Ellipse Fill="#FF6E1111" Height="60" Width="60" Canvas.Left="64" Canvas.Top="122"/> <Ellipse Fill="#FFF4F4F5" Height="30" Width="30" Canvas.Left="106" Canvas.Top="112"/> <Ellipse Fill="#FFB23A77" Stroke="Black" Width="120" Height="120" Canvas.Left="464" Canvas.Top="92" /> <Ellipse Fill="#FF6E1111" Height="60" Width="60" Canvas.Left="495" Canvas.Top="122"/> <Ellipse Fill="#FFF4F4F5" Height="30" Width="30" Canvas.Left="534" Canvas.Top="112"/> <Path Data="M218,331.99992 C223,347.99965 227,361.99935 254,366.99935 281,371.99935 303.33333,359.99937 322,349.99937 344,360.66604 344.94601,367.9588 372,368.99881 398,369.9983 407,358.99934 413,338.9998" Height="37.063" Stretch="Fill" Stroke="Black" Canvas.Left="219" Canvas.Top="344" Width="195"/> </Canvas> </Window>
app.xaml
<?xml version="1.0" encoding="UTF-8"?> <Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" StartupUri="win.xaml" />
qb.proj
<?xml version="1.0" encoding="UTF-8"?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build" ToolsVersion="4.0"> <PropertyGroup> <AssemblyName>QB</AssemblyName> <OutputType>winexe</OutputType> <OutputPath>.\</OutputPath> </PropertyGroup> <ItemGroup> <ApplicationDefinition Include="app.xaml" /> <Page Include="win.xaml" /> <Reference Include="System" /> <Reference Include="WindowsBase" /> <Reference Include="PresentationCore" /> <Reference Include="PresentationFramework" /> <Reference Include="System.Xaml" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> </Project>