?? wndmsg.cpp
字號:
#include <windows.h>
#include <commctrl.h>
#include "WndMsg.h"
#include "MsgHelp.h"
#include "BaseKey.h"
#include "CAppWnd.h"
#include "CTimer.h"
#include "CD3DApp.h"
#include "CShakingCamera.h"
#include "CMenu.h"
#include "CStatusBar.h"
#include "CBlockFollowing.h"
#include "CGameManager.h"
#include "CGameState.h"
extern bool g_IsActive;
extern CAppWnd theAppWnd; //窗口
extern CTimer theTimer;
extern CD3DApp theD3DApp; //D3D設備
extern CShakingCamera theCamera;
extern CMenu theMenu; //菜單
extern CStatusBar theStatusBar; //狀態欄
extern CGameManager theGameManager; //游戲邏輯管理
extern CBlockFollowing theBlockFollowing;
extern CGameState theGameState;
///////////////////////////////////////////////////////////
//初始化圖形層:
///////////////////////////////////////////////////////////
bool InitLogic()
{
return theGameManager.Init();
}
///////////////////////////////////////////////////////////
//初始化圖形層:
///////////////////////////////////////////////////////////
void FreeLogic()
{
theGameManager.Free();
}
///////////////////////////////////////////////////////////
//初始化邏輯層:
///////////////////////////////////////////////////////////
bool InitGraphics( HWND hwnd )
{
if ( theD3DApp.InitD3D( true, hwnd ) )
{
return theD3DApp.InitApp();
}
return false;
}
///////////////////////////////////////////////////////////
//初始化用戶交互層:
///////////////////////////////////////////////////////////
bool InitGUI( HWND hwnd, HINSTANCE hInstance )
{
InitCommonControls();
//theToolBar1.Init( hwnd, hInstance );
theStatusBar.Init( hwnd, hInstance );
return true;
}
///////////////////////////////////////////////////////////
//程序結束工作
///////////////////////////////////////////////////////////
void OnQuit()
{
FreeLogic();
theD3DApp.FreeApp();
theD3DApp.FreeD3D();
theMenu.Free();
theStatusBar.Free();
PostQuitMessage( NULL );
}
///////////////////////////////////////////////////////////
//響應按鍵函數
///////////////////////////////////////////////////////////
void OnKeyDown( WPARAM wP )
{
switch ( wP )
{
/*case VK_A:
theCamera.strafe( 0.1f );
break;
case VK_D:
theCamera.strafe( -0.1f );
break;
case VK_W:
theCamera.fly( -0.1f );
break;
case VK_S:
theCamera.fly( 0.1f );
break;
case VK_Q:
theCamera.RotationY( 0.1f );
break;
case VK_E:
theCamera.RotationY( -0.1f );
break;
case VK_F1:
theCamera.LookAtX( -6.0f );
break;
case VK_F2:
theCamera.LookAtY( -6.0f );
break;
case VK_F3:
theCamera.LookAtZ( -6.0f );
break;
case VK_F4:
theCamera.Slope45();
break;*/
case VK_LEFT:
theBlockFollowing.Move( true );
break;
case VK_RIGHT:
theBlockFollowing.Move( false );
break;
case VK_UP:
theBlockFollowing.Rotate();
break;
case VK_DOWN:
theBlockFollowing.Drop();
break;
case VK_RETURN:
theGameState.PauseGame();
break;
}
}
///////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////
void OnGUIItem( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
//if ( !theToolBar1.HandleMsg( hwnd, msg, wParam, lParam ) )
theMenu.HandleMsg( hwnd, msg, wParam, lParam );
}
///////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////
void OnSize( LPARAM lParam )
{
RECT rc, rcSB;
long WndHeight, SBHeight, x, y;
long width;
HWND hSB = theStatusBar.GetHWnd();
HWND hWnd = theAppWnd.GetHWnd();
//HWND hTB = theToolBar1.GetHWnd(); //工具條(如果沒有工具條,設0)
//RECT rcTB;
long TBHeight = 0;
GetWindowRect( hSB, &rcSB );
GetClientRect( hWnd, &rc );
//GetWindowRect( hTB, &rcTB );
SBHeight = rcSB.bottom - rcSB.top;
//TBHeight = rcTB.bottom - rcTB.top;
WndHeight = rc.bottom - rc.top - SBHeight - TBHeight;
width = rc.right - rc.left;
x = LOWORD( lParam );
y = HIWORD( lParam );
SetWindowPos( theAppWnd.GetHDisplayWnd(), HWND_TOP,
0, TBHeight,
width,
WndHeight,
SWP_SHOWWINDOW ); //調整子窗口
//SendMessage( hTB, TB_AUTOSIZE, 0, 0 ); //調整工具條
MoveWindow( hSB, 0, y - SBHeight, x, y, TRUE ); //調整狀態欄
theStatusBar.SetParts();
}
///////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////
void OnLoop()
{
theGameManager.OnGameRun();
theCamera.Shake();
theD3DApp.Render();
theTimer.UpdateFps();
}
void ActiveWnd()
{
g_IsActive = true;
SetWindowText( theAppWnd.GetHWnd(), "RussiaGame3D-Active" );
}
void InactiveWnd()
{
g_IsActive = false;
SetWindowText( theAppWnd.GetHWnd(), "RussiaGame3D-Inactive" );
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -