📄 mgcapplication.cpp
字号:
// 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
#include "MgcApplication.h"
#include "MgcRTLib.h"
#pragma comment(lib,"comctl32.lib")
#pragma comment(lib,"MgcCore.lib")
#pragma comment(lib,"MgcEngine.lib")
//---------------------------------------------------------------------------
HWND MgcApplication::ms_hWnd = 0;
HWND MgcApplication::ms_hStatusWnd = 0;
HINSTANCE MgcApplication::ms_hInstance = 0;
MgcApplication* MgcApplication::ms_pApplication = 0;
MgcCommand* MgcApplication::ms_pCommand = 0;
char MgcApplication::ms_windowClassName[] = "Magic Application";
//---------------------------------------------------------------------------
MgcApplication::MgcApplication (const char* pWindowCaption,
unsigned int uiWidth, unsigned int uiHeight, unsigned int uiMenuID,
unsigned int uiStatusPanes, DWORD dwWindowStyle)
{
// text for window caption
if ( pWindowCaption && pWindowCaption[0] )
{
m_pWindowCaption = new char[strlen(pWindowCaption)+1];
strcpy(m_pWindowCaption,pWindowCaption);
}
else
{
m_pWindowCaption = new char[strlen(ms_windowClassName)+1];
strcpy(m_pWindowCaption,ms_windowClassName);
}
// client window dimensions
m_uiWidth = uiWidth;
m_uiHeight = uiHeight;
// client window style
m_dwWindowStyle = dwWindowStyle | WS_CLIPCHILDREN;
// menu resource ID
m_uiMenuID = uiMenuID;
// number of panes in status bar
m_uiStatusPanes = uiStatusPanes;
ms_pApplication = this;
// performance measurements (display in status pane 0)
LARGE_INTEGER ticksPerSecond;
QueryPerformanceFrequency(&ticksPerSecond);
m_fSecondsPerTick = MgcReal(1.0/(double)ticksPerSecond.LowPart);
m_fLastTime = -1.0;
m_fAccumTime = 0.0;
m_iClicks = 0;
m_iTimer = 1;
m_iMaxTimer = 30;
}
//---------------------------------------------------------------------------
MgcApplication::~MgcApplication ()
{
delete[] m_pWindowCaption;
delete ms_pCommand;
ms_hWnd = 0;
ms_hStatusWnd = 0;
ms_hInstance = 0;
ms_pApplication = 0;
ms_pCommand = 0;
}
//---------------------------------------------------------------------------
void MgcApplication::SetWindowCaption (char* pCaption)
{
delete[] m_pWindowCaption;
m_pWindowCaption = new char[strlen(pCaption)+1];
strcpy(m_pWindowCaption,pCaption);
SetWindowText(ms_hWnd,m_pWindowCaption);
}
//---------------------------------------------------------------------------
void MgcApplication::SetCommandLine (char* pCommandLine)
{
if ( !pCommandLine )
return;
int length = strlen(pCommandLine);
if ( length == 0 )
return;
// strip off quotes if command line was built from double-clicking a file
char* pTemp = new char[length+1];
if ( pCommandLine[0] == '\"' )
{
strcpy(pTemp,pCommandLine+1); // remove leading quote
if ( pCommandLine[length-1] == '\"' )
pTemp[length-2] = '\0'; // remove trailing quote
}
else
strcpy(pTemp,pCommandLine);
ms_pCommand = new MgcCommand(pTemp);
delete[] pTemp;
}
//---------------------------------------------------------------------------
long double MgcApplication::GetCurrentTimeInSeconds ()
{
LARGE_INTEGER freq, counter;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&counter);
long double dNumer = (long double) counter.QuadPart;
long double dDenom = (long double) freq.QuadPart;
return dNumer/dDenom;
}
//---------------------------------------------------------------------------
void MgcApplication::MeasureTime ()
{
// start performance measurements
LARGE_INTEGER curr;
if ( m_fLastTime == -1.0 )
{
QueryPerformanceCounter(&curr);
m_fLastTime = curr.LowPart * m_fSecondsPerTick;
m_fAccumTime = 0.0;
m_iClicks = 0;
}
// measure time
QueryPerformanceCounter(&curr);
MgcReal fCurrTime = curr.LowPart * m_fSecondsPerTick;
MgcReal fDelta = fCurrTime - m_fLastTime;
m_fLastTime = fCurrTime;
m_fAccumTime += fDelta;
}
//---------------------------------------------------------------------------
void MgcApplication::DrawFrameRate ()
{
if ( --m_iTimer == 0 )
{
MgcReal fFrameRate;
if ( m_fAccumTime > 0.0 )
fFrameRate = m_iClicks/m_fAccumTime;
else
fFrameRate = 0.0;
char msg[32];
sprintf(msg,"fps: %.1f",fFrameRate);
unsigned int uiPane = 0;
HWND hStatusWnd = GetStatusWindowHandle();
SendMessage(hStatusWnd,SB_SETTEXT,(WPARAM)uiPane,(LPARAM)msg);
SendMessage(hStatusWnd,WM_PAINT,0,0);
m_iTimer = m_iMaxTimer;
}
}
//---------------------------------------------------------------------------
void MgcApplication::UpdateClicks ()
{
m_iClicks++;
}
//---------------------------------------------------------------------------
void MgcApplication::ResetTime ()
{
m_fLastTime = -1.0;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Windows95 WinProc and WinMain routines
//---------------------------------------------------------------------------
static MgcApplication* pTheApp = 0;
//---------------------------------------------------------------------------
bool MgcApplication::WmCreate (LPCREATESTRUCT lpCS)
{
return true;
}
//---------------------------------------------------------------------------
bool MgcApplication::WmDestroy ()
{
return true;
}
//---------------------------------------------------------------------------
bool MgcApplication::WmEraseBkgnd (HDC hDC)
{
return false;
}
//---------------------------------------------------------------------------
bool MgcApplication::WmMove (int iXPos, int iYPos)
{
return false;
}
//---------------------------------------------------------------------------
bool MgcApplication::WmPaint (HDC hDC)
{
return false;
}
//---------------------------------------------------------------------------
bool MgcApplication::WmCommand (WORD wNotifyCode, WORD wID, HWND hwndCtl)
{
return false;
}
//---------------------------------------------------------------------------
bool MgcApplication::WmSysChar (char cCharCode, long lKeyData)
{
return false;
}
//---------------------------------------------------------------------------
bool MgcApplication::WmSysKeyDown (int iVirtKey, long lKeyData)
{
return false;
}
//---------------------------------------------------------------------------
bool MgcApplication::WmSysKeyUp (int iVirtKey, long lKeyData)
{
return false;
}
//---------------------------------------------------------------------------
bool MgcApplication::WmChar (char cCharCode, long lKeyData)
{
return false;
}
//---------------------------------------------------------------------------
bool MgcApplication::WmKeyDown (int iVirtKey, long lKeyData)
{
return false;
}
//---------------------------------------------------------------------------
bool MgcApplication::WmKeyUp (int iVirtKey, long lKeyData)
{
return false;
}
//---------------------------------------------------------------------------
bool MgcApplication::WmLButtonDown (int iXPos, int iYPos, unsigned int uiKeys)
{
return false;
}
//---------------------------------------------------------------------------
bool MgcApplication::WmLButtonUp (int iXPos, int iYPos, unsigned int uiKeys)
{
return false;
}
//---------------------------------------------------------------------------
bool MgcApplication::WmRButtonDown (int iXPos, int iYPos, unsigned int uiKeys)
{
return false;
}
//---------------------------------------------------------------------------
bool MgcApplication::WmRButtonUp (int iXPos, int iYPos, unsigned int uiKeys)
{
return false;
}
//---------------------------------------------------------------------------
bool MgcApplication::WmMouseMove (int iXPos, int iYPos, unsigned int uiKeys)
{
return false;
}
//---------------------------------------------------------------------------
bool MgcApplication::WmDefault (WPARAM wp, LPARAM lp)
{
return false;
}
//---------------------------------------------------------------------------
bool MgcApplication::WmSize (int iWidth, int iHeight, unsigned int uiSizeType)
{
// let application know of new client dimensions
pTheApp->SetWidth(iWidth);
pTheApp->SetHeight(iHeight);
unsigned int uiNumPanes = pTheApp->GetStatusPanes();
if ( uiNumPanes )
{
// resize the status window
HWND hStatusWnd = pTheApp->GetStatusWindowHandle();
WPARAM wparam = uiSizeType;
LPARAM lparam = MAKELPARAM(iWidth,iHeight);
SendMessage(hStatusWnd,WM_SIZE,wparam,lparam);
// specify number of panes and repaint
RECT rect;
GetClientRect(pTheApp->GetWindowHandle(),&rect);
int* panes = new int[uiNumPanes];
for (unsigned int i = 0; i < uiNumPanes-1; i++)
panes[i] = (i+1)*rect.right/uiNumPanes;
panes[uiNumPanes-1] = rect.right;
wparam = WPARAM(uiNumPanes);
lparam = LPARAM(panes);
SendMessage(hStatusWnd,SB_SETPARTS,wparam,lparam);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -