MinGW の gcc で Windows のビジュアルスタイルに対応する
Windowsアプリケーションでビジュアルスタイルを適用するには、ComCtl32.dllのバージョン6以降を使用する必要があります。
MSDNには、「YourApp.exe.manifest」というファイルを作成し、YourApp.exeと同じディレクトリに配置する方法が紹介されています。(マニフェスト外出し)
今回はこの手順を参考に、マニフェストを exe に埋め込んでみます。
[手順]
InitCommonControls()は、最初のCreateWindow()を呼ぶ前くらいに1回呼んでおけばいいと思います。
マニフェストファイル(test.manifest)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" /> </dependentAssembly> </dependency> </assembly>
リソースファイル(test.rc)
#include <winresrc.h> CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "test.manifest"
マニフェストを埋め込んだ exe を作成する
カレントディレクトリに次のファイルがあると仮定します。
- WinMain.c
- test.rc
- test.manifest
ビルドコマンド:
windres --input-format=rc --output-format=coff -o test.res test.rc gcc -c -o WinMain.o WinMain.c gcc -mwindows -o Test.exe WinMain.o test.res -lComCtl32
まず、 windres コマンドで test.rc から test.res を作ります。--output-format=coff というオプションが重要なようです。
2行目はソースをコンパイルし、オブジェクトファイル(.o)を作成しています。
3行目でオブジェクトファイル、test.res、ComCtl32.lib をリンクしています。
test.res をリンクすることで、マニフェストファイルが埋め込まれるようです。