📄 example1.cpp
字号:
}
// --------------------------- IntToStr() function
__inline char *IntToStr(int);
__inline char *IntToStr(int d)
{
char *StrStrTmp;
StrStrTmp=garbagestring(32);
sprintf(StrStrTmp,"%d",d);
return StrStrTmp;
}
// --------------------------- MsgBox() function
char *HelpFileStr;
void MsgBoxCallback(LPHELPINFO);
void MsgBoxCallback(LPHELPINFO lpHelpInfo)
{
WinHelp(0,HelpFileStr,1,lpHelpInfo->dwContextId);
}
DWORD MsgBox(char *,DWORD = VbMsgBoxStyle_vbOKOnly,char * = App.Title ,char * = "",DWORD = 0);
DWORD MsgBox(char *Prompt,DWORD Buttons,char *Title,char *HelpFile,DWORD Context)
{
MSGBOXPARAMS MsgBoxDat;
memset(&MsgBoxDat,0,sizeof(MsgBoxDat));
MsgBoxDat.cbSize=sizeof(MsgBoxDat);
MsgBoxDat.hInstance=App.hInstance;
MsgBoxDat.lpszText=Mid(Prompt,1,1024);
MsgBoxDat.lpszCaption=Title;
MsgBoxDat.dwStyle=Buttons;
if((Buttons&VbMsgBoxStyle_vbSystemModal)==0) MsgBoxDat.dwStyle=MsgBoxDat.dwStyle|8192;
MsgBoxDat.dwContextHelpId=Context;
MsgBoxDat.lpfnMsgBoxCallback=(DWORD) &MsgBoxCallback;
MsgBoxDat.dwLanguageId=0;
HelpFileStr=HelpFile;
return(MessageBoxIndirect(&MsgBoxDat));
}
// --------------------------- InternalTimer() function
__inline float InternalTimer(void);
__inline float InternalTimer(void)
{
return(time(0)*(float)0.12345);
}
// --------------------------- Randomize() function
float CurrentRnd;
void Randomize(float = InternalTimer());
void Randomize(float seed)
{
double Fractional;
if (seed==0.00000) seed=1.12345;
CurrentRnd=fmod(InternalTimer(),seed);
while(CurrentRnd==0.00000)
{
CurrentRnd=fmod(InternalTimer(),0.00123);
}
CurrentRnd=modf(fabs(CurrentRnd*10),&Fractional);
}
// --------------------------- Rnd() function
float Rnd(float = CurrentRnd);
float Rnd(float Number)
{
float TempSeed;
double Fractional;
if(Number==0.00000)
{
TempSeed=CurrentRnd;
Randomize(CurrentRnd);
if (TempSeed==0) TempSeed=CurrentRnd;
return(TempSeed);
}
if(Number<0.00000) {
TempSeed=fmod(InternalTimer(),Number);
while(TempSeed==0.0)
{
TempSeed=fmod(InternalTimer(),0.00123);
}
return(modf(fabs(TempSeed*10),&Fractional));
}
Randomize(CurrentRnd);
return(CurrentRnd);
}
// --------------------------- FileLen() function
DWORD FileLen(char *);
DWORD FileLen(char *FileName)
{
WIN32_FIND_DATA Filedats;
DWORD FileHandle;
FileHandle=FindFirstFile(FileName,&Filedats);
if (FileHandle==-1) return 0;
FindClose(FileHandle);
return Filedats.nFileSizeLow;
}
// --------------------------- CLng() function
double CLng(double);
double CLng(double d)
{
if (d < 0.0)
{
if (fabs(floor(d)-d) < 0.5)
{
return floor(d);
}
else
{
return ceil(d);
}
}
else
{
if ((d-floor(d)) <= 0.5)
{
return floor(d);
}
else
{
return ceil(d);
}
}
}
// ---------------------------
// Comparisons handling
// ---------------------------
class VBComp
{
public:
VBComp(char *lv) { StrVBComp = lv; }
VBComp(double lv) { StrVBComp = DblToStr(lv); }
VBComp(float lv) { StrVBComp = SngToStr(lv); }
VBComp(DWORD lv) { StrVBComp = DWORDToStr(lv); }
VBComp(int lv) { StrVBComp = IntToStr(lv); }
char *ValStr() { return StrVBComp; }
friend int operator ==(char *StrLeft, VBComp &StrRight) { return -(strcmp(StrLeft, StrRight.ValStr()) == 0); };
friend int operator ==(double StrLeft, VBComp &StrRight) { return -(strcmp(DblToStr(StrLeft), StrRight.ValStr()) == 0); };
friend int operator ==(float StrLeft, VBComp &StrRight) { return -(strcmp(SngToStr(StrLeft), StrRight.ValStr()) == 0); };
friend int operator ==(DWORD StrLeft, VBComp &StrRight) { return -(strcmp(DWORDToStr(StrLeft), StrRight.ValStr()) == 0); };
friend int operator ==(int StrLeft, VBComp &StrRight) { return -(strcmp(IntToStr(StrLeft), StrRight.ValStr()) == 0); };
friend int operator !=(char *StrLeft, VBComp &StrRight) { return -(strcmp(StrLeft, StrRight.ValStr()) != 0); };
friend int operator !=(double StrLeft, VBComp &StrRight) { return -(strcmp(DblToStr(StrLeft), StrRight.ValStr()) != 0); };
friend int operator !=(float StrLeft, VBComp &StrRight) { return -(strcmp(SngToStr(StrLeft), StrRight.ValStr()) != 0); };
friend int operator !=(DWORD StrLeft, VBComp &StrRight) { return -(strcmp(DWORDToStr(StrLeft), StrRight.ValStr()) != 0); };
friend int operator !=(int StrLeft, VBComp &StrRight) { return -(strcmp(IntToStr(StrLeft), StrRight.ValStr()) != 0); };
friend int operator >(char *StrLeft, VBComp &StrRight) { return -(strcmp(StrLeft, StrRight.ValStr()) > 0); };
friend int operator >(double StrLeft, VBComp &StrRight) { return -(strcmp(DblToStr(StrLeft), StrRight.ValStr()) > 0); };
friend int operator >(float StrLeft, VBComp &StrRight) { return -(strcmp(SngToStr(StrLeft), StrRight.ValStr()) > 0); };
friend int operator >(DWORD StrLeft, VBComp &StrRight) { return -(strcmp(DWORDToStr(StrLeft), StrRight.ValStr()) > 0); };
friend int operator >(int StrLeft, VBComp &StrRight) { return -(strcmp(IntToStr(StrLeft), StrRight.ValStr()) > 0); };
friend int operator >=(char *StrLeft, VBComp &StrRight) { return -(strcmp(StrLeft, StrRight.ValStr()) >= 0); };
friend int operator >=(double StrLeft, VBComp &StrRight) { return -(strcmp(DblToStr(StrLeft), StrRight.ValStr()) >= 0); };
friend int operator >=(float StrLeft, VBComp &StrRight) { return -(strcmp(SngToStr(StrLeft), StrRight.ValStr()) >= 0); };
friend int operator >=(DWORD StrLeft, VBComp &StrRight) { return -(strcmp(DWORDToStr(StrLeft), StrRight.ValStr()) >= 0); };
friend int operator >=(int StrLeft, VBComp &StrRight) { return -(strcmp(IntToStr(StrLeft), StrRight.ValStr()) >= 0); };
friend int operator <(char *StrLeft, VBComp &StrRight) { return -(strcmp(StrLeft, StrRight.ValStr()) < 0); };
friend int operator <(double StrLeft, VBComp &StrRight) { return -(strcmp(DblToStr(StrLeft), StrRight.ValStr()) < 0); };
friend int operator <(float StrLeft, VBComp &StrRight) { return -(strcmp(SngToStr(StrLeft), StrRight.ValStr()) < 0); };
friend int operator <(DWORD StrLeft, VBComp &StrRight) { return -(strcmp(DWORDToStr(StrLeft), StrRight.ValStr()) < 0); };
friend int operator <(int StrLeft, VBComp &StrRight) { return -(strcmp(IntToStr(StrLeft), StrRight.ValStr()) < 0); };
friend int operator <=(char *StrLeft, VBComp &StrRight) { return -(strcmp(StrLeft, StrRight.ValStr()) <= 0); };
friend int operator <=(double StrLeft, VBComp &StrRight) { return -(strcmp(DblToStr(StrLeft), StrRight.ValStr()) <= 0); };
friend int operator <=(float StrLeft, VBComp &StrRight) { return -(strcmp(SngToStr(StrLeft), StrRight.ValStr()) <= 0); };
friend int operator <=(DWORD StrLeft, VBComp &StrRight) { return -(strcmp(DWORDToStr(StrLeft), StrRight.ValStr()) <= 0); };
friend int operator <=(int StrLeft, VBComp &StrRight) { return -(strcmp(IntToStr(StrLeft), StrRight.ValStr()) <= 0); };
friend int operator ||(char *StrLeft, VBComp &StrRight) { return -(strcmp(StrLeft, StrRight.ValStr()) || 0); };
friend int operator ||(double StrLeft, VBComp &StrRight) { return -(strcmp(DblToStr(StrLeft), StrRight.ValStr()) || 0); };
friend int operator ||(float StrLeft, VBComp &StrRight) { return -(strcmp(SngToStr(StrLeft), StrRight.ValStr()) || 0); };
friend int operator ||(DWORD StrLeft, VBComp &StrRight) { return -(strcmp(DWORDToStr(StrLeft), StrRight.ValStr()) || 0); };
friend int operator ||(int StrLeft, VBComp &StrRight) { return -(strcmp(IntToStr(StrLeft), StrRight.ValStr()) || 0); };
friend int operator &&(char *StrLeft, VBComp &StrRight) { return -(strcmp(StrLeft, StrRight.ValStr()) && 0); };
friend int operator &&(double StrLeft, VBComp &StrRight) { return -(strcmp(DblToStr(StrLeft), StrRight.ValStr()) && 0); };
friend int operator &&(float StrLeft, VBComp &StrRight) { return -(strcmp(SngToStr(StrLeft), StrRight.ValStr()) && 0); };
friend int operator &&(DWORD StrLeft, VBComp &StrRight) { return -(strcmp(DWORDToStr(StrLeft), StrRight.ValStr()) && 0); };
friend int operator &&(int StrLeft, VBComp &StrRight) { return -(strcmp(IntToStr(StrLeft), StrRight.ValStr()) && 0); };
friend int operator ==(VBComp &StrLeft, char *StrRight) { return -(strcmp(StrLeft.ValStr(), StrRight) == 0); };
friend int operator ==(VBComp &StrLeft, double StrRight) { return -(strcmp(StrLeft.ValStr(), DblToStr(StrRight)) == 0); };
friend int operator ==(VBComp &StrLeft, float StrRight) { return -(strcmp(StrLeft.ValStr(), SngToStr(StrRight)) == 0); };
friend int operator ==(VBComp &StrLeft, DWORD StrRight) { return -(strcmp(StrLeft.ValStr(), DWORDToStr(StrRight)) == 0); };
friend int operator ==(VBComp &StrLeft, int StrRight) { return -(strcmp(StrLeft.ValStr(), IntToStr(StrRight)) == 0); };
friend int operator !=(VBComp &StrLeft, char *StrRight) { return -(strcmp(StrLeft.ValStr(), StrRight) != 0); };
friend int operator !=(VBComp &StrLeft, double StrRight) { return -(strcmp(StrLeft.ValStr(), DblToStr(StrRight)) != 0); };
friend int operator !=(VBComp &StrLeft, float StrRight) { return -(strcmp(StrLeft.ValStr(), SngToStr(StrRight)) != 0); };
friend int operator !=(VBComp &StrLeft, DWORD StrRight) { return -(strcmp(StrLeft.ValStr(), DWORDToStr(StrRight)) != 0); };
friend int operator !=(VBComp &StrLeft, int StrRight) { return -(strcmp(StrLeft.ValStr(), IntToStr(StrRight)) != 0); };
friend int operator >(VBComp &StrLeft, char *StrRight) { return -(strcmp(StrLeft.ValStr(), StrRight) > 0); };
friend int operator >(VBComp &StrLeft, double StrRight) { return -(strcmp(StrLeft.ValStr(), DblToStr(StrRight)) > 0); };
friend int operator >(VBComp &StrLeft, float StrRight) { return -(strcmp(StrLeft.ValStr(), SngToStr(StrRight)) > 0); };
friend int operator >(VBComp &StrLeft, DWORD StrRight) { return -(strcmp(StrLeft.ValStr(), DWORDToStr(StrRight)) > 0); };
friend int operator >(VBComp &StrLeft, int StrRight) { return -(strcmp(StrLeft.ValStr(), IntToStr(StrRight)) > 0); };
friend int operator >=(VBComp &StrLeft, char *StrRight) { return -(strcmp(StrLeft.ValStr(), StrRight) >= 0); };
friend int operator >=(VBComp &StrLeft, double StrRight) { return -(strcmp(StrLeft.ValStr(), DblToStr(StrRight)) >= 0); };
friend int operator >=(VBComp &StrLeft, float StrRight) { return -(strcmp(StrLeft.ValStr(), SngToStr(StrRight)) >= 0); };
friend int operator >=(VBComp &StrLeft, DWORD StrRight) { return -(strcmp(StrLeft.ValStr(), DWORDToStr(StrRight)) >= 0); };
friend int operator >=(VBComp &StrLeft, int StrRight) { return -(strcmp(StrLeft.ValStr(), IntToStr(StrRight)) >= 0); };
friend int operator <(VBComp &StrLeft, char *StrRight) { return -(strcmp(StrLeft.ValStr(), StrRight) < 0); };
friend int operator <(VBComp &StrLeft, double StrRight) { return -(strcmp(StrLeft.ValStr(), DblToStr(StrRight)) < 0); };
friend int operator <(VBComp &StrLeft, float StrRight) { return -(strcmp(StrLeft.ValStr(), SngToStr(StrRight)) < 0); };
friend int operator <(VBComp &StrLeft, DWORD StrRight) { return -(strcmp(StrLeft.ValStr(), DWORDToStr(StrRight)) < 0); };
friend int operator <(VBComp &StrLeft, int StrRight) { return -(strcmp(StrLeft.ValStr(), IntToStr(StrRight)) < 0); };
friend int operator <=(VBComp &StrLeft, char *StrRight) { return -(strcmp(StrLeft.ValStr(), StrRight) <= 0); };
friend int operator <=(VBComp &StrLeft, double StrRight) { return -(strcmp(StrLeft.ValStr(), DblToStr(StrRight)) <= 0); };
friend int operator <=(VBComp &StrLeft, float StrRight) { return -(strcmp(StrLeft.ValStr(), SngToStr(StrRight)) <= 0); };
friend int operator <=(VBComp &StrLeft, DWORD StrRight) { return -(strcmp(StrLeft.ValStr(), DWORDToStr(StrRight)) <= 0); };
friend int operator <=(VBComp &StrLeft, int StrRight) { return -(strcmp(StrLeft.ValStr(), IntToStr(StrRight)) <= 0); };
friend int operator ||(VBComp &StrLeft, char *StrRight) { return -(strcmp(StrLeft.ValStr(), StrRight) || 0); };
friend int operator ||(VBComp &StrLeft, double StrRight) { return -(strcmp(StrLeft.ValStr(), DblToStr(StrRight)) || 0); };
friend int operator ||(VBComp &StrLeft, float StrRight) { return -(strcmp(StrLeft.ValStr(), SngToStr(StrRight)) || 0); };
friend int operator ||(VBComp &StrLeft, DWORD StrRight) { return -(strcmp(StrLeft.ValStr(), DWORDToStr(StrRight)) || 0); };
friend int operator ||(VBComp &StrLeft, int StrRight) { return -(strcmp(StrLeft.ValStr(), IntToStr(StrRight)) || 0); };
friend int operator &&(VBComp &StrLeft, char *StrRight) { return -(strcmp(StrLeft.ValStr(), StrRight) && 0); };
friend int operator &&(VBComp &StrLeft, double StrRight) { return -(strcmp(StrLeft.ValStr(), DblToStr(StrRight)) && 0); };
friend int operator &&(VBComp &StrLeft, float StrRight) { return -(strcmp(StrLeft.ValStr(), SngToStr(StrRight)) && 0); };
friend int operator &&(VBComp &StrLeft, DWORD StrRight) { return -(strcmp(StrLeft.ValStr(), DWORDToStr(StrRight)) && 0); };
friend int operator &&(VBComp &StrLeft, int StrRight) { return -(strcmp(StrLeft.ValStr(), IntToStr(StrRight)) && 0); };
friend int operator ==(VBComp &StrLeft, VBComp &StrRight) { return -(strcmp(StrLeft.ValStr(), StrRight.ValStr()) == 0); };
friend int operator !=(VBComp &StrLeft, VBComp &StrRight) { return -(strcmp(StrLeft.ValStr(), StrRight.ValStr()) != 0); };
friend int operator >(VBComp &StrLeft, VBComp &StrRight) { return -(strcmp(StrLeft.ValStr(), StrRight.ValStr()) > 0); };
friend int operator >=(VBComp &StrLeft, VBComp &StrRight) { return -(strcmp(StrLeft.ValStr(), StrRight.ValStr()) >= 0); };
friend int operator <(VBComp &StrLeft, VBComp &StrRight) { return -(strcmp(StrLeft.ValStr(), StrRight.ValStr()) < 0); };
friend int operator <=(VBComp &StrLeft, VBComp &StrRight) { return -(strcmp(StrLeft.ValStr(), StrRight.ValStr()) <= 0); };
friend int operator ||(VBComp &StrLeft, VBComp &StrRight) { return -(strcmp(StrLeft.ValStr(), StrRight.ValStr()) || 0); };
friend int operator &&(VBComp &StrLeft, VBComp &StrRight) { return -(strcmp(StrLeft.ValStr(), StrRight.ValStr()) && 0); };
private:
char *StrVBComp;
};
// --------------------------- DoEvents() function
void DoEvents(void);
void DoEvents(void)
{
MSG DoEventsMsg;
if (PeekMessage(&DoEventsMsg,0,0,0,PM_REMOVE) != 0)
{
TranslateMessage(&DoEventsMsg);
DispatchMessage(&DoEventsMsg);
}
return;
}
// --------------------------- Dir() function
char *Dir(char *PathName="",int Attributes=VbFileAttribute_vbNormal);
char *Dir(char *PathName,int Attributes)
{
static WIN32_FIND_DATA DirDat;
static DWORD hDirFound;
static int CurrentAttributes;
int FoundAttributes;
if(strlen(PathName)==0)
{
CantFoundFirst:
while(1)
{
if(FindNextFile(hDirFound,&DirDat)==0)
{
if(GetLastError()==ERROR_NO_MORE_FILES)
{
FindClose(hDirFound);
return("");
}
}
FoundAttributes=DirDat.dwFileAttributes & 0xff;
if((FoundAttributes==0x20)||(FoundAttributes==0)) return(DirDat.cFileName);
if((FoundAttributes & CurrentAttributes)!=0)
{
return(DirDat.cFileName);
}
}
}
CurrentAttributes=Attributes;
hDirFound=FindFirstFile(PathName,&DirDat);
if(hDirFound==INVALID_HANDLE_VALUE) return("");
FoundAttributes=DirDat.dwFileAttributes & 0xff;
if((FoundAttributes==0x20)||(FoundAttributes==0)) return(DirDat.cFileName);
if((FoundAttributes & CurrentAttributes)!=0)
{
return(DirDat.cFileName);
}
goto CantFoundFirst;
}
// --------------------------- Timer() function
float Timer(void);
float Timer(void)
{
SYSTEMTIME TimerDats;
float TimerRes;
GetLocalTime(&TimerDats);
TimerRes = CLng(TimerDats.wMilliseconds) / 1000;
TimerRes = TimerRes + ((((CLng(TimerDats.wHour) * 60) + CLng(TimerDats.wMinute)) * 60) + CLng(TimerDats.wSecond));
return TimerRes;
}
// --------------------------- AsmPointerFill() function
__inline void AsmPointerFill(DWORD MemToFill,DWORD FillDat,DWORD FillLen)
{
_asm {
push eax
push ecx
push edi
mov edi,MemToFill
mov ecx,FillLen
mov eax,FillDat
cld
shr ecx,2
rep stosd
mov ecx,FillLen
and ecx,3
rep stosb
pop edi
pop ecx
pop eax
}
return;
}
// --------------------------- CreateTempVarWORD() function
WORD *CreateTempVarWORD(WORD DatastoStore,DWORD VariableNumber)
{
TempVarsWORD[VariableNumber]=DatastoStore;
return &TempVarsWORD[VariableNumber];
}
// --------------------------- CreateTempVarDWORD() function
DWORD *CreateTempVarDWORD(DWORD DatastoStore,DWORD VariableNumber)
{
TempVarsDWORD[VariableNumber]=DatastoStore;
return &TempVarsDWORD[VariableNumber];
}
// --------------------------- CreateTempVarCHAR() function
char **CreateTempVarCHAR(char * DatastoStore,DWORD VariableNumber)
{
if (TempVarsCHAR[VariableNumber]) free((void *) TempVarsCHAR[VariableNumber]);
TempVarsCHAR[VariableNumber]=strdup(DatastoStore);
return &TempVarsCHAR[VariableNumber];
}
// --------------------------- CreateTempVarCHARPtr() function
char *CreateTempVarCHARPtr(char * DatastoStore,DWORD VariableNumber)
{
if (TempVarsCHAR[VariableNumber]) free((void *) TempVarsCHAR[VariableNumber]);
TempVarsCHAR[VariableNumber]=strdup(DatastoStore);
return TempVarsCHAR[VariableNumber];
}
// --------------------------- CreateTempVarBOOL() function
BOOL *CreateTempVarBOOL(BOOL DatastoStore,DWORD VariableNumber)
{
TempVarsBOOL[VariableNumber]=DatastoStore;
return &TempVarsBOOL[VariableNumber];
}
// --------------------------- CreateTempVarBYTE() function
BYTE *CreateTempVarBYTE(BYTE DatastoStore,DWORD VariableNumber)
{
TempVarsBYTE[VariableNumber]=DatastoStore;
return &TempVarsBYTE[VariableNumber];
}
// --------------------------- CreateTempVarDOUBLE() function
double *CreateTempVarDOUBLE(double DatastoStore,DWORD VariableNumber)
{
TempVarsDOUBLE[VariableNumber]=DatastoStore;
return &TempVarsDOUBLE[VariableNumber];
}
// --------------------------- CreateTempVarFLOAT() function
float *CreateTempVarFLOAT(float DatastoStore,DWORD VariableNumber)
{
TempVarsFLOAT[VariableNumber]=DatastoStore;
return &TempVarsFLOAT[VariableNumber];
}
// ---------------------------
// User modules
// ---------------------------
#include "D:\Dev\VB2VC\Example1\ModMain.cpp"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -