问题标题: 关于wp系列的所有头文件

0
0
已解决
王牌工作室官方
王牌工作室官方
新手光能
新手光能

把他们放到Dev-Cpp/MinGW32/lib/gcc/mingw32/9.2.0/include/目录下(这是32bit9.2.0,请根据实际情况调整)

新建wp文件夹;

beep.h

#ifndef BEEP_H_
#define BEEP_H_

#ifdef BEEPDEF
#include<windows.h>
#endif

#define	qdo 262 
#define qre 294
#define qmi 330
#define qfa 349
#define qso 392
#define qla 440
#define qsi 494
#define do 523
#define re 578
#define mi 659
#define fa 698
#define so 784
#define la 880
#define si 988
#define do1 1046
#define re1 1175
#define mi1 1318
#define fa1 1480
#define so1 1568
#define la1 1760
#define si1 1976
#define sqdo 277
#define sqre 311
#define sqfa 370
#define sqso 415
#define sqla 466
#define sdo 554
#define sre 622
#define sfa 740
#define sso 831
#define sla 932
#define sdo1 1046
#define sre1 1245
#define sfa1 1480
#define sso1 1661
#define sla1 1865

//#define M(c1,c2) if(c2=='s') s##c1 else if(c2=='l') c1##l else if(c2=='q') q##c1

int MakePai(int minutes)
{
	double pai=60.0/minutes;
	return pai*1000;
}
//int MakeNum(char make,char pl)
//{
//	switch(make)
//	{
//		case 'C': {
//			return M(do,pl);
//			break;
//		}
//		case 'D': {
//			return M(re,pl);
//			break;
//		}
//		case 'E': {
//			return M(mi,pl);
//			break;
//		}
//		case 'F': {
//			return M(fa,pl);
//			break;
//		}
//		case 'G': {
//			return M(so,pl);
//			break;
//		}
//		case 'A': {
//			return M(la,pl);
//			break;
//		}
//		case 'B': {
//			return M(si,pl);
//			break;
//		}
//		default: {
//			return 0;
//			break;
//		}
//	}
//}

#endif

downinternetfile.h

#ifndef DOWNINTERNETFILE_H_
#define DOWNINTERNETFILE_H_

