// 14.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "d3dx9.h"
#include "d3d9.h"
#include <d3dx9math.h>
#define D3DFVF_CUSTOMVERTEX ( D3DFVF_XYZRHW| D3DFVF_DIFFUSE )
IDirect3D9 *D3dObject;
IDirect3DDevice9* D3dDevice;
LPDIRECT3DVERTEXBUFFER9 Buff=NULL;
VOID * p;
struct CUSTOMVERTEX
{
float X,Y,Z , rwh;
DWORD color;
};
CUSTOMVERTEX Tre[]=
{
{20.0f,20.0f,20.5f,0x1AAAAfff},
{60.0f,20.0f,20.5f,0x1AAAAfff},
{40.0f,50.5f,20.5f,0x1AAAAfff},
};
LRESULT __stdcall MainWindowProc
(
HWND hwnd,
UINT msg,
WPARAM wParam,
LPARAM lParam
);
void DrawWindowArea(HWND hwnd);
int __stdcall WinMain
(
HINSTANCE instance,
HINSTANCE previousInstance,
LPSTR commandLine,
int commandShow
)
{
WNDCLASS wc;
ZeroMemory(&wc, sizeof(wc));
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.hInstance = instance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.lpszClassName = "mywndclass";
wc.lpfnWndProc = MainWindowProc;
if( !RegisterClass(&wc) )
return 0;
HWND AppWnd = CreateWindow
(
"mywndclass",
"d3d test",
WS_OVERLAPPEDWINDOW,
100, 100, 450, 400,
NULL,
NULL,
instance,
NULL
);
if( !AppWnd )
return 0;
D3dObject = Direct3DCreate9(D3D_SDK_VERSION);
if( !D3dObject )
return 0;
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
HRESULT res;
res = D3dObject -> CreateDevice
(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
AppWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3dpp,
&D3dDevice
);
if( res != D3D_OK )
{
D3dObject -> Release();
return 0;
}
ShowWindow(AppWnd, commandShow);
UpdateWindow(AppWnd);
MSG msg;
while( GetMessage(&msg, NULL, 0, 0) > 0 )
{
DispatchMessage(&msg);
}
Buff->Release();
D3dDevice -> Release();
D3dObject -> Release();
return msg.wParam;
}
LRESULT __stdcall MainWindowProc
(
HWND hwnd,
UINT msg,
WPARAM wParam,
LPARAM lParam
)
{
switch(msg)
{
case WM_PAINT:
DrawWindowArea(hwnd);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
void DrawWindowArea(HWND hwnd)
{
D3dDevice ->CreateVertexBuffer(sizeof(CUSTOMVERTEX)*3,0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&Buff,NULL);
void *p;
Buff -> Lock(0, 0, &p, 0);
CopyMemory(p, Tre, sizeof(Tre));
Buff -> Unlock();
D3dDevice -> Clear
(
0,
NULL,
D3DCLEAR_TARGET,
D3DCOLOR_XRGB(255, 255, 255),
0,
0
);
D3dDevice ->BeginScene();
D3dDevice ->SetStreamSource(0,Buff,0,sizeof(CUSTOMVERTEX));
D3dDevice ->SetFVF(D3DFVF_CUSTOMVERTEX);
D3dDevice ->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
D3dDevice ->EndScene();
D3dDevice -> Present(NULL, NULL, NULL, NULL);
RECT wndRect;
GetClientRect(hwnd, &wndRect);
ValidateRect(hwnd, &wndRect);
}
has exited with code 0 (0x0)
Вот код:
Код:
Всё работает!Но меня смущяет ,что в Debug окне выходит следующее:
Код:
The program 'C:\Program Files\Microsoft Visual Studio\MyProjects\Вершины v 2(4)\Debug\Окно.exe' has exited with code 0 (0x0).
Что это?
Как правило, это значит, что программа корректно завешилась.
Ясно)А то я думал это какой-то недачёт.
[COLOR="Red"]Постановляю: ЗАКРЫТЬ.[/COLOR]