開発環境 |
Microsoft Visual C++ 2010 Express (SP1) |
実行環境 |
Microsoft Windows XP Home Edition (SP3) |
プロジェクトの種類 |
空の CLR プロジェクト |
プロジェクト名 |
clrmdx |
参考
clrmdx.cpp
/*
プロジェクトへの参照の追加(参照タブ)
C:\WINDOWS\Microsoft.NET\DirectX for Managed Code\1.0.2902.0
Microsoft.DirectX.Direct3D.dll
*/
#pragma comment(linker, "/subsystem:windows")
#pragma comment(linker, "/entry:main")
#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>
#include "Form1.h"
using namespace ClrMdx;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// コントロールが作成される前に、Windows XP ビジュアル効果を有効にします
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// メイン ウィンドウを作成して、実行します
Application::Run(gcnew Form1());
return 0;
}
Form1.h
#pragma once
namespace ClrMdx
{
using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;
using namespace Microsoft::DirectX::Direct3D;
public ref class Form1 : public Form
{
public:
Form1(void)
{
InitializeComponent();
PresentParameters^ pp = gcnew PresentParameters();
pp->Windowed = true;
pp->SwapEffect = SwapEffect::Discard; // ダブルバッファを有効に
device = gcnew Device(0, DeviceType::Hardware, this,
CreateFlags::HardwareVertexProcessing, pp);
}
protected:
~Form1()
{
if (components) {
delete components;
}
}
private:
System::ComponentModel::Container ^components;
Device^ device;
void InitializeComponent(void)
{
SuspendLayout();
AutoScaleDimensions = SizeF(6, 12);
AutoScaleMode = Windows::Forms::AutoScaleMode::Font;
ClientSize = Drawing::Size(292, 273);
Name = L"Form1";
Text = L"Form1";
Paint += gcnew PaintEventHandler(this, &Form1::Form1_Paint);
ResumeLayout(false);
}
Void Form1_Paint(Object^ sender, PaintEventArgs^ e)
{
device->Clear(ClearFlags::Target, Color::DarkCyan, 1.0f, 0);
device->Present(); // バッファをスワップ
}
};
}
最終更新:2012年09月19日 06:47