#include<wininet.h>
#include<stdio.h>
#pragma comment(lib,"wininet.lib")
#define MAXBLOCKSIZE 1024
void download(const char* Url, const char* save_as) /*将Url指向的地址的文件下载到save_as指向的本地文件*/
{
	byte Temp[MAXBLOCKSIZE];
	ULONG Number = 1;

	FILE* stream;
	HINTERNET hSession = InternetOpen("RookIE/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
	if (hSession != NULL)
	{
		HINTERNET handle2 = InternetOpenUrl(hSession, Url, NULL, 0, INTERNET_FLAG_DONT_CACHE, 0);
		if (handle2 != NULL)
		{


			if ( (stream = fopen( save_as, "wb" )) != NULL )
			{
				while (Number > 0)
				{
					InternetReadFile(handle2, Temp, MAXBLOCKSIZE - 1, &Number);

					fwrite(Temp, sizeof (char), Number, stream);
				}
				fclose( stream );
			}

			InternetCloseHandle(handle2);
			handle2 = NULL;
		}
		InternetCloseHandle(hSession);
		hSession = NULL;
	}
}

#endif

easy_list.h @薛乘志 

#ifndef EASY_LIST_H_
#define EASY_LIST_H_

#include <list>
namespace std {
    template <class T>
    class easy_list {
        private:
            list<T> _list;
            typename list<T>::iterator _it;
        public:
            list<T> *operator->() {
                return &_list;
            }
            T &operator[](int _i) {
                _it = _list.begin();
                for (int i = 0; ; _it++, i++) {
                    if (i == _i) {
                        return *_it;
                    }
                }
            }
            typename list<T>::iterator &operator()(int _i) {
                _it = _list.begin();
                for (int i = 0; ; _it++, i++) {
                    if (i == _i) {
                        return _it;
                    }
                }
                return 0;
            }
    };
}

#endif

file.h

#ifndef FILE_H_
#define FILE_H_

#include<windows.h>
#include<initializer_list>
#include<string>
std::string OpenFile(const char *format,const char *DefaultPath=NULL)
{
   	OPENFILENAME ofn;
 	TCHAR szOpenFileNames[80*MAX_PATH];
	TCHAR szPath[MAX_PATH];
	TCHAR szFileName[80*MAX_PATH];
	TCHAR* p;
	int nLen = 0;
	ZeroMemory( &ofn, sizeof(ofn) );
	ofn.Flags = OFN_EXPLORER;
	ofn.lStructSize = sizeof(ofn);
	ofn.lpstrFile = szOpenFileNames;
	ofn.nMaxFile = sizeof(szOpenFileNames);
	ofn.lpstrFile[0] = '\0';
	ofn.lpstrFilter = TEXT(format);
	ofn.lpstrInitialDir = DefaultPath;
	if( GetOpenFileName( &ofn ) )
	{  
	 //把第一个文件名前的复制到szPath,即:
	 //如果只选了一个文件,就复制到最后一个'/'
	 lstrcpyn(szPath, szOpenFileNames, ofn.nFileOffset );
	 //当只选了一个文件时,下面这个NULL字符是必需的.
	 szPath[ ofn.nFileOffset ] = '\0';
	 nLen = lstrlen(szPath);
	 
	 if( szPath[nLen-1] != '\\' )   //如果选了多个文件,则必须加上'//'
	 {
	  lstrcat(szPath, TEXT("\\"));
	 }
	 
	 p = szOpenFileNames + ofn.nFileOffset; //把指针移到第一个文件
	 
	 ZeroMemory(szFileName, sizeof(szFileName));
	 while( *p )
	 {   
	  lstrcat(szFileName, szPath);  //给文件名加上路径  
	  lstrcat(szFileName, p);    //加上文件名 
	  break;
	 }
	}
	return szFileName;
}
std::string OpenFileEx(const char *format,int *cformat,const char *DefaultPath=NULL)
{
   	OPENFILENAME ofn;
 	TCHAR szOpenFileNames[80*MAX_PATH];
	TCHAR szPath[MAX_PATH];
	TCHAR szFileName[80*MAX_PATH];
	TCHAR* p;
	int nLen = 0;
	ZeroMemory( &ofn, sizeof(ofn) );
	ofn.Flags = OFN_EXPLORER;
	ofn.lStructSize = sizeof(ofn);
	ofn.lpstrFile = szOpenFileNames;
	ofn.nMaxFile = sizeof(szOpenFileNames);
	ofn.lpstrFile[0] = '\0';
	ofn.lpstrFilter = TEXT(format);
	ofn.lpstrInitialDir = DefaultPath;
	if( GetOpenFileName( &ofn ) )
	{  
	 //把第一个文件名前的复制到szPath,即:
	 //如果只选了一个文件,就复制到最后一个'/'
	 lstrcpyn(szPath, szOpenFileNames, ofn.nFileOffset );
	 //当只选了一个文件时,下面这个NULL字符是必需的.
	 szPath[ ofn.nFileOffset ] = '\0';
	 nLen = lstrlen(szPath);
	 
	 if( szPath[nLen-1] != '\\' )   //如果选了多个文件,则必须加上'//'
	 {
	  lstrcat(szPath, TEXT("\\"));
	 }
	 
	 p = szOpenFileNames + ofn.nFileOffset; //把指针移到第一个文件
	 
	 ZeroMemory(szFileName, sizeof(szFileName));
	 while( *p )
	 {   
	  lstrcat(szFileName, szPath);  //给文件名加上路径  
	  lstrcat(szFileName, p);    //加上文件名 
	  break;
	 }
	 *cformat=ofn.nFilterIndex;
	}
	return szFileName;
}
std::string SaveFile(const char *format)
{
	OPENFILENAME ofn;
 	TCHAR szOpenFileNames[80*MAX_PATH];
	TCHAR szPath[MAX_PATH];
	TCHAR szFileName[80*MAX_PATH];
	TCHAR* p;
	int nLen = 0;
	ZeroMemory( &ofn, sizeof(ofn) );
	ofn.Flags = OFN_EXPLORER;
	ofn.lStructSize = sizeof(ofn);
	ofn.lpstrFile = szOpenFileNames;
	ofn.nMaxFile = sizeof(szOpenFileNames);
	ofn.lpstrFile[0] = '\0';
	ofn.lpstrFilter = TEXT(format);
	if( GetSaveFileName( &ofn ) )
	{
		return szOpenFileNames;
	}
	return (std::string)"\0";
}
std::string SaveFileEx(char *format,int *cformat)
{
	OPENFILENAME ofn;
 	TCHAR szOpenFileNames[80*MAX_PATH];
	TCHAR szPath[MAX_PATH];
	TCHAR szFileName[80*MAX_PATH];
	TCHAR* p;
	int nLen = 0;
	ZeroMemory( &ofn, sizeof(ofn) );
	ofn.Flags = OFN_EXPLORER;
	ofn.lStructSize = sizeof(ofn);
	ofn.lpstrFile = szOpenFileNames;
	ofn.nMaxFile = sizeof(szOpenFileNames);
	ofn.lpstrFile[0] = '\0';
	ofn.lpstrFilter = TEXT(format);
	if( GetSaveFileName( &ofn ) )
	{
		*cformat=ofn.nFilterIndex;
		return szOpenFileNames;
	}
	return (std::string)"\0";
}
std::string OpenPicture()
{
   	OPENFILENAME ofn;
 	TCHAR szOpenFileNames[80*MAX_PATH];
	TCHAR szPath[MAX_PATH];
	TCHAR szFileName[80*MAX_PATH];
	TCHAR* p;
	int nLen = 0;
	ZeroMemory( &ofn, sizeof(ofn) );
	ofn.Flags = OFN_EXPLORER;
	ofn.lStructSize = sizeof(ofn);
	ofn.lpstrFile = szOpenFileNames;
	ofn.nMaxFile = sizeof(szOpenFileNames);
	ofn.lpstrFile[0] = '\0';
	ofn.lpstrFilter = TEXT("图片\0*.jpg;*.jpeg;*.png;*.ico\0");
	if( GetOpenFileName( &ofn ) )
	{  
	 //把第一个文件名前的复制到szPath,即:
	 //如果只选了一个文件,就复制到最后一个'/'
	 lstrcpyn(szPath, szOpenFileNames, ofn.nFileOffset );
	 //当只选了一个文件时,下面这个NULL字符是必需的.
	 szPath[ ofn.nFileOffset ] = '\0';
	 nLen = lstrlen(szPath);
	 
	 if( szPath[nLen-1] != '\\' )   //如果选了多个文件,则必须加上'//'
	 {
	  lstrcat(szPath, TEXT("\\"));
	 }
	 
	 p = szOpenFileNames + ofn.nFileOffset; //把指针移到第一个文件
	 
	 ZeroMemory(szFileName, sizeof(szFileName));
	 while( *p )
	 {   
	  lstrcat(szFileName, szPath);  //给文件名加上路径  
	  lstrcat(szFileName, p);    //加上文件名 
	  break;
	 }
	}
	return szFileName;
}
std::string OpenColor()
{
   	OPENFILENAME ofn;
 	TCHAR szOpenFileNames[80*MAX_PATH];
	TCHAR szPath[MAX_PATH];
	TCHAR szFileName[80*MAX_PATH];
	TCHAR* p;
	int nLen = 0;
	ZeroMemory( &ofn, sizeof(ofn) );
	ofn.Flags = OFN_EXPLORER;
	ofn.lStructSize = sizeof(ofn);
	ofn.lpstrFile = szOpenFileNames;
	ofn.nMaxFile = sizeof(szOpenFileNames);
	ofn.lpstrFile[0] = '\0';
	ofn.lpstrFilter = TEXT("彩色颜色\0*.rgb\0");
	if( GetOpenFileName( &ofn ) )
	{  
	 //把第一个文件名前的复制到szPath,即:
	 //如果只选了一个文件,就复制到最后一个'/'
	 lstrcpyn(szPath, szOpenFileNames, ofn.nFileOffset );
	 //当只选了一个文件时,下面这个NULL字符是必需的.
	 szPath[ ofn.nFileOffset ] = '\0';
	 nLen = lstrlen(szPath);
	 
	 if( szPath[nLen-1] != '\\' )   //如果选了多个文件,则必须加上'//'
	 {
	  lstrcat(szPath, TEXT("\\"));
	 }
	 
	 p = szOpenFileNames + ofn.nFileOffset; //把指针移到第一个文件
	 
	 ZeroMemory(szFileName, sizeof(szFileName));
	 while( *p )
	 {   
	  lstrcat(szFileName, szPath);  //给文件名加上路径  
	  lstrcat(szFileName, p);    //加上文件名 
	  break;
	 }
	}
	return szFileName;
}
#include "Shlobj.h"
std::string OpenFolder(const char *text="从下面选文件夹目录:")
{
	TCHAR szBuffer[MAX_PATH] = {0};
	BROWSEINFO bi;
	ZeroMemory(&bi,sizeof(BROWSEINFO));
	bi.hwndOwner = NULL;
	bi.pszDisplayName = szBuffer;
	bi.lpszTitle = (text);
	bi.ulFlags = BIF_RETURNFSANCESTORS;
	LPITEMIDLIST idl = SHBrowseForFolder(&bi);
	if (idl == NULL)
	{
		return (std::string)"\0";
	}
	SHGetPathFromIDList(idl,szBuffer);
	return szBuffer;
}
std::string OpenFolderOrFile(const char *text="从下面选择文件或文件夹:")
{
	TCHAR szBuffer[MAX_PATH] = {0};
	BROWSEINFO bi;
	ZeroMemory(&bi,sizeof(BROWSEINFO));
	bi.hwndOwner = NULL;
	bi.pszDisplayName = szBuffer;
	bi.lpszTitle = text;
	bi.ulFlags = BIF_BROWSEINCLUDEFILES;
	LPITEMIDLIST idl = SHBrowseForFolder(&bi);
	if (idl == NULL)
	{
	    return (std::string)"\0";
	}
	SHGetPathFromIDList(idl,szBuffer);
	return szBuffer;
}

#endif

longnum.h

#ifndef LONGNUM_H_
#define LONGNUM_H_

#include<string>
#include<sstream>
#include<istream>
#include<ostream>
#include<algorithm>
#include<cmath>
using std::string;
using std::istream;
using std::ostream;
using std::fill;
using std::sqrt;
class LongNum
{
	string shu;
	string jia(string a, string b){
	    string ans;
	    reverse(a.begin(), a.end());
	    reverse(b.begin(), b.end());
	    a.push_back('0');  b.push_back('0');
	    if(a.size() < b.size()) swap(a, b);
	    while(b.size() < a.size()) b.push_back('0');
	    int c[1000]={0}, k = a.size();
	    for(int i = 0; i < a.size(); i++)
	    {
	        int s = c[i] + a[i]-'0' + b[i] - '0';
	        c[i] = s%10;
	        c[i+1] += s/10;
	    }
	    while(c[k]==0 && k>=0) k--;
	    while(k >= 0)
	        ans.push_back(c[k--]+'0');
	    return ans;
	}
	string jian(string a, string b){
	    string ans;
	    bool flag = false;
	    if(a.size() < b.size() || (a.size()==b.size() && a < b)){
	        swap(a, b);
	        flag = true;    
	    }
	    reverse(a.begin(), a.end());
	    reverse(b.begin(), b.end());
	    a.push_back('0');  b.push_back('0');
	    if(a.size() < b.size()) swap(a, b);
	    while(b.size() < a.size()) b.push_back('0');
	    int c[1000]={0}, k = a.size();
	    for(int i = 0; i < a.size(); i++){
	        if(a[i] < b[i]) a[i]+=10, a[i+1]--;
	        c[i] = a[i] - b[i];
	    }
	    while(c[k]==0 && k>=0) k--;
	    if(flag) ans.push_back('-');
	    while(k >= 0)
	        ans.push_back(c[k--]+'0');
	    return ans;
	}
	string cheng(string a, string b){
	    string ans;
	    reverse(a.begin(), a.end());
	    reverse(b.begin(), b.end());
	    int c[1000]={0}, k = a.size()+b.size()+1;
	    for(int i = 0; i < a.size(); i++){ 
	        for(int j = 0; j < b.size(); j++){
	            c[i+j] += (a[i]-'0')*(b[j]-'0');
	            c[i+j+1] += c[i+j]/10;
	            c[i+j] %= 10;
	        }
	    } 
	    while(c[k]==0 && k>=0) k--;
	    while(k >= 0){ 
	        ans.push_back(c[k--]+'0');
	    } 
	    return ans;
	}
	string chu(string a, long long b){
	    int z[256] = {0}, d = 0;
	    for(int i = 0; i < a.size(); i++)
	    {
	        d = 10*d + a[i] - '0';
	        z[i] = d / b;
	        d %= b;
	    }
	    string ans;
	    int len = 0;
	    while(z[len] == 0 && len < a.size()-1)
	        len++;
	    for(int i = len; i < a.size(); i++){
	        ans.push_back(z[i]+'0');
	    }
	    return ans;
	}
	int sub1(int *a, int *b, int La, int Lb){
	    if (La < Lb)
	        return -1;//如果a小于b,则返回-1
	    if (La == Lb) {
	        for (int i = La - 1; i >= 0; i--)
	            if (a[i] > b[i])
	                break;
	            else if (a[i] < b[i])
	                return -1;//如果a小于b,则返回-1
	
	    }
	    for (int i = 0; i < La; i++) //高精度减法
	    {
	        a[i] -= b[i];
	        if (a[i] < 0)
	            a[i] += 10, a[i + 1]--;
	    }
	    for (int i = La - 1; i >= 0; i--)
	        if (a[i])
	            return i + 1;//返回差的位数
	    return 0;//返回差的位数
	
	}
	string yu(string n1, string n2){
		int nn=2;
	    string s, v;//s存商,v存余数
	    int a[100010], b[100010], r[100010], 
		La = n1.size(), Lb = n2.size(), i, tp = La;
		
	    fill(a, a + 100010, 0);
	    fill(b, b + 100010, 0);
	    fill(r, r + 100010, 0);
	    for (i = La - 1; i >= 0; i--)
	        a[La - 1 - i] = n1[i] - '0';
	    for (i = Lb - 1; i >= 0; i--)
	        b[Lb - 1 - i] = n2[i] - '0';
	    if (La < Lb || (La == Lb && n1 < n2)) {
	        return n1;
	    }
	    int t = La - Lb;
	    for (int i = La - 1; i >= 0; i--) 
	        if (i >= t)
	            b[i] = b[i - t];
	        else
	            b[i] = 0;
	    Lb = La;
	    for (int j = 0; j <= t; j++) {
	        int temp;
			
	        while ((temp = sub1(a, b + j, La, Lb - j)) >= 0)
		     {
	           La = temp;
	            r[t - j]++;
	        }
	    }
	    for (i = 0; i < 100010 - 10; i++)
	        r[i + 1] += r[i] / 10, r[i] %= 10;
	    while (!r[i])
	        i--;
	    while (i >= 0)
	        s += r[i--] + '0';
	    i = tp;
	    while (!a[i])
	        i--;
	    while (i >= 0)
	        v += a[i--] + '0';
	    if (v.empty())
	        v = "0";
		return v;
	}
	string toString(long long n){
		std::ostringstream sout;
		sout<<n;
		return sout.str();
	}
	unsigned long long toInt(string s){
		std::istringstream sin;
		long long n;
		sin>>n;
		return n;
	}
	public:
		LongNum(string s="0"){shu=s;}
		LongNum(int n){shu=toString(n);}
		LongNum(long long n){shu=toString(n);}
		LongNum(float)  = delete;
		LongNum(double) = delete;
		LongNum(const LongNum&) = default;
		operator string(){return shu;}
		LongNum&operator=(string s){shu=s;return *this;}
		LongNum&operator=(int n){shu=toString(n);return *this;}
		LongNum&operator=(long long n){shu=toString(n);return *this;}
		LongNum&operator=(float)  = delete;
		LongNum&operator=(double) = delete;
		LongNum operator+(const LongNum&ln)   {return jia(shu,ln.shu);}
		LongNum operator-(const LongNum&ln)   {return jian(shu,ln.shu);}
		LongNum operator*(const LongNum&ln)   {return cheng(shu,ln.shu);}
		LongNum operator/(const long long&ll) {return chu(shu,ll);}
		LongNum operator%(const LongNum&ln) {return yu(shu,ln.shu);}
		LongNum operator+=(const LongNum&ln)   {shu=jia(shu,ln.shu);return *this;}
		LongNum operator-=(const LongNum&ln)   {shu=jian(shu,ln.shu);return *this;}
		LongNum operator*=(const LongNum&ln)   {shu=cheng(shu,ln.shu);return *this;}
		LongNum operator/=(const long long&ll) {shu=chu(shu,ll);return *this;}
		LongNum operator%=(const LongNum&ln) {shu=yu(shu,ln.shu);return *this;}
		LongNum operator++(){this->operator+=(1);return *this;}
		LongNum operator++(int){LongNum t=*this;this->operator+=(1);return t;}
		LongNum operator--(){this->operator-=(1);return *this;}
		LongNum operator--(int){LongNum t=*this;this->operator-=(1);return t;}
		friend istream&operator>>(istream&is,LongNum&ln);
		friend ostream&operator<<(ostream&os,LongNum ln);
		friend bool operator< (LongNum x,LongNum y);
		friend bool operator<=(LongNum x,LongNum y);
		friend bool operator> (LongNum x,LongNum y);
		friend bool operator>=(LongNum x,LongNum y);
		friend bool operator==(LongNum x,LongNum y);
};
istream&operator>>(istream&is,LongNum&ln)
{
	is>>ln.shu;
	return is;
}
ostream&operator<<(ostream&os,LongNum ln)
{
	os<<ln.shu;
	return os;
}
bool operator< (LongNum x,LongNum y)
{
	if(x.shu.size()!=y.shu.size())
		return x.shu.size()<y.shu.size();
	return x.shu<y.shu;
}
bool operator> (LongNum x,LongNum y)
{
	return y<x;
}
bool operator==(LongNum x,LongNum y)
{
	return x.shu==y.shu;
}

LongNum sqrt(LongNum ln)
{
	for(LongNum i=1;i<ln+1;i++)
	{
		if(i*i==ln) return i;
	}
	return LongNum();
}


#endif

playmp3.h

#ifndef PLAYMP3_H_
#define PLAYMP3_H_

#include<windows.h>
#include"mmsystem.h"
#include<stdio.h>
#ifdef __cplusplus
namespace wpPlayMp3 {
#endif
void debug_out(const char *str,...)
{
#ifdef DEBUG
	va_list v;
	va_start(v,str);
	vprintf(str,v);
	va_end(v);
#endif
}
void OpenMp3(char *Path,char *Parameter)
{
	char cmd[1024]={ };
	sprintf(cmd,"open %s %s",Path,(Parameter==0?"alias myMusic":Parameter));
	if(mciSendString(cmd, NULL, 0, NULL)) debug_out("Unable to open file");
}
void PlayMp3(char *Name)
{
	char cmd[1024]={ };
	sprintf(cmd,"play %s",Name);
	if(mciSendString(cmd, NULL, 0, NULL)) debug_out("Unable to play file");
}
void CloseMp3(char *Name)
{
	char cmd[1024]={ };
	sprintf(cmd,"close %s",Name);
	if(mciSendString(cmd, NULL, 0, NULL)) debug_out("Unable to close file");
}
void SendCommand(char *Command)
{
	if(mciSendString(Command, NULL, 0, NULL)) debug_out("Unable to execute %s",Command);
}
#ifdef __cplusplus
}
#endif

#endif

readbmp.h

研发中

sdkmainwindow.h  @Microsoft_Docs

#ifndef SDKMAINWINDOW_H_
#define SDKMAINWINDOW_H_

#include<windows.h>
#ifndef SDKBASEWINDOW
#define SDKBASEWINDOW
template <class DERIVED_TYPE> 
class BaseWindow
{
public:
    static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        DERIVED_TYPE *pThis = NULL;

        if (uMsg == WM_NCCREATE)
        {
            CREATESTRUCT* pCreate = (CREATESTRUCT*)lParam;
            pThis = (DERIVED_TYPE*)pCreate->lpCreateParams;
            SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pThis);

            pThis->m_hwnd = hwnd;
        }
        else
        {
            pThis = (DERIVED_TYPE*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
        }
        if (pThis)
        {
            return pThis->HandleMessage(uMsg, wParam, lParam);
        }
        else
        {
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
        }
    }

    BaseWindow() : m_hwnd(NULL) { }

    BOOL Create(
        PCWSTR lpWindowName,
        DWORD dwStyle,
        DWORD dwExStyle = 0,
        int x = CW_USEDEFAULT,
        int y = CW_USEDEFAULT,
        int nWidth = CW_USEDEFAULT,
        int nHeight = CW_USEDEFAULT,
        HWND hWndParent = 0,
        HMENU hMenu = 0
        )
    {
        WNDCLASS wc = {0};

        wc.lpfnWndProc   = DERIVED_TYPE::WindowProc;
        wc.hInstance     = GetModuleHandle(NULL);
        wc.lpszClassName = ClassName();

        RegisterClass(&wc);

        m_hwnd = CreateWindowEx(
            dwExStyle, ClassName(), lpWindowName, dwStyle, x, y,
            nWidth, nHeight, hWndParent, hMenu, GetModuleHandle(NULL), this
            );

        return (m_hwnd ? TRUE : FALSE);
    }

    HWND Window() const { return m_hwnd; }

protected:

    virtual PCWSTR  ClassName() const = 0;
    virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) = 0;

    HWND m_hwnd;
};
#endif
class MainWindow : public BaseWindow<MainWindow>
{
public:
	friend class BaseWindow<MainWindow>;
    PCWSTR  ClassName() const { return L"MainWindow"; }
    LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
};

#endif

sdkeditwindow.h BaseWindow is @Microsoft_Docs

#ifndef SDKEDITWINDOW_H_
#define SDKEDITWINDOW_H_

#include<windows.h>
#ifndef SDKBASEWINDOW
#define SDKBASEWINDOW
template <class DERIVED_TYPE> 
class BaseWindow
{
public:
    static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        DERIVED_TYPE *pThis = NULL;

        if (uMsg == WM_NCCREATE)
        {
            CREATESTRUCT* pCreate = (CREATESTRUCT*)lParam;
            pThis = (DERIVED_TYPE*)pCreate->lpCreateParams;
            SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pThis);

            pThis->m_hwnd = hwnd;
        }
        else
        {
            pThis = (DERIVED_TYPE*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
        }
        if (pThis)
        {
            return pThis->HandleMessage(uMsg, wParam, lParam);
        }
        else
        {
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
        }
    }

    BaseWindow() : m_hwnd(NULL) { }

    BOOL Create(
        PCWSTR lpWindowName,
        DWORD dwStyle,
        DWORD dwExStyle = 0,
        int x = CW_USEDEFAULT,
        int y = CW_USEDEFAULT,
        int nWidth = CW_USEDEFAULT,
        int nHeight = CW_USEDEFAULT,
        HWND hWndParent = 0,
        HMENU hMenu = 0
        )
    {
        WNDCLASS wc = {0};

        wc.lpfnWndProc   = DERIVED_TYPE::WindowProc;
        wc.hInstance     = GetModuleHandle(NULL);
        wc.lpszClassName = ClassName();

        RegisterClass(&wc);

        m_hwnd = CreateWindowEx(
            dwExStyle, ClassName(), lpWindowName, dwStyle, x, y,
            nWidth, nHeight, hWndParent, hMenu, GetModuleHandle(NULL), this
            );

        return (m_hwnd ? TRUE : FALSE);
    }

    HWND Window() const { return m_hwnd; }

protected:

    virtual PCWSTR  ClassName() const = 0;
    virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) = 0;

    HWND m_hwnd;
};
#endif
class EditWindow : public BaseWindow<EditWindow>
{
public:
	PCWSTR  ClassName() const {return L"edit"; }
	LRESULT HandleMessage(UINT uMsg,WPARAM wParam,LPARAM lParam);
};

#endif

socket.h

#ifndef SOCKET_H_
#define SOCKET_H_

#include<winsock.h>
#include<string.h>
#include<stdio.h>
#pragma comment(lib, "ws2_32.lib")
class fwq
{
	WSADATA wsaData;      
    SOCKET sListen;      
    SOCKET sClient;      
    SOCKADDR_IN local;      
    SOCKADDR_IN client;
    char szMessage[1024];
    char ip[100];
    int ret;      
    int iaddrSize = sizeof(SOCKADDR_IN);
    public:
    	explicit fwq(bool print=false)
    	{
    		WSAStartup(0x0202, &wsaData);
		    sListen = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
		    local.sin_family = AF_INET;
		    local.sin_port = htons(5150);
		    local.sin_addr.s_addr = htonl(INADDR_ANY);
		    bind(sListen, (struct sockaddr *) &local, sizeof(SOCKADDR_IN));
		    ::listen(sListen, 1);
		    sClient = accept(sListen, (struct sockaddr *) &client, &iaddrSize);
		    if(print) printf("Accepted client:%s:%d\n", inet_ntoa(client.sin_addr),ntohs(client.sin_port));
		    strcpy(ip,inet_ntoa(client.sin_addr));
		}
		~fwq(){}
		void listen(char *szBuffer,int boo)
		{
			ret = recv(sClient, szBuffer, 1024, 0);
	        if(boo) szBuffer[ret] = '\0';
		}
		void Return(const char* msg,int len)
		{
			::send(sClient, msg, len, 0);
		}
		const char *GetIp(){return ip;}
};
class khd
{
	WSADATA wsaData;
    SOCKET sClient;
    SOCKADDR_IN server;
    char szMessage[1024];
    int ret;
    public:
    	khd(const char *ip="127.0.0.1")
    	{
    		WSAStartup(0x0202, &wsaData);
		    sClient = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
		    memset(&server, 0, sizeof(SOCKADDR_IN));
		    server.sin_family = PF_INET;
		    server.sin_port = htons(5150);
		    server.sin_addr.s_addr = inet_addr(ip);
		    connect(sClient, (struct sockaddr *) &server, sizeof(SOCKADDR_IN));
		}
		~khd()
		{
			closesocket(sClient);
    		WSACleanup();
		}
		void send(const char *msg,int len,char* (*func)(char*)=NULL)
		{
			if(msg==NULL)
			{
		        func(szMessage);
		        ::send(sClient, szMessage, len, 0);
			}
			else
			{
				::send(sClient, msg, strlen(msg), 0);
			}
			
		}
		void Receive(char* szBuffer,int boo)
		{
			int len=recv(sClient, szBuffer, 1024, 0);
			if(boo) szBuffer[len]='\0';
		}
};

#endif

utf.h

研发中

wfloat.h

#ifndef WFLOAT_H_
#define WFLOAT_H_

#include<string>
#include<vector>
#include<algorithm>
#include<iostream>
#include<deque>
#include<exception>
#define ACCURACY 100;	//定义除法精度
using std::ostream;
using std::istream;
using std::vector;
using std::cout;
using std::string;
using std::deque;
struct DividedByZeroException : std::exception
{
	const char* what(){return "Divided By Zero Exception!\n";}
};
class WFloat	//高精度浮点数类
{
	//基本运算符重载
	friend WFloat operator+(const WFloat&, const WFloat&);	//加法重载
	friend WFloat operator-(const WFloat&, const WFloat&);	//减法重载
	friend WFloat operator*(const WFloat&, const WFloat&);	//乘法重载
	friend WFloat operator/(const WFloat&, const WFloat&) throw(DividedByZeroException);	//除法重载
	friend WFloat operator-(const WFloat&);	//负号重载
	
	//比较重载
	friend bool operator==(const WFloat&, const WFloat&);	//等于重载
	friend bool operator!=(const WFloat&, const WFloat&);	//不等于重载
	friend bool operator<(const WFloat&, const WFloat&);	//小于重载
	friend bool operator<=(const WFloat&, const WFloat&);	//小于等于重载
	friend bool operator>(const WFloat&, const WFloat&);	//大于重载
	friend bool operator>=(const WFloat&, const WFloat&);	//大于等于重载

	//扩展运算符重载
	friend WFloat operator+=(WFloat&, const WFloat&);	//加等重载
	friend WFloat operator-=(WFloat&, const WFloat&);	//减等重载
	friend WFloat operator*=(WFloat&, const WFloat&);	//乘等重载
	friend WFloat operator/=(WFloat&, const WFloat&) throw(DividedByZeroException);	//除等重载
	
	//输入输出重载
	friend ostream& operator<<(ostream&, const WFloat&);	//输出重载
	friend istream& operator>>(istream&, WFloat&);	//输入重载

public:
	WFloat();
	WFloat(int);	//用一个整数构造
	WFloat(string);	//用一个字符串构造
	WFloat(const WFloat&) = default;	//用一个高精度数构造
	WFloat operator=(const WFloat&);	//赋值函数
	WFloat abs() const;	//取绝对值
	~WFloat() {}

	static const WFloat ZERO;	//定义0
	static const WFloat ONE;	//定义1
	static const WFloat TEN;	//定义10(用于除法化整)

private:
	vector<char>integer;	//整数部分
	vector<char>decimal;	//小数部分
	void trim();	//将多余的零删去
	bool tag;	//用来表示正负,true为正
};
const WFloat WFloat::ZERO = WFloat("0");
const WFloat WFloat::ONE = WFloat("1");
const WFloat WFloat::TEN = WFloat("10");
WFloat::WFloat()	//默认构造函数
{
	tag = true;
	integer.push_back(0);
	decimal.push_back(0);
}

WFloat::WFloat(int num)	//用整型初始化
{
	if (num >= 0)	//判断正负
	{
		tag = true;
	}
	else
	{
		tag = false;
		num *= (-1);
	}
	do {
		integer.push_back((char)(num % 10));	//按位倒序写入整数部分
		num /= 10;
	} while (num != 0);

	decimal.push_back(0);	//因为用整数赋值,小数部分为0
}
WFloat::WFloat(string num)	//用字符串初始化,格式形如"-123.456"、"1.0"
{
	bool type = true;	//用于判断小数部分是否结束
	tag = true;	//默认为正数,读到'-'再变为负数
	for (string::reverse_iterator iter = num.rbegin(); iter < num.rend(); iter++)	  //逆向迭代
	{
		char ch = (*iter);
		if (ch == '.')	//遇到小数点则开始向整数部分写入
		{
			type = false;
			iter++;
		}
		if (iter == num.rend() - 1)	//读取正负号
		{
			if (ch == '+')
			{
				break;
			}
			if (ch == '-')
			{
				tag = false;
				break;
			}
		}
		//利用逆向迭代器,将整个数据倒序存入
		if (type)
			decimal.push_back((char)((*iter) - '0'));
		else
			integer.push_back((char)((*iter) - '0'));
	}
}
WFloat operator-(const WFloat& num)	//取负操作
{
	WFloat temp(num);
	temp.tag = !temp.tag;
	return temp;
}
void WFloat::trim()	
{
	//因为我们是逆向存储的,所以整数的尾部和小数的首部可能会有多余的0
	vector<char>::reverse_iterator iter = integer.rbegin();	//对整数部分
	while (!integer.empty() && (*iter) == 0)
	{
		integer.pop_back();	//指向不为空且尾部为0,删去
		iter = integer.rbegin();	//再次指向尾部
		//整数部分的“尾部”就是最高位,如00515.424900的左两个0
	}

	if (integer.size() == 0 && decimal.size() == 0)	//如果整数、小数全为空
	{
		tag = true;
	}

	if (integer.size() == 0)	//如果整数部分是0
	{
		integer.push_back(0);
	}

	vector<char>::const_iterator it = decimal.begin();	//对小数部分
	while (!decimal.empty() && (*it) == 0)
	{
		it = decimal.erase(it);	//指向不为空且首部为0,删去
		//小数部分的“首部”就是最低位,上例中的右两个0
	}

	if (decimal.size() == 0)	//如果小数部分是0
	{
		decimal.push_back(0);
	}
}
WFloat WFloat::operator=(const WFloat& num)	//赋值(拷贝)操作
{
	integer = num.integer;
	decimal = num.decimal;
	tag = num.tag;
	return (*this);
}
ostream& operator<<(ostream& out, const WFloat& num)	//输出重载
{
	if (!num.tag)	//负数
	{
		out << "-";
	}

	for (vector<char>::const_reverse_iterator iter = num.integer.rbegin(); iter != num.integer.rend(); iter++)  //输出整数部分
	{
		out << (char)((*iter) + '0');
	}

	cout << '.';

	for (vector<char>::const_reverse_iterator iter = num.decimal.rbegin(); iter != num.decimal.rend(); iter++)  //输出小数部分
	{
		out << (char)((*iter) + '0');
	}
	return out;
}
istream& operator>>(istream& in, WFloat& num)	//输入重载
{
	string str;
	in >> str;
	num = WFloat(str);
	return in;
}
bool operator<(const WFloat& num1, const WFloat& num2)	//小于重载
{
	bool sign;	//返回值
	if (num1.tag != num2.tag)	//如果异号
	{
		sign = !num1.tag;	//如果num1正,则不小于;反之,则小于
		return sign;
	}
	else
	{
		//如果同号,先比较整数再比较小数
		if (num1.integer.size() != num2.integer.size())	//如果整数部分不等长
		{
			if (num1.tag)	//如果同为正,则整数部分长的大
			{
				sign = num1.integer.size() < num2.integer.size();	
				return sign;
			}
			else
			{
				//同为负,则整数部分长的小
				sign = num1.integer.size() > num2.integer.size();
				return sign;
			}
		}
		//如果整数部分等长
		vector<char>::const_reverse_iterator iter1, iter2;
		iter1 = num1.integer.rbegin();
		iter2 = num2.integer.rbegin();
		while (iter1 != num1.integer.rend())
		{
			if (num1.tag && *iter1 < *iter2)
				return true;
			if (num1.tag && *iter1 > *iter2)
				return false;
			if (!num1.tag && *iter1 > *iter2)
				return true;
			if (!num1.tag && *iter1 < *iter2)
				return false;
			iter1++;
			iter2++;
		}

		//下面比较小数部分
		vector<char>::const_reverse_iterator it1, it2;
		it1 = num1.decimal.rbegin();
		it2 = num2.decimal.rbegin();
		while (it1 != num1.decimal.rend() && it2!=num2.decimal.rend())
		{
			if (num1.tag && *it1 < *it2)
				return true;
			if (num1.tag && *it1 > *it2)
				return false;
			if (!num1.tag && *it1 > *it2)
				return true;
			if (!num1.tag && *it1 < *it2)
				return false;
			it1++;
			it2++;
		}
		//如果整数部分,而小数部分停止前全部一样,那么看谁的小数位更多
		return(num1.tag && it2 != num2.decimal.rend()) || (!num1.tag && it1 != num1.decimal.rend());
	}
}
bool operator==(const WFloat& num1, const WFloat& num2)	//等于重载
{
	if (num1.tag != num2.tag)
		return false;
	if (num1.integer.size() != num2.integer.size())
		return false;
	if (num1.decimal.size() != num2.decimal.size())
		return false;

	//如果长度和符号相同,那么下面逐位比较
	vector<char>::const_iterator iter1, iter2;
	iter1 = num1.decimal.begin();
	iter2 = num2.decimal.begin();
	while (iter1 != num1.decimal.end())
	{
		if (*iter1 != *iter2)
			return false;
		iter1++;
		iter2++;
	}

	iter1 = num1.integer.begin();
	iter2 = num2.integer.begin();
	while (iter1 != num1.integer.end())
	{
		if (*iter1 != *iter2)
			return false;
		iter1++;
		iter2++;
	}
	return true;
}
bool operator> (const WFloat& num1, const WFloat& num2)
{
	return num2<num1;
}
bool operator!=(const WFloat& num1, const WFloat& num2)
{
	return !(num1 == num2);
}

bool operator>=(const WFloat& num1, const WFloat& num2)
{
	bool tag = (num1 > num2) || (num1 == num2);
	return tag;
}

bool operator<=(const WFloat& num1, const WFloat& num2)
{
	bool tag = (num1 < num2) || (num1 == num2);
	return tag;
}
WFloat operator+=(WFloat& num1, const WFloat& num2)	//加等于重载
{
	if (num1.tag == num2.tag)	//只处理同符号数,异号由-减法处理
	{
		vector<char>::iterator iter1;
		vector<char>::const_iterator iter2, it;

		//先处理小数部分
		int num1_decimal_size = num1.decimal.size();	//小数部分长度
		int num2_decimal_size = num2.decimal.size();
		char carry = 0;	//进位
		if (num1_decimal_size < num2_decimal_size)	//如果num2小数部分更长
		{
			iter1 = num1.decimal.begin();
			iter2 = num2.decimal.begin();
			iter2 = iter2 - (num1_decimal_size - num2_decimal_size);	//将指向调整到一一对应的位置

			while (iter1 != num1.decimal.end() && iter2 != num2.decimal.end())
			{
				(*iter1) = (*iter1) + (*iter2) + carry;
				carry = ((*iter1) > 9);	//如果大于9则carry=1
				(*iter1) = (*iter1) % 10;
				iter1++;
				iter2++;
			}

			it = num2.decimal.begin();
			iter2 = num2.decimal.end();
			iter2 = iter2 - num1_decimal_size - 1;	//指向长出部分
			while (iter2 != it)
			{
				num1.decimal.insert(num1.decimal.begin(), *iter2);
				iter2--;
			}
			num1.decimal.insert(num1.decimal.begin(), *iter2);
			iter1 = num1.decimal.begin();
		}
		else
			if (num1_decimal_size > num2_decimal_size) //如果num1小数部分更长,同理
			{
				iter1 = num1.decimal.begin();
				iter1 = iter1 + (num1_decimal_size - num2_decimal_size);
				//将指向调整到一一对应的位置
				iter2 = num2.decimal.begin();

				while (iter1 != num1.decimal.end() && iter2 != num2.decimal.end())
				{
					(*iter1) = (*iter1) + (*iter2) + carry;
					carry = ((*iter1) > 9);	//如果大于9则carry=1
					(*iter1) = (*iter1) % 10;
					iter1++;
					iter2++;
				}
			}
			else
			{
				iter1 = num1.decimal.begin();	//如果二者等长
				iter2 = num2.decimal.begin();
				while (iter1 != num1.decimal.end() && iter2 != num2.decimal.end())
				{
					(*iter1) = (*iter1) + (*iter2) + carry;
					carry = ((*iter1) > 9);	//如果大于9则carry=1
					(*iter1) = (*iter1) % 10;
					iter1++;
					iter2++;
				}
			}

		//再处理整数部分
		iter1 = num1.integer.begin();
		iter2 = num2.integer.begin();
		//从个位开始相加
		while (iter1 != num1.integer.end() && iter2 != num2.integer.end())
		{
			(*iter1) = (*iter1) + (*iter2) + carry;
			carry = ((*iter1) > 9);	//如果大于9则carry=1
			(*iter1) = (*iter1) % 10;
			iter1++;
			iter2++;
		}
		//总会有一个先到达end()
		while (iter1 != num1.integer.end())	//如果被加数更长,处理进位
		{
			(*iter1) = (*iter1) + carry;
			carry = ((*iter1) > 9);	//如果大于9则carry=1
			(*iter1) = (*iter1) % 10;
			iter1++;
		}
		while (iter2 != num2.integer.end())	//加数更长
		{
			char val = (*iter2) + carry;
			carry = (val > 9);
			val %= 10;
			num1.integer.push_back(val);
			iter2++;
		}
		if (carry != 0)	//如果还有进位,则说明要添加一位
		{
			num1.integer.push_back(carry);
		}
		return num1;
	}
	else
	{	//如果异号
		if (num1.tag)	//如果被加数为正,加数为负,相当于减等于
		{
			WFloat temp(-num2);
			return num1 -= temp;
		}
		else
		{
			WFloat temp(-num1);
			return num1 = num2 - temp;
		}
	}
}
WFloat operator-=(WFloat& num1, const WFloat& num2)	//减等于重载
{
 	if (num1.tag == num2.tag)	//只处理同号,异号由+加法处理
	{
		if (num1.tag)	//如果同为正
		{
			if (num1 < num2)	//且被减数小
			{
				WFloat temp(num2 - num1);
				num1 = -temp;
				return num1;
			}
		}
		else
		{
			if (-num1 > -num2)	//如果同为负,且被减数绝对值大
				return num1 = -((-num1) - (-num2));
			else
				return num1 = (-num2) - (-num1);
		}

		//下面是同为正,且减数小的情况
		//小数部分 
		char borrow = 0;  //借位
		int num1_decimal_size = num1.decimal.size();
		int num2_decimal_size = num2.decimal.size();
		vector<char>::iterator it1 = num1.decimal.begin();
		vector<char>::const_iterator it2 = num2.decimal.begin();

		if (num1_decimal_size > num2_decimal_size)	//如果被减数小数部分更长
		{
			num1_decimal_size -= num2_decimal_size;	//长出部分
			it1 = it1 + num1_decimal_size;	//跳过长出部分
		}
		else 
		{	//如果减数的小数部分更长,则需要给被减数补0
			int number = num2_decimal_size - num1_decimal_size;
			while (number != 0)
			{
				num1.decimal.insert(num1.decimal.begin(), 0); //缺少的位数补0
				number--;
			}
			it1 = num1.decimal.begin();	//插入后需要重新指向
			it2 = num2.decimal.begin();
		}
		while ((it1 != num1.decimal.end()) && (it2 != num2.decimal.end()))
		{
			(*it1) = (*it1) - (*it2) - borrow;
			borrow = 0;
			if ((*it1) < 0)
			{
				borrow = 1;
				(*it1) += 10;
			}
			it1++;
			it2++;
		}
		//整数部分
		vector<char>::iterator iter1;
		vector<char>::const_iterator iter2;
		iter1 = num1.integer.begin();
		iter2 = num2.integer.begin();

		while (iter1 != num1.integer.end() && iter2 != num2.integer.end())
		{
			(*iter1) = (*iter1) - (*iter2) - borrow;
			borrow = 0;
			if ((*iter1) < 0) {
				borrow = 1;
				(*iter1) += 10;
			}
			iter1++;
			iter2++;
		}
		while (iter1 != num1.integer.end()) {
			(*iter1) = (*iter1) - borrow;
			borrow = 0;
			if ((*iter1) < 0) 
			{
				borrow = 1;
				(*iter1) += 10;
			}
			else break;
			iter1++;
		}
		num1.trim();	//把多余的0去掉
		return num1;
	}
	else 
	{
		//如果异号
		if (num1 > WFloat::ZERO)
		{
			WFloat temp(-num2);
			return num1 += temp;
		}
		else
		{ 
			WFloat temp(-num1);
			return num1 = -(num2 + temp);
		}
	}
}
WFloat operator*=(WFloat& num1, const WFloat& num2)	//乘等于重载
{
	WFloat result(0);	//储存结果
	if (num1 == WFloat::ZERO || num2 == WFloat::ZERO)	//有0做乘数得0
		result = WFloat::ZERO;
	else
	{
		int size = 0;
		vector<char>temp_num1(num1.integer.begin(), num1.integer.end());	//一个临时变量,用于将整数部分与小数部分合并
		if (num1.decimal.size() != 1 || (num1.decimal.size() == 1 && (*num1.decimal.begin()) != 0)) //如果被乘数有小数部分,插入小数
		{
			temp_num1.insert(temp_num1.begin(), num1.decimal.begin(), num1.decimal.end());
			size += num1.decimal.size();
		}
		
		vector<char>temp_num2(num2.integer.begin(), num2.integer.end());	//一个临时变量,用于将整数部分与小数部分合并
		if (num2.decimal.size() != 1 || (num2.decimal.size() == 1 && (*num2.decimal.begin()) != 0)) //如果被乘数有小数部分,插入小数
		{
			temp_num2.insert(temp_num2.begin(), num2.decimal.begin(), num2.decimal.end());
			size += num2.decimal.size();
		}

		//开始乘法
		vector<char>::const_iterator iter2 = temp_num2.begin();
		while (iter2 != temp_num2.end())
		{
			if (*iter2 != 0)
			{
				deque<char>temp(temp_num1.begin(), temp_num1.end());
				char carry = 0;	//进位
				deque<char>::iterator iter1 = temp.begin();
				while (iter1 != temp.end())	//被乘数乘以某一位乘数
				{
					(*iter1) *= (*iter2);
					(*iter1) += carry;
					carry = (*iter1) / 10;
					(*iter1) %= 10;
					iter1++;
				}
				if (carry != 0)
				{
					temp.push_back(carry);
				}
				int num_of_zeros = iter2 - temp_num2.begin();	//计算错位
				while (num_of_zeros--) 
					temp.push_front(0);	//乘得结果后面添0
				WFloat temp2;
				temp2.integer.clear();
				temp2.integer.insert(temp2.integer.end(), temp.begin(), temp.end());
				temp2.trim();
				result = result + temp2;
			}
			iter2++;
		}
		result.tag = ((num1.tag && num2.tag) || (!num1.tag && !num2.tag));

		//由于我们将小数和整数合并在一起,因此下面要把小数点重新添上
		if (size != 0)
		{
			if (size >= result.integer.size())	//说明需要补前导0
			{
				int n = size-result.integer.size();
				for (int i = 0; i <= n; i++)
					result.integer.insert(result.integer.end(), 0);
			}
			result.decimal.clear();
			result.decimal.insert(result.decimal.begin(), result.integer.begin(), result.integer.begin() + size);
			result.integer.erase(result.integer.begin(), result.integer.begin() + size);
		}
	}
	num1 = result;
	num1.trim();
	return num1;
}
WFloat operator/=(WFloat& num1, const WFloat& num2) throw(DividedByZeroException)	//除等于重载
{
	if (num2 == WFloat::ZERO)
		throw DividedByZeroException();
	if (num1 == WFloat::ZERO)
		return num1;

	WFloat temp_num1 = num1;
	WFloat temp_num2 = num2;
	if (temp_num1.tag == false || temp_num2.tag == false)	//转换成无符号除法来做
	{
		temp_num1.tag = true;
		temp_num2.tag = true;
	}
	
	int Integer_Size = 0;	//整数部分应为几位
	if ((temp_num2.decimal.size() == 1) && (*(temp_num2.decimal.begin()) == 0)) {} //如果除数没有小数部分,不做操作
	else
	{
		//否则把除数和乘数同时扩大,直到除数为整数(只对Integer部分运算)
		int t = temp_num2.decimal.size();
		while (t--)
		{
			temp_num1 = temp_num1 * WFloat::TEN;
			temp_num2 = temp_num2 * WFloat::TEN;
		}
	}
	if (temp_num1 < temp_num2)	//被除数小于除数,应该是0.xxx
	{
		while (temp_num1 < temp_num2)
		{
			temp_num1 *= WFloat::TEN;
			Integer_Size--;
		}
	}
	else
	{
		while (temp_num1 > temp_num2)
		{
			temp_num1.decimal.push_back(*temp_num1.integer.begin());
			temp_num1.integer.erase(temp_num1.integer.begin());
			Integer_Size++;
		}
	}

	int k = ACCURACY;
	WFloat quotient(0);	//商

	while (k--)
	{
		if (temp_num1 < temp_num2)
		{
			temp_num1 = temp_num1 * WFloat::TEN;
			quotient = quotient * WFloat::TEN;
		}
		else
		{
			int i;
			WFloat compare;
			for (i = 1; i <= 10; i++)	//“试商”
			{
				WFloat BF(i);
				compare = temp_num2 * BF;
				if (compare > temp_num1)
					break;
			}
			compare -= temp_num2;
			temp_num1 -= compare;
			WFloat index(i - 1);
			quotient = quotient + index;
		}
	}

	if (Integer_Size < 0)	//如果是小数除以大数,结果为0.xxx
	{
		vector<char> temp(quotient.integer.begin(), quotient.integer.end());
		quotient.integer.clear();
		quotient.integer.push_back(0);	//整数部分为0

		quotient.decimal.clear();
		int count_zero = -Integer_Size;
		//下面先补充前导0
		while (--count_zero)
		{
			quotient.decimal.insert(quotient.decimal.begin(), 0);
		}
		quotient.decimal.insert(quotient.decimal.begin(), temp.begin(), temp.end());
	}
	else
	{
		if (quotient.integer.size() > Integer_Size)
		{
			vector<char> temp(quotient.integer.begin(), quotient.integer.end());

			quotient.integer.clear();	//这里如果不清空会有错误

			quotient.integer.assign(temp.end() - Integer_Size, temp.end());

			quotient.decimal.clear();	//同理需要清空

			quotient.decimal.insert(quotient.decimal.begin(), temp.begin(), temp.end() - Integer_Size);
		}
		else
		{
			//这一部分意义不明,我觉得不会走到这个分支
			int t = Integer_Size - quotient.integer.size();
			while (t--)
			{
				quotient = quotient * WFloat::TEN;
			}
		}
	}
	quotient.tag = ((num1.tag && num2.tag) || (!num1.tag && !num2.tag));
	num1 = quotient;
	num1.trim();
	return num1;
}
WFloat operator+(const WFloat& num1, const WFloat& num2)	//调用+=
{
	WFloat temp(num1);
	temp += num2;
	return temp;
}

WFloat operator-(const WFloat& num1, const WFloat& num2)	//调用-=
{
	WFloat temp(num1);
	temp -= num2;
	return temp;
}

WFloat operator*(const WFloat& num1, const WFloat& num2)	//调用*=
{
	WFloat temp(num1);
	temp *= num2;
	return temp;
}

WFloat operator/(const WFloat& num1, const WFloat& num2)  throw(DividedByZeroException)	//调用/=
{
	WFloat temp(num1);
	temp /= num2;
	return temp;
}

#endif

Window.h

#ifndef WINDOW_H_
#define WINDOW_H_

#include<windows.h>
namespace wp
{
	class Window
	{
		HDC hdc=NULL;
		public:
			Window() = default;
			Window(HDC h):hdc(h){}
			Window(PAINTSTRUCT ps):hdc(ps.hdc){}
			~Window() = default;
			int drawPoint(int x,int y,COLORREF color)
			{
				if(hdc!=NULL)
				{
					SetPixel(hdc,x,y,color);
					return 0;
				}
				else return 100;
			}
			int drawLine(int x1,int y1,int x2,int y2,COLORREF color)
			{
				if(hdc!=NULL)
				{
					if(x1==x2)
					{
						for(int i=y1;i<=y2;i++)
							this->drawPoint(x1,i,color);
						return 0;
					}
					if(y1==y2)
					{
						for(int i=x1;i<=x2;i++)
							this->drawPoint(i,y1,color);
						return 0;
					}
					return 255;
				}
				else return 100;
			}
			int drawRect(int x1,int y1,int x2,int y2,COLORREF color)
			{
				if(hdc!=NULL)
				{
					for(int i=x1;i<=x2;i++)
						for(int j=y1;j<=y2;j++)
							this->drawPoint(i,j,color);
					return 0;
				}
				else return 100;
			}
			int drawText(int x,int y,char *text)
			{
				if(hdc!=NULL)
				{
					TextOut(hdc,x,y,text,strlen(text));
					return 0;
				}
				else return 100;
			}
			int drawTextW(char *text,LPRECT rect,UINT format)
			{
				if(hdc!=NULL)
				{
					DrawText(hdc,text,-1,rect,format);
					return 0;
				}
				else return 100;
			}
	};
}//end namespace wp

#endif

wpstring.h

#ifndef WINDOW_H_
#define WINDOW_H_

#include<windows.h>
namespace wp
{
	class Window
	{
		HDC hdc=NULL;
		public:
			Window() = default;
			Window(HDC h):hdc(h){}
			Window(PAINTSTRUCT ps):hdc(ps.hdc){}
			~Window() = default;
			int drawPoint(int x,int y,COLORREF color)
			{
				if(hdc!=NULL)
				{
					SetPixel(hdc,x,y,color);
					return 0;
				}
				else return 100;
			}
			int drawLine(int x1,int y1,int x2,int y2,COLORREF color)
			{
				if(hdc!=NULL)
				{
					if(x1==x2)
					{
						for(int i=y1;i<=y2;i++)
							this->drawPoint(x1,i,color);
						return 0;
					}
					if(y1==y2)
					{
						for(int i=x1;i<=x2;i++)
							this->drawPoint(i,y1,color);
						return 0;
					}
					return 255;
				}
				else return 100;
			}
			int drawRect(int x1,int y1,int x2,int y2,COLORREF color)
			{
				if(hdc!=NULL)
				{
					for(int i=x1;i<=x2;i++)
						for(int j=y1;j<=y2;j++)
							this->drawPoint(i,j,color);
					return 0;
				}
				else return 100;
			}
			int drawText(int x,int y,char *text)
			{
				if(hdc!=NULL)
				{
					TextOut(hdc,x,y,text,strlen(text));
					return 0;
				}
				else return 100;
			}
			int drawTextW(char *text,LPRECT rect,UINT format)
			{
				if(hdc!=NULL)
				{
					DrawText(hdc,text,-1,rect,format);
					return 0;
				}
				else return 100;
			}
	};
}//end namespace wp

#endif

王牌工作室官方在2022-02-12 19:39:16追加了内容

wpstring.h复制错了

#ifndef WPSTRING_H_
#define WPSTRING_H_

#include<vector>
#include<string>
#include<stdio.h>
using std::vector;
using std::string;
vector<string> substr(string s,char ch)
{
	vector<string> ary;
	s=ch+s+ch;
	int l,r;
	for(int i=1;i<s.size();i++)
	{
		if(s[i-1]==ch&&s[i]!=ch)
		{
			l=i;
		}
		if(s[i]==ch&&s[i-1]!=ch)
		{
			r=i;
			ary.push_back(s.substr(l,r-l));
		}
	}
	return ary;
}
const char *strcat(char *buffer,char *str1,char *str2)
{
	if(buffer==NULL)
	{
		static char _Buffer[1024];
		sprintf(_Buffer,"%s%s",str1,str2);
		return _Buffer;
	}
	else
	{
		sprintf(buffer,"%s%s",str1,str2);
		return buffer;
	}
}

#endif

 

王牌工作室官方在2022-02-12 19:42:04追加了内容

使用方法:

#include<wp/文件名.h>


0
0
0
我要回答