// The following is mainly the news cycle, the root ordinary program is different
Int apientry Winmain (Hinstance Hinstance,
Hinstance Hprevinstance,
LPSTR LPCMDLINE,
INT ncmdshow)
{
// Todo: Place Code Here.
MSG msg;
Haccel HaccelTable;
// Initialize Global Strings
LoadString (Hinstance, IDS_APP_TITLE, SZTITLE, MAX_LOADSTRING);
LoadString (Hinstance, IDC_DirectX, SzWindowClass, Max_LoadString);
MyRegisterClass (Hinstance);
// Perform Application InIstization:
IF (! initinstance (hinstance, ncmdshow))
{
Return False;
}
Hacceltable = loading (hinstance, (lpctstr) iDC_directx);
// Initialize the DirectDraw environment and implement the DirectDraw function
IF (Failed (InitDirectDraw (Hinstance))) {
MessageBox (getActiveWindow (), "Initialization DirectDraw process error!", "Error", MB_OK;
FREEDRAW ();
DESTROYWINDOW ());
Return False;
}
// main message loop:
While (1)
{
IF (PEEKMESSAGE (& MSG, NULL, 0, 0, PM_NOREMOVE))
{
IF (! GetMessage (& MSG, NULL, 0, 0))
{
Return msg.wparam;
}
IF (! TranslateAccelerator (Msg.hwnd, HaccelTable, & MSG))
{
TranslateMessage (& MSG);
DispatchMessage (& MSG);
}
}
ELSE IF (g_bactive)
{
IF (failed (mainloop ()))
{
FREEDRAW ();
MessageBox (GetActiveWindow (), Text ("Displaying The next frame failed.")
Text ("THE Sample Will Now EXIT."), Text ("DirectDraw Sample"),
MB_ICONERROR | MB_OK);
PostquitMessage (0);
}
}
Else
Waitmessage ();
}
Return msg.wparam;
}
// function: myregisterclass ()
// purpose: registers the window class.
Atom MyRegisterClass (Hinstance Hinstance)
{
WNDCLASSEX WCEX;
Wcex.cbsize = sizeof (wndclassex);
WCEX.Style = CS_HREDRAW | CS_VREDRAW;
WCEX.LPFNWNDPROC = (WndProc) WndProc;
Wcex.cbclsextra = 0;
Wcex.cbWndextra = 0; wcex.hinstance = Hinstance;
Wcex.hicon = loading (Hinstance, (LPCTSTR) IDI_DIRECTX);
Wcex.hcursor = loadingcursor (null, idc_arrow);
Wcex.hbrbackground = (hbrush) getStockObject (Black_brush);
WCEX.LPSZMENUNAME = NULL;
WCEX.LPSZCLASSNAME = SzWindowClass;
Wcex.hiconsm = loading (Wcex.hinstance, (LPCTSTR) IDI_SMALL);
Return RegisterClassex (& WCEX);
}
Bool InitInstance (Hinstance Hinstance, Int ncmdshow)
{
Hwnd hwnd;
Hinst = Hinstance; // Store Instance Handle in Our Global Variable
HWND = CREATEWINDOW (SzwindowClass, Sztitle, WS_POPUP,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, HINSTANCE, NULL
IF (! hwnd)
{
Return False;
}
ShowWindow (HWND, NCMDSHOW);
UpdateWindow (HWND);
Return True;
}
Lresult Callback WndProc (HWND HWND, UINT MESSAGE, WPARAM WPARAM, LPARAM LPARAM)
{
Switch (Message)
{
Case WM_ActivateApp:
g_bactive = wparam;
Break;
Case WM_KeyDown:
IF (wparam == vk_escape)
{
PostquitMessage (0);
Return 0;
}
Break;
Case WM_DESTROY:
FREEDRAW ();
PostquitMessage (0);
Break;
DEFAULT:
Return DefWindowProc (Hwnd, Message, WPARAM, LPARAM);
}
Return 0;
}