前田稔(Maeda Minoru)の超初心者のプログラム入門
ファイル名 | 説明 |
---|---|
DRImage.cpp | Direct Draw Image |
#using <System.dll> #using <System.Windows.Forms.dll> #using <System.Drawing.dll> #using <Microsoft.DirectX.dll> #using <Microsoft.DirectX.DirectDraw.dll> using namespace System; using namespace System::Windows::Forms; using namespace System::Drawing; using namespace Microsoft::DirectX; using namespace Microsoft::DirectX::DirectDraw; |
ref class DXDraw : public System::Windows::Forms::Form { Microsoft::DirectX::DirectDraw::Device ^draw; // DrawDevice object. Microsoft::DirectX::DirectDraw::Surface ^primary; // primary destination surface. Microsoft::DirectX::DirectDraw::Surface ^offscreen; // offscreen surface(bitmap loaded). Rectangle dest; public: // Constructor DXDraw() { draw = nullptr; primary = nullptr; offscreen = nullptr; // caption の設定 this->Text = "Dirext Draw"; this->ClientSize = System::Drawing::Size(480, 480); CreateSurfaces(); } |
void CreateSurfaces() { // DrawDevice を生成 draw = gcnew Device(); draw->SetCooperativeLevel(this, CooperativeLevelFlags::Normal); // primary Surface を生成 SurfaceDescription ^description = gcnew SurfaceDescription(); description->SurfaceCaps->PrimarySurface = true; primary = gcnew Surface(description, draw); // offscreen(Image) Surface を生成 description->Clear(); offscreen = gcnew Surface("C:\\Data\\Test\\emiko_s.bmp", description, draw); } |
void Draw() { if (primary==nullptr) return; dest = Rectangle(PointToScreen(Point(0,0)), ClientSize); primary->Draw(dest, offscreen, DrawFlags::Wait); } |
int main() { DXDraw ^frm; frm = gcnew DXDraw(); if (frm) { frm->CreateSurfaces(); // Create Draw Surfaces frm->Show(); // メッセージループ while(frm->Created) { frm->Draw(); Application::DoEvents(); } } return 0; } |