📄 _apputil.cpp
字号:
#include "stdafx.h"
#include "_apputil.h"
float fps = 0.0f;
float fs_frame;
float fs_time = 0;
DWORD fs_save;
HANDLE g_output = NULL;
char g_title[256];
BOOL _fs_wait();
HWND _console(int x, int y, int width, int height, int buff_width, int buff_height, char *title)
{
SMALL_RECT srect;
COORD size;
CONSOLE_SCREEN_BUFFER_INFO info;
RECT rect;
HWND hWnd = NULL;
AllocConsole();
g_output=GetStdHandle(STD_OUTPUT_HANDLE);
size.X = buff_width;
size.Y = buff_height;
SetConsoleScreenBufferSize(g_output,size);
GetConsoleScreenBufferInfo(g_output,&info);
srect.Left = 0;
srect.Top = 0;
srect.Right = info.dwMaximumWindowSize.X-1;
srect.Bottom = info.dwMaximumWindowSize.Y-1;
strcpy(g_title, title);
SetConsoleWindowInfo(g_output, TRUE, &srect);
SetConsoleTitle(g_title);
while(!(hWnd = FindWindow(NULL, g_title)));
GetWindowRect(hWnd, &rect);
MoveWindow(hWnd, x, y, rect.right-rect.left, height, TRUE);
return hWnd;
}
void _console_title(char *title)
{
strcpy(g_title, title);
SetConsoleTitle(g_title);
}
int _printf(const char *log, ...)
{
static char buff[4096];
vsprintf(buff, log, (char *)(&log+1));
if(!g_output)
return printf(buff);
DWORD len = (DWORD)strlen(buff);
return WriteConsole(g_output, buff, len, &len, 0);
}
BOOL _frame_skip()
{
if(fs_time==0) fs_save = GetTickCount();
// while(_fs_wait());
if(_fs_wait())
return TRUE;
fs_time -= 1000.0f / fs_frame;
if(fs_time < 0)
return FALSE;
else
return TRUE;
}
BOOL _fs_wait()
{
DWORD a = GetTickCount();
fs_time += (a - fs_save);
fs_save = a;
if(fs_time < 0)
{
// Sleep(abs((int)fs_time));
Sleep(1);
return TRUE;
}
else
return FALSE;
}
BOOL _frame_rate()
{
static char str_debug[256];
static DWORD dwFrame = 0;
static DWORD dwOldTime = 0;
++dwFrame;
DWORD dwTime = GetTickCount() - dwOldTime;
if(dwTime > 1000)
{
fps = dwFrame * 1000.0F / dwTime;
dwOldTime = GetTickCount();
dwFrame = 0;
sprintf(str_debug, "%s - %3.1ffps", g_title, fps);
SetConsoleTitle(str_debug);
return TRUE;
}
return FALSE;
}
void _log(const char *log, ...)
{
static char buff[4096];
static char filename[256];
static DWORD date = 0;
DWORD update;
struct tm *timer;
long ct;
char *tm;
ct=(long)time(NULL);
timer = localtime(&ct);
tm=asctime(timer);
tm[strlen(tm)-1] = NULL;
update = (timer->tm_year+1900)*10000 + (timer->tm_mon+1)*100 + timer->tm_mday;
if(date != update)
{
date = update;
sprintf(filename, "%s%d.txt", LOG_FILE, date);
}
vsprintf(buff, log, (char *)(&log+1));
_printf("%s\n", buff);
FILE *fp = fopen(filename, "a+t");
fprintf(fp, "[%s] - %s\n", tm, buff);
fclose(fp);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -