mytool.cpp
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:9k
- #include "stdafx.h"
- #include "windows.h"
- #include "stdio.h"
- #include "string.h"
- #include "time.h"
- #include "mytool.h"
- #include "formula.h"
- mytool::mytool()
- {
- strcpy(DaNum, "零壹贰叁肆伍陆柒捌玖");
- strcpy(DaDanwei , "元拾佰仟万拾佰仟亿拾佰仟特拾佰仟吉拾佰仟伯拾佰仟令拾佰仟阿拾佰仟库拾佰仟依拾佰仟斯拾佰仟舌拾佰仟扣拾佰仟磊拾佰仟比拾佰仟吕拾佰仟加拾佰仟须拾佰仟辰拾佰仟奔拾佰仟左拾佰仟马拾佰仟肥拾佰仟夺拾佰仟扔拾佰仟盍拾佰仟厚拾佰仟度拾佰仟磁拾佰仟顺拾佰仟");
- strcpy(DaNumE, "○一二三四五六七八九十");
- }
- mytool::~mytool()
- {
-
- }
- /////////////////////////////////////////////////////////////
- //分析字符串确定串格式
- //0表示不正确,1数字型,2日期型,3表达式
- int mytool::analysisStr(char *ssp)
- {
- int i,len,pt=0,ret=0,flage=0;
- len=strlen(ssp);
- //查看是否有非法字符
- for(i=0;i<len;i++)
- {
- if('0'<=ssp[i] && ssp[i]<='9')
- continue;
- if(ssp[i]=='+'||ssp[i]=='-'||ssp[i]=='*'||ssp[i]=='/'||ssp[i]=='^')
- continue;
- if(ssp[i]=='.'||ssp[i]=='('||ssp[i]==')'||ssp[i]==' ')
- continue;
- if((ssp[i]==-93 && ssp[i+1]==-85)||(ssp[i]==-93 && ssp[i+1]==-83))
- {
- i++;
- continue;
- }
- if((ssp[i]==-95 && ssp[i+1]==-63)||(ssp[i]==-95 && ssp[i+1]==-62))
- {
- i++;
- continue;
- }
- break;
- }
- if(i==len)
- {
- for(i=0;i<len;i++)
- {
- if('0'<=ssp[i] && ssp[i]<='9')
- flage=1;
- if('.'==ssp[i])
- pt++;
- if(ssp[i]=='+'||ssp[i]=='-'||ssp[i]=='*'||ssp[i]=='/'||ssp[i]=='^')
- {
- ret=3;
- break;
- }
- if((ssp[i]==-93 && ssp[i+1]==-85)||(ssp[i]==-93 && ssp[i+1]==-83))
- {
- ret=3;
- break;
- }
- if((ssp[i]==-95 && ssp[i+1]==-63)||(ssp[i]==-95 && ssp[i+1]==-62))
- {
- ret=3;
- break;
- }
- }
- if(ret==0)
- {
- if(pt==2)
- ret=2;
- if(pt<2 && flage==1)
- ret=1;
- }
- }
- // MessageBox (0,ss,0,0);
- return ret;
- }
- mytool::TranDaxieDollor(char *source,char *Daxie)
- {
- int i,point,len;
- char tem[1000]="",tem2[1000]="",ss1[10],ss2[10];
- char pss[20]="";
- ss1[2]=ss2[2]=0;
- //确定小数点
- strcpy(pss,"整");
- len=strlen(source);
- point=len-1;
- for(i=0;i<len;i++)
- {
- if('.'==source[i])
- {
- point=i;
- pss[0]=0;
- if(i+1<len)
- {
- ss1[0]=DaNum[(source[i+1]-0x30)*2];
- ss1[1]=DaNum[(source[i+1]-0x30)*2+1];
- strcat(ss1,"角");
- strcat(pss,ss1);
- }
- if(i+2<len)
- {
- ss1[0]=DaNum[(source[i+2]-0x30)*2];
- ss1[1]=DaNum[(source[i+2]-0x30)*2+1];
- ss1[2]=0;
- strcat(ss1,"分");
- strcat(pss,ss1);
- }
- break;
- }
- }
- //
- for(i=0;i<point;i++)
- {
- ss1[0]=DaNum[(source[point-i-1]-0x30)*2];
- ss1[1]=DaNum[(source[point-i-1]-0x30)*2+1];
- ss1[2]=0;
- ss2[0]=DaDanwei[i*2];
- ss2[1]=DaDanwei[i*2+1];
- ss2[2]=0;
- sprintf(tem2,"%s%s%s",ss1,ss2,tem);
- strcpy(tem,tem2);
- }
- strcat(tem,pss);
- strcpy(Daxie,tem);
- }
- mytool::TranDaxieNum(char *source,char *Daxie)
- {
- int i,len;
- char tem[1000]="",tem2[1000]="",ss1[3];
- ss1[2]=0;
- //
- len=strlen(source);
- for(i=0;i<len;i++)
- {
- if(source[i]!='.')
- {
- ss1[0]=DaNum[(source[i]-0x30)*2];
- ss1[1]=DaNum[(source[i]-0x30)*2+1];
- sprintf(tem2,"%s%s",tem,ss1);
- strcat(tem,ss1);
- }
- else
- {
- strcat(tem,"点");
- }
- }
- strcpy(Daxie,tem);
- }
- ////////////////////////////////////////////////////////////
- //日期处理
- mytool::GetDate(char *ss)
- {
- SYSTEMTIME systime;
- GetSystemTime (&systime);
- sprintf(ss,"%d年%d月%d日", systime.wYear,systime.wMonth,systime.wDay);
- }
- mytool::GetDateChina(char *ss)
- {
- SYSTEMTIME systime;
- GetSystemTime (&systime);
- sprintf(ss,"%d年%d月%d日", systime.wYear,systime.wMonth,systime.wDay);
- TranDateChina(ss,systime);
- }
- mytool::TranDate(char *ss,SYSTEMTIME systime)
- {
- GetSystemTime (&systime);
- sprintf(ss,"%d年%d月%d日", systime.wYear,systime.wMonth,systime.wDay);
- }
- mytool::TranDateChina(char *ss,SYSTEMTIME systime)
- {
- int i,tt,tt2;
- char nn[10]="",yy[10]="",rr[10]="";
- char tem1[1000]="",ss1[3];
- ss1[2]=0;
- tt=systime.wYear;
- for(i=0;i<4;i++)
- {
- tt2=tt%10;
- ss1[0]=DaNumE[tt2*2];
- ss1[1]=DaNumE[tt2*2+1];
- sprintf(tem1,"%s%s",ss1,nn);
- strcpy(nn,tem1);
- tt=tt/10;
- }
- //////////////////////////////////////////////////////////
- if(systime.wMonth==10)
- {
- strcpy(yy,"十");
- }
- else
- {
- if(systime.wMonth>9)
- {
- ss1[0]=DaNumE[systime.wMonth%10*2];
- ss1[1]=DaNumE[systime.wMonth%10*2+1];
- sprintf(tem1,"%s",ss1);
- ss1[0]=DaNumE[systime.wMonth/10*2];
- ss1[1]=DaNumE[systime.wMonth/10*2+1];
- sprintf(yy,"%s十%s",ss1,tem1);
- }
- else
- {
- ss1[0]=DaNumE[systime.wMonth*2];
- ss1[1]=DaNumE[systime.wMonth*2+1];
- strcpy(yy,ss1);
- }
- }
- //////////////////////////////////////////////////////////
- if(systime.wDay==10)
- {
- strcpy(yy,"十");
- }
- else
- {
- if(systime.wDay>9)
- {
- ss1[0]=DaNumE[systime.wDay%10*2];
- ss1[1]=DaNumE[systime.wDay%10*2+1];
- sprintf(tem1,"%s",ss1);
- ss1[0]=DaNumE[systime.wDay/10*2];
- ss1[1]=DaNumE[systime.wDay/10*2+1];
- sprintf(rr,"%s十%s",ss1,tem1);
- }
- else
- {
- ss1[0]=DaNumE[systime.wDay*2];
- ss1[1]=DaNumE[systime.wDay*2+1];
- strcpy(rr,ss1);
- }
- }
- sprintf(ss,"%s年%s月%s日",nn,yy,rr);
- }
- //返回非零说明有错误发生
- int mytool::formcaculate(char *formss,double *retvar)
- {
- formula ff;
- ff.caculate(formss);
- return ff.getformulaVar(retvar);
- }
- //97版的mdb
- BOOL mytool::mypassmdb (char * FileName,char *Pass)
- {
- char cWord[13];
- FILE *fp;
- fp = fopen(FileName,"rb"); //打开文字文件只读
- if (fp == 0)
- {
- MessageBox (0,"文件不能打开!",0,0);
- return 0;
- }
- if (GetFileSize(fp,0) <= 80)
- {
- MessageBox (0,"这不是Mdb文件!",0,0);
- return 0;
- }
- fseek(fp, 66,SEEK_SET);//寻至密码处
- fread (cWord,13,1,fp); //读出加密器
- fclose (fp);
- if ((BYTE)(cWord[0] ^ 0x86) == 0)//判断有无密码
- strcpy(Pass,"No Password");
- else
- { //对加密串进行逐位解密
- cWord[0] ^= 0x86;
- cWord[1] ^= 0xFB;
- cWord[2] ^= 0xEC;
- cWord[3] ^= 0x37;
- cWord[4] ^= 0x5D;
- cWord[5] ^= 0x44;
- cWord[6] ^= 0x9C;
- cWord[7] ^= 0xFA;
- cWord[8] ^= 0xC6;
- cWord[9] ^= 0x5E;
- cWord[10] ^= 0x28;
- cWord[11] ^= 0xE6;
- cWord[12] ^= 0x13;
- strcpy(Pass,cWord);//返回解明码
- }
- // MessageBox (0,Pass,0,0);
- return 0;
- }
- void mytool::TranComStr(int selet ,char *retss)
- {
- int len,ret,i,pt;
- double tem;
- char ss[1001];
- if(selet==2)
- {
- GetAsyncKeyState(16);
- if(GetAsyncKeyState(16)==0)
- GetDate(retss);
- else
- GetDateChina(retss);
- }
- if(selet==1)
- {
- SendMessage(GetFocus(), WM_COPY, 1, 0);
- // 1 创建一个新的COleDataObject对象
- COleDataObject obj;
- // 2 检查剪贴板中数据格式是否满足需要
- if (obj.AttachClipboard()) {
- if (obj.IsDataAvailable(CF_TEXT)) {
- HGLOBAL hmem = obj.GetGlobalData(CF_TEXT);
- CMemFile sf((BYTE*) ::GlobalLock(hmem), ::GlobalSize(hmem));
- CString buffer;
- // 3 将剪贴板中的数据放到CMemFile对象中
- //当然你可以用其他的内存对象或者自定义的数据类型或对象
- LPSTR str = buffer.GetBufferSetLength(::GlobalSize(hmem));
-
- // 4 从CMemFile对象中读出数据
- sf.Read(str,::GlobalSize(hmem));
- ::GlobalUnlock(hmem);
- // 5 用数据做相关操作
- //TRACE("Paste received = '%s'rn", buffer);
- if(buffer.GetLength()>0)
- {
- sprintf(ss,"%s",buffer);
- ret=analysisStr(ss);
- if(ret==1)
- TranDaxieNum(ss,retss);
- if(ret==2)
- TranDaxieNum(ss,retss);
- if(ret==3)
- {
- ret=formcaculate(ss,&tem);
- if(ret!=-1)
- {
- //sprintf(retss,"%d %lf",ret,tem);
- sprintf(retss,"%lf",tem);
- //结果去尾0处理
- pt=-1;
- len=strlen(retss);
- for(i=0;i<len;i++)
- {
- if('.'==retss[i])
- {
- pt=i;
- break;
- }
- }
- if(pt!=-1)
- {
- for(i=len-1;i>=0;i--)
- {
- if(retss[i]=='0')
- retss[i]=0;
- else
- {
- if(retss[i]=='.')
- retss[i]=0;
- break;
- }
- }
- }
- //结果去尾0处理END
- }
- else
- {
- retss[0]=0;
- }
- }
- }
- }
- }
- }
- }
- //本段程序为附加程序,用于获取指定窗口的内容
- void getAppss(int wparam)
- {
- if(wparam==32)
- {
- long t;
- t=GetWindowTextLength(GetFocus());
- if(t>200000)
- { MessageBox(0,"被复制对象不大于20万字节",0,0);
- t=200000;
- }
- HANDLE hGlobalMemory = GlobalAlloc(GHND, t + 1); // 分配内存
- LPBYTE lpGlobalMemory = (LPBYTE)GlobalLock(hGlobalMemory),lpgmem; // 锁定内存
- lpgmem=lpGlobalMemory;
- /*lstr=(char*)malloc(t+1);
- if(lstr==0 || hGlobalMemory==0)
- { MessageBox(0,"分配内存失败",0,0);
- sprintf(ss,"%ld",hGlobalMemory);
- }*/
- // free(lstr);
-
- if(t>4000)
- {
- char ss[200001];
- SendMessage(GetFocus(), WM_GETTEXT, t, (LPARAM)ss);
- ss[t]=0;
- for(int i=0;i<t;i++)
- *(lpgmem++)=ss[i];
- *(lpgmem)=0;
- }
- else
- {
- char ss[4001];
- SendMessage(GetFocus(), WM_GETTEXT, t, (LPARAM)ss);
- ss[t]=0;
- for(int i=0;i<t;i++)
- *(lpgmem++)=ss[i];
- *(lpgmem)=0;
- }
- GlobalUnlock(hGlobalMemory); // 锁定内存块解锁
- OpenClipboard(GetFocus());
- GetClipboardFormatName(0,0,0);
- EmptyClipboard();
- //GetClipboardData(CF_TEXT)
- SetClipboardData(CF_TEXT,hGlobalMemory);
- GlobalFree(hGlobalMemory);
- // strcat(tems,"进入剪切板");
- CloseClipboard();
- }
- }