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

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/10752019/viewspace-976554/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10752019/viewspace-976554/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值