📄 appcom.h
字号:
#include "windows.h"
#include "resource.h"
#include "stdio.h"
#ifndef APPCOM_H
#define APPCOM_H
typedef int (*PUPDATEFRAME)(LONG);
//============Golable Var==================
typedef struct struct_AppData
{
TCHAR* szClassName; //窗口的类名
TCHAR* szAppTitle; //窗口的标题
HWND hWnd; //窗口的句柄
HINSTANCE hApp; //程序的实例句柄
HACCEL hAccel; //快捷键
BOOL bIsActive; //游戏是否激活
int fps; //
}APPDATA,*LPAPPDATA;
APPDATA g_AppData;
//============================================
extern TCHAR szClassName[];
extern TCHAR szAppTitle[];
//==========Golable Function==================
extern RunApp(LPSTR ,int);
extern LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
//============================================
//============================================
//Function Name : CreateExcApp
//Description: 创建一个独占模式的应用
//============================================
//================================================================
// Function Name: CreateNormalApp
// Description: 创建一个普通模式的应用
//================================================================
BOOL CreateApp(int nCmdShow=SW_SHOW,ULONG uStyle=WS_OVERLAPPEDWINDOW)
{
WNDCLASSEX wndclass ;
wndclass.cbSize = sizeof (wndclass) ;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = g_AppData.hApp ;
wndclass.hIcon = LoadIcon (g_AppData.hApp, MAKEINTRESOURCE(IDI_ICON1)) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject(GRAY_BRUSH) ;
wndclass.lpszMenuName = LPSTR(IDR_MENU1);
wndclass.lpszClassName = g_AppData.szClassName;
wndclass.hIconSm = LoadIcon (g_AppData.hApp, MAKEINTRESOURCE(IDI_ICON2)) ;
// Register the class
RegisterClassEx(&wndclass);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++
//================Create Window===============================
g_AppData.hWnd = CreateWindowEx(0, // Extended style
g_AppData.szClassName,
g_AppData.szAppTitle,
uStyle&~WS_SIZEBOX&~WS_MAXIMIZEBOX,
190,
20,
420,
550,
NULL, // Handle of parent
NULL, // Handle to menu
g_AppData.hApp, // Application instance
NULL); // Additional data
//=============================================================
if (!g_AppData.hWnd)
return FALSE;
RECT rct;
ShowWindow(g_AppData.hWnd,nCmdShow);
UpdateWindow(g_AppData.hWnd);
return TRUE;
}
//=====================================================
// Function Name: WinMain
// Description
//=====================================================
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
g_AppData.hApp=hInstance;
g_AppData.szClassName=szClassName;
g_AppData.szAppTitle=szAppTitle;
g_AppData.bIsActive=FALSE;
g_AppData.fps=0;
return RunApp(lpCmdLine,nCmdShow);
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++
//================================================================
//
// Function name: MainLoop
// Description : the Main Message Loop
//
//===============================================================
int MainLoop( PUPDATEFRAME pfUpdateFrame=NULL )
{
MSG msg;
static DWORD thisTick;
static DWORD lastTick;
int count=0;
lastTick=::GetTickCount();
while( 1 )
{
if(PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
{
if( !GetMessage( &msg, NULL, 0, 0 ) )
{//Remove The message From the Message Queue
return msg.wParam;
}
if ( !TranslateAccelerator( g_AppData.hWnd, g_AppData.hAccel, &msg ) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else if ( g_AppData.bIsActive )
{
thisTick=GetTickCount();
if( (thisTick-lastTick)>1000)
{
g_AppData.fps=count*1000/(thisTick-lastTick);
count=0;
lastTick=thisTick;
}
else
count++;
if(pfUpdateFrame)
(*pfUpdateFrame)(g_AppData.fps);
}
else
{
WaitMessage();
}
}
return msg.wParam;
}
//++++++++++++++++++++++++++++++++++++++++++++
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -