h>#includeddutilh
// Defines constants and global variables
#define SAFE_DELETE(p){ if (p) { delete (p); (p)=NULL; } }
#define SAFE_RELEASE(p) { if (p) { (p)>Release(); (p)=NULL; } }
#define ERMSG(x)MessageBox(hWndxDirectDraw ProgramMB_OK);
CDisplay* g_pDisplay= NULL;
CSurface* g_pTextSurface= NULL;
BOOLg_bActive = FALSE;
// Functionprototypes
LRESULT CALLBACK MainWndProc(HWND UINT WPARAM LPARAM);
HRESULT WinInit(HINSTANCE hInst int nCmdShow HWND* phWnd);
HRESULT InitDirectDraw(HWND hWnd);
VOIDFreeDirectDraw();
HRESULT DisplayFrame();
//★ Windows Main
int APIENTRY WinMain(HINSTANCE hInst HINSTANCE hPrevInst LPSTR pCmdLine int nCmdShow)
{ MSG msg;
HWNDhWnd;
if (FAILED(WinInit(hInst nCmdShow &hWnd)))return FALSE;
if (FAILED(InitDirectDraw(hWnd)))
{ if (g_pDisplay)
g_pDisplay>GetDirectDraw()>SetCooperativeLevel(NULL DDSCL_NORMAL);
ERMSG(DirectDraw init failed The sample will now exit);
return FALSE;
}
while(TRUE)
{ if (PeekMessage(&msg NULL PM_NOREMOVE))
{ if ( == GetMessage(&msg NULL ))return (int)msgwParam;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{ if (g_bActive)
{ if (FAILED(DisplayFrame()))
{ SAFE_DELETE(g_pDisplay);
ERMSG(Displaying the next frame failed The sample will now exit);
return FALSE;
}
}
elseWaitMessage();
}
}
}
//★ WinInit()
HRESULT WinInit(HINSTANCE hInst int nCmdShow HWND* phWnd)
{ WNDCLASS wc;
HWND hWnd;
// Register the Window Class
wclpszClassName = TEXT(Hello DirectX !);
wclpfnWndProc = MainWndProc;
wcstyle = CS_VREDRAW | CS_HREDRAW;
wchInstance = hInst;
wchIcon = LoadIcon(NULLIDI_APPLICATION);
wchCursor = LoadCursor(NULL IDC_ARROW);
wchbrBackground = (HBRUSH)(COLOR_WINDOW+);
wclpszMenuName= NULL;
wccbClsExtra= ;
wccbWndExtra= ;
if (RegisterClass(&wc)==)return E_FAIL;
// Create and show the main window
hWnd = CreateWindowEx( TEXT(Hello DirectX !) TEXT(DirectDraw TEXT View)
WS_POPUP CW_USEDEFAULT CW_USEDEFAULT
CW_USEDEFAULT CW_USEDEFAULT NULL NULL hInst NULL);
if (hWnd==NULL) return E_FAIL;
ShowWindow(hWnd nCmdShow);
UpdateWindow(hWnd);
*phWnd = hWnd;
return S_OK;
}
//★ InitDirectDraw()
HRESULT InitDirectDraw(HWND hWnd)
{ HRESULT hr;
g_pDisplay = new CDisplay();
if (FAILED(hr= g_pDisplay>CreateFullScreenDisplay(hWnd )))
{ ERMSG(This display card does not support xx);
return hr;
}
// Create a surface and draw text to it
if (FAILED(hr= g_pDisplay>CreateSurfaceFromText(&g_pTextSurface
NULLHello DirectX !RGB()RGB())))
return hr;
return S_OK;
}
//★ FreeDirectDraw()
VOID FreeDirectDraw()
{ SAFE_DELETE(g_pTextSurface);
SAFE_DELETE(g_pDisplay);
}
//★ MainWndProc()
LRESULT CALLBACK MainWndProc(HWND hWnd UINT msg WPARAM wParam LPARAM lParam)
{ switch(msg)
{ case WM_KEYDOWN:
PostMessage(hWnd WM_CLOSE );
return L;
case WM_SIZE:
// Check to se