登录社区:用户名: 密码: 忘记密码 网页功能:加入收藏 设为首页 网站搜索  

文档

下载

图书

论坛

安全

源码

硬件

游戏
首页 信息 空间 VB VC Delphi Java Flash 补丁 控件 安全 黑客 电子书 笔记本 手机 MP3 杀毒 QQ群 产品库 分类信息 编程网站
  立华软件园 - 安全技术中心 - 技术文档 - 入门基础 技术文章 | 相关下载 | 电子图书 | 攻防录像 | 安全网站 | 在线论坛 | QQ群组 | 搜索   
 安全技术技术文档
  · 安全配制
  · 工具介绍
  · 黑客教学
  · 防火墙
  · 漏洞分析
  · 破解专题
  · 黑客编程
  · 入侵检测
 安全技术工具下载
  · 扫描工具
  · 攻击程序
  · 后门木马
  · 拒绝服务
  · 口令破解
  · 代理程序
  · 防火墙
  · 加密解密
  · 入侵检测
  · 攻防演示
 安全技术论坛
  · 安全配制
  · 工具介绍
  · 防火墙
  · 黑客入侵
  · 漏洞检测
  · 破解方法
 其他安全技术资源
  · 攻防演示动画
  · 电子图书
  · QQ群组讨论区
  · 其他网站资源
最新招聘信息

C++源代码游戏编程--WinMain()函数集
发表日期:2007-01-17作者:[转贴] 出处:  

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<Map[0].Hight;j++)
        for (i=0;i<Map[0].Width;i++)
        {
            *(Map[0].Data+i*Map[0].Hight+j)=reachable;
        }

    for (j=0;j<Map[0].Hight;j++)
        for (i=0;i<Map[0].Width;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();
            }
        }
    }
}


本人e-mail: fuzipin@sina,com
希望通过交流进一步提高我们的游戏开发水平,OK
我来说两句】 【发送给朋友】 【加入收藏】 【返加顶部】 【打印本页】 【关闭窗口
中搜索 C++源代码游戏编程--WinMain()函数集

 ■ [欢迎对本文发表评论]
用  户:  匿名发出:
您要为您所发的言论的后果负责,故请各位遵纪守法并注意语言文明。

最新招聘信息

关于我们 / 合作推广 / 给我留言 / 版权举报 / 意见建议 / 广告投放 / 友情链接  
Copyright ©2001-2006 Lihuasoft.net webmaster(at)lihuasoft.net
网站编程QQ群   京ICP备05001064号 页面生成时间:0.00209