The Main Window Procedure

The Helworld.c sample has a very simple main window procedure—after all, the application allows practically no user interaction.

When the window procedure receives a WM_DESTROY message, it calls the CleanUp function, just as you would expect.

When it receives a WM_ACTIVATE message, it retrieves an IDirect3DRMWinDevice interface and calls the IDirect3DRMWinDevice::HandleActivate method to ensure that the colors are correct in the active rendering window. Similarly, the function reacts to a WM_PAINT message by calling the IDirect3DRMWinDevice::HandlePaint method.

/////////////////////////////////////////////////////////////////////

//

// WindowProc

// Main window message handler.

//

/////////////////////////////////////////////////////////////////////

LONG FAR PASCAL WindowProc(HWND win, UINT msg,

WPARAM wparam, LPARAM lparam)

{

RECT r;

PAINTSTRUCT ps;

LPDIRECT3DRMWINDEVICE lpD3DRMWinDev;

switch (msg) {

case WM_DESTROY:

CleanUp();

break;

case WM_ACTIVATE:

{

// Create a Windows-specific D3DRM window device to handle this

// message.

LPDIRECT3DRMWINDEVICE lpD3DRMWinDev;

if (!myglobs.dev)

break;

myglobs.dev->lpVtbl->QueryInterface(myglobs.dev,

&IID_IDirect3DRMWinDevice, (void **) &lpD3DRMWinDev);

lpD3DRMWinDev->lpVtbl->HandleActivate(lpD3DRMWinDev,

(WORD) wparam);

lpD3DRMWinDev->lpVtbl->Release(lpD3DRMWinDev);

}

break;

case WM_PAINT:

if (!myglobs.bInitialized || !myglobs.dev)

return DefWindowProc(win, msg, wparam, lparam);

// Create a Windows-specific D3DRM window device to handle this

// message.

if (GetUpdateRect(win, &r, FALSE)) {

BeginPaint(win, &ps);

myglobs.dev->lpVtbl->QueryInterface(myglobs.dev,

&IID_IDirect3DRMWinDevice, (void **) &lpD3DRMWinDev);

if (FAILED(lpD3DRMWinDev->lpVtbl->HandlePaint(lpD3DRMWinDev,

ps.hdc)))

lpD3DRMWinDev->lpVtbl->Release(lpD3DRMWinDev);

EndPaint(win, &ps);

}

break;

default:

return DefWindowProc(win, msg, wparam, lparam);

}

return 0L;

}