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"
- #include "../DllManager.h"
- extern DllManager ChLib;//定义在主DLL中
- 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;
- }
- //////////////////////////////////////////////////////////
- tt=systime.wMonth%10;
- tem1[0]=0;
- if(tt>0)
- {
- ss1[0]=DaNumE[tt*2];
- ss1[1]=DaNumE[tt*2+1];
- ss1[2]=0;
- sprintf(tem1,"%s",ss1);
- }
- tt=systime.wMonth/10;
- if(tt>0)
- {
- ss1[0]=0;
- if(tt>1)
- {
- ss1[0]=DaNumE[tt*2];
- ss1[1]=DaNumE[tt*2+1];
- ss1[2]=0;
- }
- sprintf(yy,"%s十%s",ss1,tem1);
- }
- else
- sprintf(yy,"%s",tem1);
- //////////////////////////////////////////////////////////
- tt=systime.wDay%10;
- tem1[0]=0;
- if(tt>0)
- {
- ss1[0]=DaNumE[tt*2];
- ss1[1]=DaNumE[tt*2+1];
- ss1[2]=0;
- sprintf(tem1,"%s",ss1);
- }
- tt=systime.wDay/10;
- if(tt>0)
- {
- ss1[0]=0;
- if(tt>1)
- {
- ss1[0]=DaNumE[tt*2];
- ss1[1]=DaNumE[tt*2+1];
- ss1[2]=0;
- }
- sprintf(rr,"%s十%s",ss1,tem1);
- }
- else
- sprintf(rr,"%s",tem1);
- 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];
- char buffer[2000]="";
- if(selet==2)
- {
- GetAsyncKeyState(16);
- if(GetAsyncKeyState(16)==0)
- GetDate(retss);
- else
- GetDateChina(retss);
- }
- if(selet==1) //万能转换
- {
- SendMessage(GetFocus(), WM_COPY, 1, 0);
- {
- OpenClipboard(GetFocus());
- if(IsClipboardFormatAvailable (CF_TEXT)!=0)
- {
- HANDLE hmem = GetClipboardData(CF_TEXT);
- if(hmem!=0)
- {
- char *pp=(char*)GlobalLock(hmem);
- strcpy(buffer,pp);
- if(buffer[strlen(buffer)-2]==13||buffer[strlen(buffer)-2]==10)
- buffer[strlen(buffer)-2]=0;//清除回车
- GlobalUnlock(hmem);
- }
- }
- CloseClipboard();
- }
- if(strlen(buffer)>0) //得到数据
- {
- sprintf(ss,"%s",buffer);
- ret=analysisStr(ss);
- //sprintf(ss,"%d",ret);
- //MessageBox(0,"dd",ss,0);
- if(ret==0){
- char temss[20];
- ChLib.ChissToCodeC("c:\jsime\MainCode.txt", ss, temss);
- if(strlen(buffer)>0) //得到数据
- {
- // MessageBox(0,ss,temss,0);
- strcpy(retss,temss);
- }
- }
- 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;
- }
- }//3
- }
- }
- }
- //本段程序为附加程序,用于获取指定窗口的内容
- 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();
- }
- }