⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mgcapplication.cpp

📁 《3D游戏引擎设计》的源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:

        wparam = 0;
        lparam = 0;
        SendMessage(hStatusWnd,WM_PAINT,wparam,lparam);

        delete[] panes;
    }

    return true;
}
//---------------------------------------------------------------------------
LRESULT CALLBACK WinProc (HWND hWnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
    switch ( msg ) 
    {
        case WM_CREATE:
        {
            LPCREATESTRUCT lpCS = LPCREATESTRUCT(lparam);
            if ( pTheApp->WmCreate(lpCS) )
                return 0;
            else
                return -1;
        }
        case WM_DESTROY:
        {
            pTheApp->WmDestroy();
            PostQuitMessage(0);
            return 0;
        }
        case WM_PAINT:
        {
            PAINTSTRUCT ps;
            HDC hDC = BeginPaint(hWnd,&ps);
            if ( pTheApp->WmPaint(hDC) )
            {
                EndPaint(hWnd,&ps);
                return 0;
            }
            EndPaint(hWnd,&ps);
            break;
        }
        case WM_ERASEBKGND:
        {
            HDC hDC = HDC(hWnd);
            if ( pTheApp->WmEraseBkgnd(hDC) )
                return 0;
            break;
        }
        case WM_MOVE:
        {
            int xPos = int(LOWORD(lparam));
            int yPos = int(HIWORD(lparam));
            if ( pTheApp->WmMove(xPos,yPos) )
                return 0;
            break;
        }
        case WM_SIZE:
        {
            int iWidth = int(LOWORD(lparam));
            int iHeight = int(HIWORD(lparam));
            unsigned int uiSizeType = (unsigned int)(wparam);
            if ( pTheApp->WmSize(iWidth,iHeight,uiSizeType) )
                return 0;
            break;
        }
        case WM_COMMAND:
        {
            WORD wNotifyCode = HIWORD(wparam);
            WORD wID = LOWORD(wparam);
            HWND hwndCtl = HWND(lparam);
            if ( pTheApp->WmCommand(wNotifyCode,wID,hwndCtl) )
                return 0;
            break;
        }
        case WM_SYSCHAR:
        {
            char cCharCode = char(wparam);
            long lKeyCode = long(lparam);
            if ( pTheApp->WmSysChar(cCharCode,lKeyCode) )
                return 0;
            break;
        }
        case WM_SYSKEYDOWN:
        {
            int iVirtKey = int(wparam);
            long lKeyCode = long(lparam);
            if ( pTheApp->WmSysKeyDown(iVirtKey,lKeyCode) )
                return 0;
            break;
        }
        case WM_SYSKEYUP:
        {
            int iVirtKey = int(wparam);
            long lKeyCode = long(lparam);
            if ( pTheApp->WmSysKeyUp(iVirtKey,lKeyCode) )
                return 0;
            break;
        }
        case WM_CHAR:
        {
            char cCharCode = char(wparam);
            long lKeyData = long(lparam);
            if ( pTheApp->WmChar(cCharCode,lKeyData) )
                return 0;
            break;
        }
        case WM_KEYDOWN:
        {
            int iVirtKey = int(wparam);
            long lKeyData = long(lparam);
            if ( pTheApp->WmKeyDown(iVirtKey,lKeyData) )
                return 0;
            break;
        }
        case WM_KEYUP:
        {
            int iVirtKey = int(wparam);
            long lKeyData = long(lparam);
            if ( pTheApp->WmKeyUp(iVirtKey,lKeyData) )
                return 0;
            break;
        }
        case WM_LBUTTONDOWN:
        {
            int iXPos = int(LOWORD(lparam));
            int iYPos = int(HIWORD(lparam));
            unsigned int uiKeys = (unsigned int)(wparam);
            if ( pTheApp->WmLButtonDown(iXPos,iYPos,uiKeys) )
                return 0;
            break;
        }
        case WM_LBUTTONUP:
        {
            int iXPos = int(LOWORD(lparam));
            int iYPos = int(HIWORD(lparam));
            unsigned int uiKeys = (unsigned int)(wparam);
            if ( pTheApp->WmLButtonUp(iXPos,iYPos,uiKeys) )
                return 0;
            break;
        }
        case WM_RBUTTONDOWN:
        {
            int iXPos = int(LOWORD(lparam));
            int iYPos = int(HIWORD(lparam));
            unsigned int uiKeys = (unsigned int)(wparam);
            if ( pTheApp->WmRButtonDown(iXPos,iYPos,uiKeys) )
                return 0;
            break;
        }
        case WM_RBUTTONUP:
        {
            int iXPos = int(LOWORD(lparam));
            int iYPos = int(HIWORD(lparam));
            unsigned int uiKeys = (unsigned int)(wparam);
            if ( pTheApp->WmRButtonUp(iXPos,iYPos,uiKeys) )
                return 0;
            break;
        }
        case WM_MOUSEMOVE:
        {
            int iXPos = int(LOWORD(lparam));
            int iYPos = int(HIWORD(lparam));
            unsigned int uiKeys = (unsigned int)(wparam);
            if ( pTheApp->WmMouseMove(iXPos,iYPos,uiKeys) )
                return 0;
            break;
        }
        default:
        {
            if ( pTheApp->WmDefault(wparam,lparam) )
                return 0;
            break;
        }
    }

    return DefWindowProc(hWnd,msg,wparam,lparam);
}
//---------------------------------------------------------------------------
int WINAPI WinMain (HINSTANCE hI, HINSTANCE hPI, LPSTR cmdline, int iWinMode)
{
    if ( MgcApplication::IsActive() )
    {
        // only one instance of application allowed
        MessageBox(NULL,"Application already active",
            MgcApplication::GetWindowClassName(),MB_OK);
        return 0;
    }

    // let the application know about the command line
    MgcApplication::SetCommandLine(cmdline);

    // create the application
    pTheApp = MgcApplication::Create();
    if ( !pTheApp )
    {
        MessageBox(NULL,"Unable to create application",
            MgcApplication::GetWindowClassName(),MB_OK);
        return 0;
    }

    // register the window class
    WNDCLASS wc;
    wc.style         = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc   = WinProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hI;
    wc.hIcon         = LoadIcon(NULL,IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL,IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszClassName = MgcApplication::GetWindowClassName();

    // register menu (if requested)
    if ( pTheApp->GetMenuID() )
        wc.lpszMenuName  = MAKEINTRESOURCE(pTheApp->GetMenuID());
    else
        wc.lpszMenuName = 0;

    RegisterClass(&wc);

    // require the window to have the specified client area
    RECT rect = { 0, 0, pTheApp->GetWidth()-1, pTheApp->GetHeight()-1 };
    AdjustWindowRect(&rect,pTheApp->GetWindowStyle(),pTheApp->GetMenuID());

    // create the application window
    HWND hWnd = CreateWindow
    (
        MgcApplication::GetWindowClassName(),
        pTheApp->GetWindowCaption(),
        pTheApp->GetWindowStyle(),
        CW_USEDEFAULT,          // initial x position
        CW_USEDEFAULT,          // initial y position
        rect.right-rect.left+1,	// initial width
        rect.bottom-rect.top+1,	// initial height
        NULL,                   // parent window handle
        NULL,                   // window menu handle
        hI,                     // program instance handle
        NULL                    // creation parameters
    );

    MgcApplication::SetWindowHandle(hWnd);
    MgcApplication::SetInstanceHandle(hI);

    // create status window (if requested)
    if ( pTheApp->GetStatusPanes() )
    {
        InitCommonControls();

        HWND hStatusWnd = CreateWindow
        (
            STATUSCLASSNAME,
            "",
            WS_CHILD | WS_VISIBLE,
            0, 0, 0, 0,
            hWnd,
            NULL,
            hI,
            NULL
        );

        MgcApplication::SetStatusWindowHandle(hStatusWnd);
    }

    // display the window
    ShowWindow(hWnd,iWinMode);
    UpdateWindow(hWnd);

    // allow the application to initialize before starting the message pump
    MSG msg;
    if ( pTheApp->Initialize() )
    {
        while ( TRUE )
        {
            if ( PeekMessage(&msg,NULL,0,0,PM_REMOVE) )
            {
                if ( msg.message == WM_QUIT )
                    break;
                
                HACCEL hAccel = NULL;
                if ( !TranslateAccelerator(hWnd,hAccel,&msg) )
                {
                    TranslateMessage(&msg);
                    DispatchMessage(&msg);
                }
            }
            else
            {
                pTheApp->OnIdle();
            }
        }
    }

    pTheApp->Terminate();

    delete pTheApp;

    return msg.wParam;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -