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

📄 mgcapplication.h

📁 《3D游戏引擎设计》的源码
💻 H
字号:
// Magic Software, Inc.
// http://www.magic-software.com
// Copyright (c) 2000, All Rights Reserved
//
// Source code from Magic Software is supplied under the terms of a license
// agreement and may not be copied or disclosed except in accordance with the
// terms of that agreement.  The various license agreements may be found at
// the Magic Software web site.  This file is subject to the license
//
// FREE SOURCE CODE
// http://www.magic-software.com/License/free.pdf

#ifndef MGCAPPLICATION_H
#define MGCAPPLICATION_H

#include <windows.h>
#include <commctrl.h>
#include "MgcCommand.h"
#include "MgcTurret.h"

class MgcApplication
{
public:
    // This must be implemented in the source file for the
    // MgcApplication-derived class.
    static MgcApplication* Create ();

    // construction
    MgcApplication
    (
        const char* pWindowCaption,     // caption of window
        unsigned int uiWidth,           // client window width
        unsigned int uiHeight,          // client window height
        unsigned int uiMenuID = 0,      // menu resource ID
        unsigned int uiStatusPanes = 0, // number of panes in status window
        DWORD dwWindowStyle = WS_OVERLAPPEDWINDOW
                                        // client window style
    );

    // destruction
    virtual ~MgcApplication ();

    // window initialization and attributes
    static bool IsActive () { return ms_pApplication != 0; }
    static void SetWindowHandle (HWND hWnd) { ms_hWnd = hWnd; }
    static HWND GetWindowHandle () { return ms_hWnd; }
    static void SetInstanceHandle (HINSTANCE hI) { ms_hInstance = hI; }
    static HINSTANCE GetInstanceHandle () { return ms_hInstance; }
    static const char* GetWindowClassName () { return ms_windowClassName; }
    DWORD GetWindowStyle () { return m_dwWindowStyle; }

    // command line parsing
    static void SetCommandLine (char* pCommandLine);
    static MgcCommand* GetCommand () { return ms_pCommand; }

    // window caption
    void SetWindowCaption (char* pCaption);
    const char* GetWindowCaption () const { return m_pWindowCaption; }

    // window size
    void SetWidth (unsigned int uiWidth) { m_uiWidth = uiWidth; }
    unsigned int GetWidth () const { return m_uiWidth; }
    void SetHeight (unsigned int uiHeight) { m_uiHeight = uiHeight; }
    unsigned int GetHeight () const { return m_uiHeight; }

    // menu methods
    unsigned int GetMenuID () const { return m_uiMenuID; }

    // status bar methods
    static void SetStatusWindowHandle (HWND hWnd) { ms_hStatusWnd = hWnd; }
    static HWND GetStatusWindowHandle () { return ms_hStatusWnd; }
    unsigned int GetStatusPanes () { return m_uiStatusPanes; }


    // This is called by WinMain after ShowWindow and UpdateWindow, but before
    // the idle loop.  The window handle is valid at this point, so any
    // MgcApplication-derived class may safely use ms_hWnd in this routine.
    // The routine should be used for allocating resources and initializing
    // any data values.
    virtual bool Initialize () { return false; }

    // The message pump.  The application should do all its real work here.
    virtual void OnIdle () { /**/ }

    // This is called by WinMain after the idle loop exits.  The application
    // should free up its resources in this routine.
    virtual void Terminate () { /**/ }


    // WinProc callbacks. Return true if event processed or if you want
    // Windows to further process the event.  Return false otherwise.

    // creation and destruction
    virtual bool WmCreate (LPCREATESTRUCT lpCS);
    virtual bool WmDestroy ();

    // command processing
    virtual bool WmCommand (WORD wNotifyCode, WORD wID, HWND hwndCtl);

    // window resizing and painting
    virtual bool WmPaint (HDC hDC);
    virtual bool WmEraseBkgnd (HDC hDC);
    virtual bool WmMove (int iXPos, int iYPos);
    virtual bool WmSize (int iWidth, int iHeight, unsigned int uiSizeType);

    // keyboard
    virtual bool WmSysChar (char cCharCode, long lKeyData);
    virtual bool WmSysKeyDown (int iVirtKey, long lKeyData);
    virtual bool WmSysKeyUp (int iVirtKey, long lKeyData);
    virtual bool WmChar (char cCharCode, long lKeyData);
    virtual bool WmKeyDown (int iVirtKey, long lKeyData);
    virtual bool WmKeyUp (int iVirtKey, long lKeyData);

    // mouse
    virtual bool WmLButtonDown (int iXPos, int iYPos, unsigned int uiKeys);
    virtual bool WmLButtonUp (int iXPos, int iYPos, unsigned int uiKeys);
    virtual bool WmRButtonDown (int iXPos, int iYPos, unsigned int uiKeys);
    virtual bool WmRButtonUp (int iXPos, int iYPos, unsigned int uiKeys);
    virtual bool WmMouseMove (int iXPos, int iYPos, unsigned int uiKeys);

    // default processing
    virtual bool WmDefault (WPARAM wparam, LPARAM lparam);

    // performance measurements
    static long double GetCurrentTimeInSeconds ();
    void MeasureTime ();
    void DrawFrameRate ();
    void UpdateClicks ();
    void ResetTime ();

protected:
    static HWND ms_hWnd;
    static HWND ms_hStatusWnd;
    static HINSTANCE ms_hInstance;
    static MgcApplication* ms_pApplication;
    static char ms_windowClassName[];
    static MgcCommand* ms_pCommand;

    char* m_pWindowCaption;
    unsigned int m_uiWidth;
    unsigned int m_uiHeight;
    unsigned int m_uiMenuID;
    unsigned int m_uiStatusPanes;
    DWORD m_dwWindowStyle;

    // frame rate measurements
    // performance measurements
    MgcReal m_fSecondsPerTick;
    MgcReal m_fLastTime;
    MgcReal m_fAccumTime;
    int m_iClicks;
    int m_iTimer;
    int m_iMaxTimer;
};

#endif

⌨️ 快捷键说明

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