ResManager.cpp
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:7k
- #include "stdafx.h"
- #include "stdio.h"
- #include "CMyWnd.h"
- #include "stdafx.h"
- #include "windows.h"
- #include "ResManager.h"
- ResManager::ResManager()
- {
- POINT pp[10];
- ControlHeight=24;
- WinHeight=100+ControlHeight;
- WinWidth=170;
- hUIFont = CreateFont(20, 0, 0, 0, FW_NORMAL,
- FALSE, FALSE, FALSE, ANSI_CHARSET,
- OUT_TT_PRECIS, CLIP_TT_ALWAYS, ANTIALIASED_QUALITY,
- DEFAULT_PITCH, "宋体");
- pp[0].x=0; pp[0].y=ControlHeight;
- pp[1].x=WinWidth; pp[1].y=ControlHeight;
- pp[2].x=WinWidth; pp[2].y=WinHeight;
- pp[3].x=20; pp[3].y=WinHeight;
- pp[4].x=20; pp[4].y=ControlHeight+40;
- pp[5].x=0; pp[5].y=ControlHeight+20;
- pp[6].x=0; pp[6].y=ControlHeight;
- //文本区
- TextRGN=CreatePolygonRgn(pp,7,1);
- WinRGN1=CreatePolygonRgn(pp,7,1);
- WinRGN2=CreatePolygonRgn(pp,7,1);
- CurBackPic[0]=0;
- }
- ResManager::~ResManager()
- {
- DeleteObject(hUIFont);
- DeleteObject (WinRGN1);
- }
- int ResManager::FixBackPic()
- {
- char dd[500];
- RegReadString("backpic",dd);
- if(dd[0]==0)
- RegSaveString("backpic",CurBackPic);
- else
- RegSaveString("backpic","");
- return 0;
- }
- ResManager::InitResManager(HDC WindDC,HINSTANCE hInst)
- {
- HANDLE hfile;
- long tt=0,i;
- char fpath[500];
- char fname[500];
- // HBRUSH hHBr;
- try {
- 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));
-
- //-------------------------------------------------
- //如果注册表中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);
- BackhBmp=(HBITMAP)LoadImage(0, fname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION );
- }
- if(BackhBmp==NULL)
- {
- GetModuleFileName(hInst,fpath,255);
- myGetPath(fpath); //取路径
- sprintf(fname,"%sback.bmp",fpath);
- BackhBmp=(HBITMAP)LoadImage(0, fname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION );
- if(BackhBmp==NULL)
- {
- fname[0]=0;
- for(i=0;i<100;i++)
- {
- sprintf(fname,"%s\%d.bmp",fpath,tt+1);
- 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;
- sprintf(fname,"%s\%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);
- BackDC = CreateCompatibleDC(WindDC);
- DeleteObject(SelectObject(BackDC,BackhBmp));
- //HRGN temrgn;
- //hHBr = CreateHatchBrush(7, RGB(0,0,255));
- //temrgn=WinRGN2;
- //OffsetRgn(temrgn,0,-ControlHeight);
- //FrameRgn(BackDC,temrgn,hHBr,2,2);
- //DeleteObject(hHBr);
- //-------------------------------------------------
- Flashhdc = CreateCompatibleDC(WindDC);
- Flashhdcbmp=CreateCompatibleBitmap(WindDC,WinWidth,WinHeight);
- SelectObject(Flashhdc, hUIFont);
- DeleteObject(SelectObject(Flashhdc,Flashhdcbmp));
- Texthdc = CreateCompatibleDC(WindDC);
- Texthdcbmp=CreateCompatibleBitmap(WindDC,WinWidth,WinHeight);
- SelectObject(Texthdc, hUIFont);
- DeleteObject(SelectObject(Texthdc,Texthdcbmp));
- BitBlt(Texthdc,0,0,WinWidth,WinHeight,BackDC,0,0,SRCCOPY);
- SetBkMode(Texthdc,TRANSPARENT);
- } catch (...)
- {
- RegSaveString("backpic","");
- }
- }
- //////////////////////////////////////////////////////////////////////////////
- //读取注册表中的一个变量
- DWORD ResManager::ReadReg(char *valname)
- {
- HKEY hKey;
- DWORD myupdate=0, myupdate1=0;
- unsigned long lon;
- if ( RegCreateKey(HKEY_CURRENT_USER,"Software\jsime", &hKey) == ERROR_SUCCESS )
- {
- //如果没有键值就建立一个
- if( RegQueryValueEx( hKey,valname,NULL,NULL,(LPBYTE)&myupdate1,&lon) != ERROR_SUCCESS )
- RegSetValueEx(hKey, valname,0,REG_DWORD,(LPBYTE)&myupdate,sizeof(DWORD));
- RegCloseKey(hKey);
- }
- return myupdate1;
- }
- /////////////////////////////////////////////////////////////////////////
- // read string
- int ResManager::RegReadString(char *valname, char *keyVal)
- {
- HKEY hKey;
- unsigned long lon;
- char dd[10]="";
- keyVal[0]=0;
- if ( RegCreateKey(HKEY_CURRENT_USER,"Software\jsime", &hKey) == ERROR_SUCCESS )
- {
- //如果没有键值就建立一个
- if( RegQueryValueEx( hKey,valname,NULL,NULL,(LPBYTE)keyVal,&lon) != ERROR_SUCCESS )
- RegSetValueEx(hKey, valname,0,REG_SZ,(LPBYTE)dd,0);
- RegCloseKey(hKey);
- }
- return 0;
- }
- int ResManager:: RegSaveString(char *valname, char *keyVal)
- {
- HKEY hKey;
- if ( RegCreateKey(HKEY_CURRENT_USER,"Software\jsime", &hKey) == ERROR_SUCCESS )
- {
- // MessageBox(0,valname,keyVal,0);
- RegSetValueEx(hKey, valname,0,REG_SZ,(LPBYTE)keyVal,strlen(keyVal)+1);
- RegCloseKey(hKey);
- }
- return 0;
- }
- int ResManager::WriteReg(char *valname,DWORD keyVal)
- {
- HKEY hKey;
- if ( RegCreateKey(HKEY_CURRENT_USER,"Software\jsime", &hKey) == ERROR_SUCCESS )
- {
- // MessageBox(0,valname,keyVal,0);
- RegSetValueEx(hKey, valname,0,REG_DWORD,(LPBYTE)&keyVal,sizeof(DWORD));
- RegCloseKey(hKey);
- }
- return 0;
- }
- //////////////////////////////////////////////////////////////////
- POINT ResManager:: ReadRegPos(char *PathName)
- {
- HKEY hKey;
- DWORD myupdate=0, myupdate1=0;
- unsigned long lon;
- POINT GetPos;
- char ss[100];
- GetPos.x=0;
- GetPos.y=0;
- sprintf(ss,"Software\jsime\%s",PathName);
- if ( RegCreateKey(HKEY_CURRENT_USER,ss, &hKey) == ERROR_SUCCESS )
- {
- //如果没有键值就建立一个
- if( RegQueryValueEx( hKey,"x",NULL,NULL,(LPBYTE)&GetPos.x,&lon) != ERROR_SUCCESS )
- RegSetValueEx(hKey, "x",0,REG_DWORD,(LPBYTE)&GetPos.x,sizeof(DWORD));
- if( RegQueryValueEx( hKey,"y",NULL,NULL,(LPBYTE)&GetPos.y,&lon) != ERROR_SUCCESS )
- RegSetValueEx(hKey, "y",0,REG_DWORD,(LPBYTE)&GetPos.y,sizeof(DWORD));
- RegCloseKey(hKey);
- }
- return GetPos;
- }
- int ResManager::WriteRegPos(char *PathName,POINT SavePos)
- {
- HKEY hKey;
- char ss[100];
- sprintf(ss,"Software\jsime\%s",PathName);
- if ( RegCreateKey(HKEY_CURRENT_USER,ss, &hKey) == ERROR_SUCCESS )
- {
- // MessageBox(0,valname,keyVal,0);
- RegSetValueEx(hKey, "x",0,REG_DWORD,(LPBYTE)&SavePos.x,sizeof(DWORD));
- RegSetValueEx(hKey, "y",0,REG_DWORD,(LPBYTE)&SavePos.y,sizeof(DWORD));
- RegCloseKey(hKey);
- }
- return 0;
- }
- int ResManager::myGetPath(char *filefullname)
- {
- int i,lon;
- lon=strlen(filefullname);
- for(i=lon;i>0;i--)
- if(filefullname[i]=='\')
- {
- filefullname[i+1]=0;
- break;
- }
- return 0;
- }