博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++源代码游戏编程---WinMain()函数集(转)
阅读量:2452 次
发布时间:2019-05-10

本文共 5834 字,大约阅读时间需要 19 分钟。

C++源代码游戏编程---WinMain()函数集(转)[@more@]

  C++源代码游戏编程--WinMain()函数交流

  //******************************************************************

  //函数:WinMain()

  //功能:应用程序入口

  //******************************************************************

  int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,

  LPSTR lpCmdLine, int nCmdShow)

  {

  MSG msg;

  hInst=hInstance;

  

  //初始化主窗口

  if (!InitWindow( hInstance, nCmdShow))

  return FALSE;

  

  //初始化DirectDraw环境

  if (!InitDDraw())

  {

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

  FreeObjects();

  DestroyWindow(hWndMain);

  return FALSE;

  }

  

  //进入消息循环

  while(1)

  {

  if(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))

  {

  if(!GetMessage(&msg, NULL, 0, 0 )) return msg.wParam;

  TranslateMessage(&msg);

  DispatchMessage(&msg);

  }

  else if(bActive)

  {

  UpdateFrame();

  }

  else WaitMessage();

  }

  return msg.wParam;

  }

  ///

  //-----------------------------------------------------------------------------

  // Name: WinMain()

  // Desc: Initialization, message loop

  //-----------------------------------------------------------------------------

  int PASCAL

  WinMain(HINSTANCE hInstance,

  HINSTANCE hPrevInstance,

  LPSTR lpCmdLine,

  int nCmdShow)

  {

  MSG msg;

  if (InitApp(hInstance, nCmdShow) != DD_OK)

  return FALSE;

  while (GetMessage(&msg, NULL, 0, 0))

  {

  TranslateMessage(&msg);

  DispatchMessage(&msg);

  }

  return msg.wParam;

  }

  /

  // 主循环

  /

  int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)

  {

  MSG msg;

  if(!InitApp(hInst, nCmdShow)) return FALSE;

  while(1)

  {

  if(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))

  {

  if(!GetMessage(&msg, NULL, 0, 0 )) return msg.wParam;

  TranslateMessage(&msg);

  DispatchMessage(&msg);

  }

  else if(bActive)

  {

  Update();

  // 翻转上一层缓冲区内容到屏幕。

  Screen->Flip();

  }

  else WaitMessage();

  }

  }

  

  ///

  int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,

  LPSTR lpCmdLine, int nCmdShow)

  {

  // any windows programmer should be familiar with this

  MSG msg;

  lpCmdLine = lpCmdLine;

  hPrevInstance = hPrevInstance;

  if(!doInit(hInstance, nCmdShow))

  {

  return FALSE;

  }

  while (1)

  {

  if(PeekMessage(&msg, NULL, 0,0,PM_NOREMOVE))

  {

  if(!GetMessage(&msg, NULL,0,0))

  return msg.wParam;

  TranslateMessage(&msg);

  DispatchMessage(&msg);

  }

  else if(bActive)

  {

  fire(480, 0, 600, 50);

  // draw fire on bottom row and then flip

  while(1)

  {

  ddrval = lpDDSPrimary->Flip(NULL, DDFLIP_WAIT);

  if(ddrval == DD_OK)

  {

  break;

  }

  if(ddrval == DDERR_SURFACELOST)

  {

  if(ddrval != DD_OK)

  {

  break;

  }

  }

  if(ddrval != DDERR_WASSTILLDRAWING)

  {

  break;

  }

  }

  } // if bActive

  else

  {

  //make sure we go to sleep if have nothiing to do

  WaitMessage();

  }

  }

  

  } // win main

  //

  //-----------------------------------------------------------------------------

  // Name: WinMain()

  // Desc: 入口,初始化,进行消息循环

  //-----------------------------------------------------------------------------

  int PASCAL

  WinMain(HINSTANCE hInstance,

  HINSTANCE hPrevInstance,

  LPSTR lpCmdLine,

  int nCmdShow)

  {

  MSG msg;

  if (InitApp(hInstance, nCmdShow) != DD_OK)

  return FALSE;

  Map[0].Width=width;

  Map[0].Hight=height;

  Map[0].Data=(char *)malloc( Map[0].Width * Map[0].Hight );

  Map[0].Pro=(char *)malloc( Map[0].Width * Map[0].Hight );

  //将地图全部置为可到达

  int i,j;

  reachable=1;

  for (j=0;j  for (i=0;i  {

  *(Map[0].Data+i*Map[0].Hight+j)=reachable;

  }

  for (j=0;j  for (i=0;i  {

  *(Map[0].Pro+i*Map[0].Hight+j)=select_pro;

  }

  //消息循环

  while (GetMessage(&msg, NULL, 0, 0))

  {

  TranslateMessage(&msg);

  DispatchMessage(&msg);

  }

  return msg.wParam;

  }

  //-----------------------------------------------------------------------------

  // Name: WinMain()

  // Desc: Entry point to the program. Initializes everything and calls

  // UpdateFrame() when idle from the message pump.

  //-----------------------------------------------------------------------------

  int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, int nCmdShow )

  {

  MSG msg;

  HWND hWnd;

  ZeroMemory( &g_Sprite, sizeof(SPRITE_STRUCT) * NUM_SPRITES );

  srand( GetTickCount() );

  if( FAILED( WinInit( hInst, nCmdShow, &hWnd ) ) )

  return FALSE;

  // Make a timer go off to re-init the table of random values every once in a while

  SetTimer( hWnd, 0, 1500, NULL );

  if( FAILED( InitDirectDraw( hWnd ) ) )

  {

  if( g_pDisplay )

  g_pDisplay->GetDirectDraw()->SetCooperativeLevel( NULL, DDSCL_NORMAL );

  MessageBox( hWnd, TEXT("DirectDraw init failed. ")

  TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),

  MB_ICONERROR | MB_OK );

  return FALSE;

  }

  g_dwLastTick = timeGetTime();

  while( TRUE )

  {

  // Look for messages, if none are found then

  // update the state and display it

  if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )

  {

  if( 0 == GetMessage(&msg, NULL, 0, 0 ) )

  {

  // WM_QUIT was posted, so exit

  return (int)msg.wParam;

  }

  // Translate and dispatch the message

  TranslateMessage( &msg );

  DispatchMessage( &msg );

  }

  else

  {

  if( g_bActive )

  {

  // Move the sprites, blt them to the back buffer, then

  // flip or blt the back buffer to the primary buffer

  if( FAILED( ProcessNextFrame() ) )

  {

  SAFE_DELETE( g_pDisplay );

  MessageBox( hWnd, TEXT("Displaying the next frame failed. ")

  TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),

  MB_ICONERROR | MB_OK );

  return FALSE;

  }

  }

  else

  {

  // Make sure we go to sleep if we have nothing else to do

  WaitMessage();

  // Ignore time spent inactive

  g_dwLastTick = timeGetTime();

  }

  }

  }

  

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

转载于:http://blog.itpub.net/8225414/viewspace-951669/

你可能感兴趣的文章
node压缩css_Node.js CSS压缩器:clean-css
查看>>
JavaScript CSS助手
查看>>
邪恶的AJAX:使用jQuery的Spyjax
查看>>
css指针悬停_CSS指针事件
查看>>
目标检测 多分辨率检测_检测视频分辨率
查看>>
ip校验和 tcp校验和_如何校验和
查看>>
pandora nohup_如何更好地训练您的Pandora广播电台
查看>>
显示器选三星还是飞利浦_如何为飞利浦色相灯设置计时器
查看>>
vm macos 启用3d_如何在macOS中启用夜班以减轻眼睛疲劳
查看>>
白色裤子为什么会沾上蓝色_什么是蓝色的,为什么它可以在Mac上运行?
查看>>
apple默认备份位置_如何将Apple Maps默认设置为步行路线
查看>>
固件中启用的虚拟化否_哪些固件或硬件机制可启用强制关机?
查看>>
如何还原桌面图标_如何为Windows 10桌面图标还原或更改文本的默认外观?
查看>>
ios numlock_从“提示”框:默认情况下启用NumLock,无广告的iOS应用和立体声供电的派对灯...
查看>>
询问HTG:白噪声屏幕保护程序,有效的文件命名以及从密码泄露中恢复
查看>>
dropbox文件_Dropbox即将发布的扩展程序更新将添加更多文件编辑支持,包括Pixlr照片...
查看>>
google hdr+_更好的隐私权控制使Google+死了
查看>>
网络串流_串流NBA篮球的最便宜方式(无需电缆)
查看>>
reddit_如何将多个子Reddit与多个Reddit合并
查看>>
如何在iPhone或iPad上使用Safari下载文件
查看>>