📄 wndmain.cpp
字号:
#include "CAppWnd.h"
#include "WndMsg.h"
#include "CMenu.h"
#include "MsgHelp.h"
extern CAppWnd theAppWnd;
extern CMenu theMenu;
bool g_IsActive; //程序激活标志
const char szWndName[] = "wnd"; //窗口的标题
/////////////////////////////////////////////////////////////////
//程序入口函数
/////////////////////////////////////////////////////////////////
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nShowCmd )
{
MSG msg;
g_IsActive = true;
ZeroMemory( &msg, sizeof(msg) );
theAppWnd.SetHInstance( hInstance ); //设置程序实例
if ( !theMenu.Init( NULL, hInstance ) ) //菜单初始化
{
Warn( "Menu init failed!" );
return 0;
}
theAppWnd.CreateWnd( szWndName, theMenu.GetHMenu() ); //创建窗口
if ( !InitGraphics( theAppWnd.GetHDisplayWnd() ) ) //D3D初始化
{
return 0;
}
if ( !InitLogic() )
return 0;
while ( msg.message != WM_QUIT )
{
if ( g_IsActive ) //如果在激活状态
{
if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) != NULL )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
OnLoop(); //逻辑,渲染
}
}
else //如果不在激活状态
{
if ( GetMessage( &msg, NULL, NULL, NULL ) != NULL )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
}
return msg.wParam;
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
WINDOWPLACEMENT wp;
switch ( msg )
{
case WM_CREATE:
if ( hwnd != theAppWnd.GetHDisplayWnd() )
InitGUI( hwnd, theAppWnd.GetHInstance() );
break;
case WM_ACTIVATE:
if ( wParam == WA_ACTIVE )
{
ActiveWnd();
}
else if ( wParam != WA_ACTIVE )
{
wp.length = sizeof(wp);
GetWindowPlacement( hwnd, &wp );
if ( wp.showCmd == SW_SHOWMINIMIZED )
{
InactiveWnd();
}
else
{
InactiveWnd();
}
}
return 0;
case WM_SETFOCUS:
if ( lParam == 0x0000 || wParam == 0x0000 )
{
ActiveWnd();
}
return 0;
//case WM_PAINT:
//break;
case WM_SIZE:
OnSize( lParam );
break;
case WM_CLOSE: //关闭窗口
OnQuit();
break;
case WM_KEYDOWN: //捕获按键消息
OnKeyDown( wParam );
return 0;
case WM_COMMAND:
OnGUIItem( hwnd, msg, wParam, lParam );
return 0;
}
return DefWindowProc( hwnd, msg, wParam, lParam );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -