ITPub博客

首页 > 应用开发 > IT综合 > DirectX8.1的DirectDraw7研究手记(二) 下 (转)

DirectX8.1的DirectDraw7研究手记(二) 下 (转)

原创 IT综合 作者:worldblog 时间:2007-12-14 09:12:16 0 删除 编辑
DirectX8.1的DirectDraw7研究手记(二) 下 (转)[@more@]

//下面主要是消息循环,根普通程序不一样

int apiENTRY WinMain(HINSTANCE hInstance,XML:namespace prefix = o ns = "urn:schemas-microsoft-com:Office:office" />

  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 initialization:

  if (!InitInstance (hInstance, nCmdShow))

  {

  return FALSE;

  }

  hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_DIRECTX);

  //初始化DirectDraw环境,并实现DirectDraw功能

  if (FAILED(initDirectDraw(hInstance))){

    MessageBox ( GetActiveWindow(), "初始化DirectDraw过程中出错!", "Error", MB_OK ) ;

    FreeDraw() ;

    DestroyWindow ( GetActiveWindow() ) ;

  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  = LoadIcon(hInstance, (LPCTSTR)IDI_DIRECTX);

  wcex.hCursor  = LoadCursor(NULL, IDC_ARROW);

  wcex.hbrBackground  = (HBRUSH )GetStockobject(BLACK_BRUSH);

  wcex.lpszMenuName  = NULL;

  wcex.lpszClassName  = szWindowClass;

  wcex.hIconSm  = LoadIcon(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;

}


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752043/viewspace-993171/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    6241
  • 访问量
    2448113