Ниже приведён код, который больше относится к windows-программированию. Создаётся главное окно приложения и ведётся обработка сообщений:
>// функция обрабатывающая сообщения главного окна приложения
>LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
> switch (msg) {
> case WM_DESTROY:
> PostQuitMessage(0);
> return 0;
> }
> return DefWindowProc(hWnd, msg, wParam, lParam);
>}
>INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, INT) {
> WNDCLASSEX wc = {
> sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
> GetModuleHandle(0), 0, 0, 0, 0, "FirstDX_cl", 0
> };
> RegisterClassEx(&wc);
> // Создание главного окна приложения
> HWND hWnd = CreateWindow("FirstDX_cl", "FirstDX",
> WS_OVERLAPPEDWINDOW, 100, 100, 160, 160,
> GetDesktopWindow(), NULL, wc.hInstance, NULL);
> if (Init(hWnd)) {
> ShowWindow (hWnd, SW_SHOWDEFAULT);
> UpdateWindow(hWnd);
> MSG msg;
> ZeroMemory(&msg, sizeof(msg));
> while (msg.message != WM_QUIT) {
> if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) {
> TranslateMessage(&msg);
> DispatchMessage(&msg);
> } else Render();
> }
> }
> ReleaseAll();
> UnregisterClass("FirstDX_cl", wc.hInstance);
> return 0;
>}
Функция Render() вызывается всегда, когда не приходят какие-либо сообщения, то есть перерисовка кадра происходит практически постоянно. Функции Init() и ReleaseAll() описаны в предыдущей части урока.
Теперь есть всё, чтобы вы смогли скомпилировать и запустить наш пример. Не забудьте добавить библиотеку d3d8.lib в ваш проект, чтобы линковщик смог найти реализации функций Direct3D.
Поведал: Ваткин.