ResManager.cpp
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:8k
- #include "stdafx.h"
- #include "stdio.h"
- #include "CMyWnd.h"
- #include "stdafx.h"
- #include "windows.h"
- #include "ResManager.h"
- mytimers::mytimers()
- {
- int i;
- for(i=0;i<6;i++)
- {
- time[i]=0;
- num[i]=0;
- }
- pt=0;
- }
- mytimers::~mytimers()
- {
- ;
- }
- mytimers::appnum(int applong)//增加长度计数
- {
- num[pt]+=applong;
- }
- mytimers::apptime()//增加一次计数
- {
- time[pt]++;
- if(time[pt]==60)
- {
- pt=(pt+1)%5;
- time[pt]=0;
- num[pt]=0;
- }
- }
- mytimers::reset()//重设计器器
- {
- int i;
- for(i=0;i<6;i++)
- {
- time[i]=0;
- num[i]=0;
- }
- pt=0;
- }
- int mytimers::GetAverage()//得到平均数
- {
- int i,tt=0,tn=0,ret;
- for(i=0;i<5;i++)
- {
- tt+=time[i];
- tn+=num[i];
- }
- if(tt==0)
- ret=0;
- else
- ret=tn*60/tt;
- if(ret==0&& tt>0)
- reset();
- return ret;//每分多少个。
- }
- /////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
- ResManager::ResManager()
- {
- char ss[100]="";
-
- //注册表的读取
- ////////////////////////////////////////////////////////////////
- //
- RegReadString("textflage",ss); //
- if(ss[0]==0)
- textflage[0]='1';
- else
- textflage[0]=ss[0];
- textflage[1]=0;
- ////////////////////////////////////////////////////////////////
- //窗口跟踪灵敏度,默认为3
- RegReadString("traceflage",ss); //跟踪10个级别0立即,9锁定
- if(ss[0]<'0' || ss[0]>'9')
- {
- //RegSaveString("traceflage","3");
- traceflage[0]='3';
- }
- else
- textflage[0]=ss[0];
- traceflage[1]=0;
- ////////////////////////////////////////////////////////////////
- //默认为有滚动
- RegReadString("scrollflage",ss); //滚动显示1,0
- if(ss[0]==0)
- scrollflage[0]='1';
- else
- scrollflage[0]=ss[0];
- scrollflage[1]=0;//设置字符串结尾
- ////////////////////////////////////////////////////////////////
- //默认为200
- clarityflage=(unsigned char)ReadReg("clarityflage"); //透明度
- if(clarityflage==0)
- clarityflage=200;
-
- ////////////////////////////////////////////////////////////////
- //默认为有边框
- RegReadString("frameflage",ss); //边框1为有,0为没有
- if(ss[0]==0)
- frameflage[0]='1';
- else
- frameflage[0]=ss[0];
- frameflage[1]=0;//设置字符串结尾
- ////////////////////////////////////////////////////////////////
- //
- RegReadString("autoword",ss);
- if(ss[0]==0)
- autoword[0]='1';
- else
- autoword[0]=ss[0];
- autoword[1]=0;
- ////////////////////////////////////////////////////////////////
- //窗花
- RegReadString("flowerflage",ss); //启用窗花1,0
- if(ss[0]==0)
- flowerflage[0]='1';
- else
- flowerflage[0]=ss[0];
- flowerflage[1]=0;
- CurBackPic[0]=0;
- ////////////////////////////////////////////////////////////////
- //模式号:1基本优先 2扩展优先 3五笔模式 4扩展模式
- RegReadString("CurModleNum",ss); //启用窗花1,0
- if(ss[0]==0)
- CurModleNum=1;
- else
- CurModleNum=ss[0]-0x30;
- }
- ResManager::~ResManager()
- {
- DeleteDC (LinebarDC);
- DeleteObject(LinebarhBmp);
- DeleteDC (LinebarDC1);
- DeleteObject(LinebarhBmp1);
- ////////////////////////////////
- DeleteDC (BackDC);
- DeleteObject(BackhBmp);
- DeleteDC (reBackDC);
- DeleteObject(reBackhBmp);
- ///////////////////////////////
- DeleteDC (oldBackDC);
- DeleteObject(oldBackhBmp);
- /////////////////////////////////
- DeleteDC (Flashhdc);
- DeleteObject(Flashhdcbmp);
- }
- int ResManager::FixBackPic()
- {
- char dd[500]="";
- RegReadString("backpic",dd);
- if(dd[0]==0){
- // MessageBox(0,0,dd,0);
- RegSaveString("backpic",CurBackPic);
- //RegReadString("backpic",dd);
- //MessageBox(0,CurBackPic,dd,0);
- }else{
- RegSaveString("backpic","");
- //MessageBox(0,CurBackPic,"save",0);
- }
- // RegSaveString("backpic",CurBackPic);
- return 0;
- }
- ResManager::InitResManager(HDC L_WindDC,HINSTANCE L_hInst,int L_WinWidth,int L_WinHeight)
- {
- // HBRUSH hHBr;
- try {
- WindDC =L_WindDC;;
- hInst =L_hInst; ;
- WinWidth =L_WinWidth; ;
- WinHeight =L_WinHeight; ;
- //两个选择线图片的装入
- LinebarhBmp=(HBITMAP)LoadBitmap(hInst,MAKEINTRESOURCE(IDB_myLine));
- LinebarDC = CreateCompatibleDC(WindDC);
- DeleteObject(SelectObject(LinebarDC,LinebarhBmp));
- LinebarhBmp1=(HBITMAP)LoadBitmap(hInst,MAKEINTRESOURCE(IDB_myLine1));
- LinebarDC1 = CreateCompatibleDC(WindDC);
- DeleteObject(SelectObject(LinebarDC1,LinebarhBmp1));
-
- loadback();
- oldBackhBmp=(HBITMAP)LoadBitmap(hInst,MAKEINTRESOURCE(IDB_Back));
- oldBackDC = CreateCompatibleDC(WindDC);
- DeleteObject(SelectObject(oldBackDC,oldBackhBmp));
- //-------------------------------------------------
- Flashhdc = CreateCompatibleDC(WindDC);
- Flashhdcbmp=CreateCompatibleBitmap(WindDC,WinWidth,WinHeight);
- DeleteObject(SelectObject(Flashhdc,Flashhdcbmp));
- } catch (...)
- {
- //RegSaveString("backpic","");
- //MessageBox(0,"ddd","dddd",0);
- }
- }
- ResManager::loadback()
- {
- HANDLE hfile;
- long tt=0;
- char fpath[500];
- char fname[500];
- DeleteDC (BackDC);
- DeleteObject(BackhBmp);
- DeleteDC (reBackDC);
- DeleteObject(reBackhBmp);
- try {
- //-------------------------------------------------
- //如果注册表中backpic键值中有正确的文件名,并能正确装载,背景图片就固定下来
- RegReadString("backpic",fname);
- BackhBmp=NULL;
- hfile=CreateFile(fname,GENERIC_READ,FILE_SHARE_READ ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
- if(hfile!=INVALID_HANDLE_VALUE)
- {
- CloseHandle(hfile);
- if(jpegpic.LoadJpegFile(WindDC,fname)) //成功,则重画窗口
- BackhBmp=jpegpic.hBitmap;
- if(BackhBmp==NULL)
- BackhBmp=(HBITMAP)LoadImage(0, fname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION );
- //MessageBox(0,fname,"CreateFile",0);
- }
- } catch (...) {
- //if( BackhBmp!=NULL)
- // DeleteObject(BackhBmp);
- BackhBmp=NULL;
- RegSaveString("backpic","");
- //MessageBox(0,"loadback","有错误发生",0);
- }
- if(BackhBmp==NULL)
- {
- GetModuleFileName(hInst,fpath,255);
- myGetPath(fpath); //取路径
- sprintf(fname,"%s\pic\back.jpg",fpath);
- if(jpegpic.LoadJpegFile(WindDC,fname)) //成功,则重画窗口
- BackhBmp=jpegpic.hBitmap;
- if(BackhBmp==NULL)
- BackhBmp=(HBITMAP)LoadImage(0, fname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION );
-
- //////////////////////////////////////////////////////////////////////
- if(BackhBmp==NULL){
- tt=findpicfile(fpath,"jpg");
- if(tt>0){
- sprintf(fname,"%s\pic\%d.jpg",fpath,tt);
- if(jpegpic.LoadJpegFile(WindDC,fname)) //成功,则重画窗口
- BackhBmp=jpegpic.hBitmap;
- }
- //MessageBox(0,fname,"有错误发生",0);
- }
- if(BackhBmp==NULL){
- tt=findpicfile(fpath,"bmp");
- if(tt>0){
- sprintf(fname,"%s\pic\%d.bmp",fpath,tt);
- BackhBmp=(HBITMAP)LoadImage(0, fname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION );
- }
- }
- ///////////////////////////////////////////////////////////////////////
- if(BackhBmp==NULL){
- BackhBmp=(HBITMAP)LoadBitmap(hInst,MAKEINTRESOURCE(IDB_Back));
- fname[0]=0;
- //当所有的装载都失败时,就启用DLL中的背景图片,保证所有情况下都有背景图片显示
- }
- }
- //保存当前的装入的图片名称,为空时说明使用了DLL中的背景。
- strcpy(CurBackPic,fname);
- //if(BackhBmp!=NULL)
- // MessageBox(0,CurBackPic,"功能暂时未编码",0);
- // DeleteObject(SelectObject(BackDC, hUIFont));
- BackDC = CreateCompatibleDC(WindDC);
- DeleteObject(SelectObject(BackDC,BackhBmp));
- //保存的一个备份背景
- reBackDC = CreateCompatibleDC(WindDC);
- reBackhBmp=CreateCompatibleBitmap(WindDC,WinWidth,WinHeight);
- DeleteObject(SelectObject(reBackDC,reBackhBmp));
- BitBlt(reBackDC,0,0,WinWidth,WinHeight,BackDC,0,0,SRCCOPY);
- }
- //得到随机文件的序号,
- long ResManager::findpicfile(char *fpath,char *typestr)
- {
- HANDLE hfile;
- long tt=0,i;
- char fname[500];
- fname[0]=0;
- for(i=0;i<100;i++){
- sprintf(fname,"%s\pic\%d.%s",fpath,tt+1,typestr);
- hfile=CreateFile(fname,GENERIC_READ,FILE_SHARE_READ ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
- if(hfile!=INVALID_HANDLE_VALUE){
- CloseHandle(hfile);
- tt++;
- }
- else
- break;
- }
- if(tt>0){
- tt=GetTickCount()%(tt+1);
- if(tt<1)
- tt=1;
- }
- return tt;
- }