📄 application.cpp
字号:
#include "application.h"
Win32Application::Win32Application()
{
m_win.SetName(APPLICATION_NAME);
}
//////////////////////////////////////////////////////////////////////////
Win32Application::~Win32Application()
{
}
//////////////////////////////////////////////////////////////////////////
int Win32Application::Create( HINSTANCE hInst, LPSTR cmdLine, int cmdShow, int width, int height )
{
// Save the intance
m_hInst = hInst;
// Create a popup-window */
m_win.InitPopup(Win32Application::WindowProc, m_hInst, cmdShow, width, height);
// Error check
if(!m_hwnd)
{
MessageBox(NULL, "Window handle not set", "ERROR", MB_OK | MB_ICONEXCLAMATION);
}
// Call our main loop and retreive value to return to Windows */
return Loop();
}
//////////////////////////////////////////////////////////////////////////////////////
bool Win32Application::Init()
{
return true;
}
//////////////////////////////////////////////////////////////////////////////////////
void Win32Application::Close()
{
//m_win.Close();
}
//////////////////////////////////////////////////////////////////////////////////////
int Win32Application::Loop()
{
MSG msg;
for( ; ; )
{
if( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
{
if( msg.message == WM_QUIT )
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if( m_win.Active() )
{
/* The function called each update */
this->CoreLoop();
}
}
return((int)msg.wParam);
}
//////////////////////////////////////////////////////////////////////////////////////
void Win32Application::CoreLoop()
{
}
//////////////////////////////////////////////////////////////////////////////////////
LRESULT CALLBACK Win32Application::WindowProc( HWND hWnd, unsigned int message, WPARAM wParam, LPARAM lParam )
{
/* Instance of the class, because we cannot call a non-static member from a static one */
static Win32Application * main = Win32Application::GetSingletonPtr();
if( !main->m_hwnd )
main->m_hwnd = hWnd;
switch( message )
{
case WM_SIZE:
main->OnSize(LOWORD(lParam), HIWORD(lParam));
return 0;
case WM_KEYDOWN:
main->OnKeyDown( (unsigned int)wParam );
return 0;
case WM_KEYUP:
main->OnKeyUp( (unsigned int)wParam );
return 0;
case WM_ACTIVATEAPP:
main->OnActivate( (BOOL)wParam);
return 0;
case WM_DESTROY:
main->OnDestroy();
main->Close(); /* Cleanup everything */
PostQuitMessage(0);
return 0;
case WM_CLOSE:
main->OnClose();
// Clean up
//main->Close();
// Quit the game
PostQuitMessage(0);
default:
break;
}
return DefWindowProc(hWnd, message, wParam,lParam);
}
//////////////////////////////////////////////////////////////////////////////////////
void Win32Application::Quit()
{
PostQuitMessage(0);
}
//////////////////////////////////////////////////////////////////////////////////////
void Win32Application::OnActivate( BOOL active )
{
m_win.SetStatus( (active == 0) ? false : true );
}
//////////////////////////////////////////////////////////////////////////////////////
void Win32Application::OnClose()
{
MessageBox(NULL, "FINT", "FINT", MB_OK);
m_win.Close();
}
//////////////////////////////////////////////////////////////////////////////////////
void Win32Application::OnDestroy()
{
//MessageBox(NULL, "DEST", "DEST", MB_OK);
// m_win.Close();
}
//////////////////////////////////////////////////////////////////////////////////////
void Win32Application::OnKeyDown( unsigned int key )
{
}
//////////////////////////////////////////////////////////////////////////////////////
void Win32Application::OnKeyUp( unsigned int key )
{
}
//////////////////////////////////////////////////////////////////////////////////////
void Win32Application::OnSize( int width, int height )
{
}
//////////////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -