📄 util.cpp
字号:
#include "stdafx.h"
#include "pca.h"
#include <stdio.h>
#include <math.h>
#include <time.h>
#include "mainfrm.h"
#include "str.h"
#include "utilcpp.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
extern CPcaApp *gApplication;
extern CMainFrame *pMainWnd;
void ByteToStr(char *str, long byte);
struct MOREINFO
{
time_t ttime;
};
int level = 0;
void GiveProcess()
{
//gApplication->Process1Event();
MSG msg;
while (PeekMessage(&msg, NULL, NULL, NULL, PM_NOYIELD | PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
#if 0
struct MOREINFO mi[10];
void Msg(int next_level, char *format, ...)
{
unsigned long mem_total;
char msg[300], msg_more[100];
va_list ap;
char str[200];
int i, h, m, s, ms;
long ttime, ttime2;
char msg_mem_total[10];
if (next_level < 0)
{
level += next_level;
// Get the free memory available
mem_total = GlobalCompact(0); //GetFreeSpace(0);
ByteToStr(msg_mem_total, mem_total);
if (level < 10)
{
time(&ttime); /*ttime = number of sec since 1/1/1970*/
ttime -= mi[level].ttime; /*ttime = number of sec since the message of the same level*/
ttime2 = ttime;
h = floor((double)ttime/3600.0); /*number of hours*/
ttime -= h * 3600;
m = floor((double)ttime/60.0); /*minuts*/
ttime -= m * 60;
s = ttime; /*seconds*/
ms = 0;
}
if (h > 0)
sprintf(msg_more, str_MSG_MORE_H, h, m, msg_mem_total);
else
{
if (m > 0)
sprintf(msg_more, str_MSG_MORE_M, m, s, msg_mem_total);
else
{
sprintf(msg_more, str_MSG_MORE_S, s, msg_mem_total);
}
}
}
if (strlen(format) == 0)
return;
strcpy(str, "");
for (i = 0; i < level; i++)
{
strcat(str, " ");
}
strcat(str, format);
va_start(ap, format);
vsprintf(msg, str, ap);
va_end(ap);
if (next_level < 0)
strcat(msg, msg_more);
strcat(msg, "\r");
gApplication->m_pDoc->SetMsg(msg);
if (next_level > 0)
{
time(&(mi[level].ttime));
level += next_level;
}
}
#endif
void ByteToStr(char *str, long byte)
{
if (byte >= 1048576)
{
sprintf(str, "%.2f M", (float)byte/1048576.0);
return;
}
if (byte >= 1024)
{
sprintf(str, "%.2f k", (float)byte/1024.0);
return;
}
sprintf(str, "%ld b", byte);
}
int SaveReport(char *str)
{
return gApplication->m_pDoc->SaveReport(str);
}
long lmin(long i1, long i2)
{
if (i1 < i2)
return i1;
else
return i2;
}
void Fail(int err)
{
CException *excpt = new CException;
//excpt->err = err;
THROW(excpt);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -