CmyFC.cpp
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:16k
- #include "stdafx.h"
- #include "stdio.h"
- #include "windows.h"
- #include "windef.h"
- #include "math.h"
- #include "CmyFC.h"
- #include "myHDC.h"
- #include "COMMDLG.H"
- #include "SHLOBJ.H"
- extern BYTE VirtKey48Map[48];
- CmyFC::CmyFC()
- {
- OSVERSIONINFO osvi;
- osvi.dwOSVersionInfoSize = 148;
- GetVersionEx(&osvi);
- if(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
- ValIsWinNT=1;
- else
- ValIsWinNT=0;
-
- }
- //浏览文件夹函数
- //browseDirectory("极速五笔",gg, m_hWnd);
- int CALLBACK CmyFC::browseCallbackProc(HWND hwnd, UINT uMsg, LPARAM /*lp*/, LPARAM pData) {
- switch(uMsg) {
- case BFFM_INITIALIZED:
- SendMessage(hwnd, BFFM_SETSELECTION, TRUE, pData);
- break;
- }
- return 0;
- }
- //browseFile(gg, m_hWnd,true,"",NULL);
- bool CmyFC::browseDirectory(char *Title,char * target, HWND owner /* = NULL */) {
- char buf[MAX_PATH];
- BROWSEINFO bi;
- LPMALLOC ma;
- int lon;
- ZeroMemory(&bi, sizeof(bi));
-
- bi.hwndOwner = owner;
- bi.pszDisplayName = buf;
- bi.lpszTitle = Title;
- bi.ulFlags = BIF_RETURNONLYFSDIRS ;
- bi.lParam = (LPARAM)target;
-
- //bi.lpfn = &browseCallbackProc;
- LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
- if(pidl != NULL)
- {
- SHGetPathFromIDList(pidl, buf);
- strcpy(target, buf);
- lon=strlen(target);
- if(lon > 0 && (target)[lon-1] != '\')
- {
- target[lon]='\';
- target[lon+1]=0;
- }
-
- if(SHGetMalloc(&ma) != E_FAIL)
- {
- ma->Free(pidl);
- ma->Release();
- }
- }
- return 1;
- }
- //save为0表示打开,为真表示保存
- UINT APIENTRY openhook (HWND, UINT, WPARAM, LPARAM)
- {
- return 0;
- }
- bool CmyFC::browseFile(char * target,int buflen, HWND owner /* = NULL */, bool save /* = true */, char* initialDir /* = Util::emptyString */, char* types /* = NULL */)
- {
- char buf[MAX_PATH];
- OPENFILENAME ofn; // common dialog box structure
- try{
- memcpy(buf, target, buflen);
- // Initialize OPENFILENAME
- ZeroMemory(&ofn, sizeof(OPENFILENAME));
- ofn.lStructSize = sizeof(OPENFILENAME);
- ofn.hwndOwner = owner;
- ofn.lpstrFile = buf;
- ofn.lpstrFilter = types;
- ofn.nFilterIndex = 1;
- ofn.lpfnHook=openhook;
- ofn.lpstrInitialDir = initialDir;
- ofn.nMaxFile = sizeof(buf);
- ofn.Flags = (save ? 0: OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST);
-
- // Display the Open dialog box.
- if ( (save ? GetSaveFileName(&ofn) : GetOpenFileName(&ofn) ) ==TRUE) {
- //MessageBox(0,ofn.lpstrFile,"dd",0);
- memcpy(target,ofn.lpstrFile,buflen);
- return true;
- }
- }
- catch(...)
- {
- MessageBox(0,"图片选择有错误发生","dd",0);
- }
- return false;
- }
- //判断系统是否NT
- BOOL CmyFC::MyIsWinNT()
- {
- OSVERSIONINFO osvi;
- osvi.dwOSVersionInfoSize = 148;
- GetVersionEx(&osvi);
- if(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
- return 1;
- else
- return 0;
- }
- int CmyFC::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;
- }
- int CmyFC::myfileExtname(char *filefullname,char *extname)
- {
- int i,lon;
- extname[0]=0;
- lon=strlen(filefullname);
- for(i=lon;i>0;i--)
- if(filefullname[i]=='.')
- {
- strcpy(extname,&filefullname[i+1]);
- break;
- }
- return 0;
- }
- //输出文本图片
- CmyFC::OutTextPic(char *ss,long x,long y,HDC hDC1,HDC hDC2, long dw , long dh,double a, double zoom,HDC backhdc)
- {
- int i,index;
- myHDC tt,temtt,pp;
- char temss[100];
- long r,outdw;
- strcpy(temss,ss);
- r=(long)sqrt(dw*dw+dh*dh);
- outdw=dw*2*strlen(temss)+r*2;
- tt.StartHDC(hDC2,outdw,500);
- temtt.StartHDC(hDC1,outdw,500);
- pp.StartHDC(hDC1,outdw,500);
- strupr(temss);
- for(i=0;i<(int)strlen(temss);i++)
- {
- index=temss[i]-65;
- OutPicture(r,r,tt.hdc,dw*2*index,0,hDC2,dw,dh,a);
- TransparentBlt2(temtt.hdc,dw*2*i,0,dw*2+r,r*2,tt.hdc,0,0,dw*2+r,r*2,RGB(255,255,255));
- //BitBlt(temtt.hdc,dw*2*i,0,dw*2+r,r*2,tt.hdc,0,0,SRCAND);//
- }
- BitBlt(pp.hdc,0,0,outdw,r*2,backhdc,x,y,SRCCOPY);
- TransparentBlt2(pp.hdc,0,0,(int)(outdw*zoom),(int)(r*2*zoom),temtt.hdc,0,0,outdw,r*2,RGB(255,255,255));
- BitBlt(hDC1,x,y,(int)(outdw*zoom),r*2,pp.hdc,0,0,SRCCOPY);
- }
- //在hDC1中输出hDC2的指定位置和大小和角度的图片
- CmyFC::OutPicture(long x,long y,HDC hDC1,long startx,long starty,HDC hDC2, long dw , long dh,double a)
- {
- POINT pt[3];
- double sidas,sidac ;
- HBRUSH hBrush;
- HRGN hRgn;
- if(ValIsWinNT==TRUE)
- {
- sidac =cos(a * 0.0174533);
- sidas =sin(a * 0.0174533);
- pt[0].y = (long)(-dh * sidac -dw * sidas + y);
- pt[0].x = (long)( dh * sidas -dw * sidac + x);
- pt[1].y = (long)(-dh * sidac +dw * sidas + y);
- pt[1].x = (long)( dh * sidas +dw * sidac + x);
- pt[2].y = (long)( dh * sidac -dw * sidas + y);
- pt[2].x = (long)(-dh * sidas -dw * sidac + x);
- //BitBlt(hDC1,0,0,2000,500,0,0,0,WHITENESS);//由于WHITENESS并不是白色
- hBrush=(HBRUSH)GetStockObject(WHITE_BRUSH);
- hRgn=CreateRectRgn(0,0,300,300);
- FillRgn(hDC1,hRgn, hBrush);
- DeleteObject (hRgn);
- PlgBlt(hDC1,pt,hDC2,startx,starty, dw*2,dh*2,0,0,0);
- }
- else
- BitBlt(hDC1,10,10,dw*2,dh*2,hDC2,startx,starty,SRCCOPY);
-
- }
- void CmyFC::TransparentBlt2(HDC hdc0,
- int nX0,int nY0,int nW0,int nH0,
- HDC hdc1,
- int nX1,int nY1,int nW1,int nH1,
- UINT Tcol)
-
- {
- HBITMAP hBMP =CreateCompatibleBitmap(hdc0,nW0, nH0);
- // HBITMAP mBMP =CreateCompatibleBitmap(hdc0,nW0, nH0);
- HBITMAP mBMP =CreateBitmap(nW0,nH0,1,1,NULL); //建单色位图
- HDC hDC =CreateCompatibleDC(hdc0);
- HDC mDC =CreateCompatibleDC(hdc0);
- HBITMAP oldBMP =(HBITMAP)SelectObject(hDC, hBMP);
- HBITMAP oldmBMP=(HBITMAP)SelectObject(mDC, mBMP);
- //拷备位图到hDC中
- if (nW0==nW1&&nH0==nH1)
- BitBlt(hDC,0,0,nW0,nH0,hdc1,nX1,nY1,SRCCOPY);
- else
- StretchBlt(hDC,0,0,nW0,nH0,hdc1,nX1,nY1,nW1,nH1,SRCCOPY);
- SetBkColor(hDC, Tcol);//除去背景色的其他色形成轮括
- BitBlt(mDC,0,0,nW0,nH0,hDC,0,0,SRCCOPY);
- //在单色的mDC设备中形成位图的黑色轮括。
- SetBkColor(hDC, RGB(0,0,0)); //设置形成图形与后的0值色
- SetTextColor(hDC, RGB(255,255,255)); //设置需要处理颜色的范围
- BitBlt(hDC,0,0,nW0,nH0,mDC,0,0,SRCAND); //取出实际以黑色为背景的图形。
- SetBkColor(hdc0,RGB(255,255,255));
- SetTextColor(hdc0,RGB(0,0,0));
- //在背景图上形成轮括
- BitBlt(hdc0,nX0,nY0,nW0,nH0,mDC,0,0,SRCAND); // SRCAND dest=source AND dest
- BitBlt(hdc0,nX0,nY0,nW0,nH0,hDC,0,0,SRCPAINT);//SRCPAINT dest=source OR dest
- SelectObject(hDC,oldBMP);
- SelectObject(mDC,oldmBMP);
- DeleteDC(hDC);
- DeleteDC(mDC);
- DeleteObject(hBMP);
- DeleteObject(mBMP);
- }
- //////////////////////////////////////////////////////////////////////////////
- //读取注册表中的一个变量
- DWORD CmyFC::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;
- }
- int CmyFC::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;
- }
- /////////////////////////////////////////////////////////////////////////
- // read string
- int CmyFC::RegReadString(char *valname, char *keyVal)
- {
- HKEY hKey;
- unsigned long lon;
- char dd[100]="";
- 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 CmyFC:: 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;
- }
- //////////////////////////////////////////////////////////////////
- POINT CmyFC:: ReadRegPos(char *PathName)
- {
- HKEY hKey;
- DWORD myupdate=0, myupdate1=0;
- unsigned long lon=4;
- 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 )
- {
- RegQueryValueEx( hKey,"x",NULL,NULL,(LPBYTE)&GetPos.x,(LPDWORD)&lon);
- RegQueryValueEx( hKey,"y",NULL,NULL,(LPBYTE)&GetPos.y,(LPDWORD)&lon);
- RegCloseKey(hKey);
- }
- //sprintf(ss,"%d %d",GetPos.x,GetPos.y);
- //MessageBox(0,ss,ss,0);
- return GetPos;
- }
- int CmyFC::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;
- }
- ///////////////////////////////////////////////////////////
- //
- //////////////////////////////////////////////////////////////////////////////
- //读取注册表中的一个变量
- DWORD CmyFC::ReadReg(char *pathname, char *valname)
- {
- HKEY hKey;
- DWORD myupdate=0, myupdate1=0;
- unsigned long lon;
- if ( RegCreateKey(HKEY_CURRENT_USER,pathname, &hKey) == ERROR_SUCCESS )
- {
- //如果没有键值
- if( RegQueryValueEx( hKey,valname,NULL,NULL,(LPBYTE)&myupdate1,&lon) != ERROR_SUCCESS )
- MessageBox(0,valname,"没有键值",0);
- RegCloseKey(hKey);
- }
- return myupdate1;
- }
- int CmyFC::WriteReg(char *pathname,char *valname,DWORD keyVal)
- {
- HKEY hKey;
- int ret =0;
- if ( RegCreateKey(HKEY_CURRENT_USER,pathname, &hKey) == ERROR_SUCCESS )
- {
- // MessageBox(0,valname,keyVal,0);
- RegSetValueEx(hKey, valname,0,REG_DWORD,(LPBYTE)&keyVal,sizeof(DWORD));
- RegCloseKey(hKey);
- }
- else
- ret =1;
- return 0;
- }
- int CmyFC::WriteReg(HKEY mainhkey,char *pathname,char *valname,DWORD keyVal)
- {
- HKEY hKey;
- int ret =0;
- if ( RegCreateKey(mainhkey,pathname, &hKey) == ERROR_SUCCESS )
- {
- // MessageBox(0,valname,keyVal,0);
- RegSetValueEx(hKey, valname,0,REG_DWORD,(LPBYTE)&keyVal,sizeof(DWORD));
- RegCloseKey(hKey);
- }
- else
- ret =1;
- return 0;
- }
- /////////////////////////////////////////////////////////////////////////
- // read string
- int CmyFC::RegReadString(char *pathname,char *valname, char *keyVal)
- {
- HKEY hKey;
- unsigned long lon;
- char dd[10]="";
- keyVal[0]=0;
- if ( RegCreateKey(HKEY_CURRENT_USER,pathname, &hKey) == ERROR_SUCCESS )
- {
- //如果没有键值
- if( RegQueryValueEx( hKey,valname,NULL,NULL,(LPBYTE)keyVal,&lon) != ERROR_SUCCESS )
- MessageBox(0,valname,"没有键值",0);
- RegCloseKey(hKey);
- }
- return 0;
- }
- int CmyFC::RegSaveString(char *pathname,char *valname, char *keyVal)
- {
- HKEY hKey;
- if ( RegCreateKey(HKEY_CURRENT_USER,pathname, &hKey) == ERROR_SUCCESS )
- {
- // MessageBox(0,valname,keyVal,0);
- RegSetValueEx(hKey, valname,0,REG_SZ,(LPBYTE)keyVal,strlen(keyVal)+1);
- RegCloseKey(hKey);
- }
- return 0;
- }
- int CmyFC::RegSaveString(HKEY mainhkey ,char *pathname,char *valname, char *keyVal)
- {
- HKEY hKey;
- if ( RegCreateKey(mainhkey,pathname, &hKey) == ERROR_SUCCESS )
- {
- // MessageBox(0,valname,keyVal,0);
- RegSetValueEx(hKey, valname,0,REG_SZ,(LPBYTE)keyVal,strlen(keyVal)+1);
- RegCloseKey(hKey);
- }
- return 0;
- }
- bool CmyFC:: DirExists(const char *dir)
- {
- bool tf;
- WIN32_FIND_DATA fd;
- HANDLE hFind = FindFirstFile(dir, &fd);
- if ((hFind != INVALID_HANDLE_VALUE) && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
- {
- tf = true;
- }
- else
- {
- tf = false;
- }
- FindClose(hFind);
- return tf;
- }
- //判断文件是否存在
- BOOL CmyFC:: FileExists(const char *dir)
- {
- BOOL tf;
- WIN32_FIND_DATA fd;
- HANDLE hFind = FindFirstFile(dir, &fd);
- if (hFind !=INVALID_HANDLE_VALUE)
- {
- tf = TRUE;
- }
- else
- {
- tf = FALSE;
- }
- FindClose(hFind);
- return tf;
- }
- ///////////////////////////////////////////////////////////////
- //读注册表判断是否需要重新装载库
- //返回为0表示不需要,1为需要重新装载
- long CmyFC::GetIsUpdate()
- {
- HKEY hKey;
- DWORD myupdate1;
- unsigned long lon;
- long ret=0;
- if ( RegCreateKey(HKEY_CURRENT_USER,"Software\jsime", &hKey) == ERROR_SUCCESS )
- {
- if( RegQueryValueEx( hKey,"jsime",NULL,NULL,(LPBYTE)&myupdate1,&lon) == ERROR_SUCCESS )
- {
- if(myupdate1==1)
- {
- //char ss[100];
- //sprintf(ss,"需要更新字库%d",myupdate1);
- //MessageBox(0,ss,"ddd",0);
- myupdate1=0;
- RegSetValueEx(hKey, "jsime",0,REG_DWORD,(LPBYTE)&myupdate1,sizeof(DWORD));
- ret=1;
- }
- }
- RegCloseKey(hKey);
- }
- else
- MessageBox(0,"Software\jsime","主键打开失败",0);
- return ret;
- }
- ////////////////////////////////////////////////////////////////
- //取得键盘字符
- //需要得到VirtKey48Map支持
- ///////////////////////////////////////////////////////////////
- BOOL CmyFC::SoftKbdProcess(char *chss,int mykey,char*retSendCH)
- {
- unsigned char temss[3];
- char temchss[3];
- int i,bas=0,ret=0;
- BYTE bb;
- bb=mykey;
- for(i=0;i<49;i++)
- {
- if(VirtKey48Map[i]==bb)
- break;
- }
- if(i<49)
- {
- GetAsyncKeyState(16);
- if(GetAsyncKeyState(16)!=0)
- bas=48;
- temchss[0] = chss[(bas+i)*2] ;
- temchss[1] = chss[(bas+i)*2 + 1] ;
- temchss[2] =0;
- temss[0] = chss[(bas+i)*2] & 0x00ff;
- temss[1] = chss[(bas+i)*2 + 1] & 0x00ff;
- if(temss[1]==' ')
- temss[1]=0;
- if(strcmp(temchss," ")==0)
- temss[0]=0;
- temss[2]=0;
-
- strcpy(retSendCH,(char*)temss);
- ret=1;
- }
- return ret;
- }
- /////////////////////////////////////////////////////////////
- //下面为函数部分
- //用于向系统发送消息
- BOOL CmyFC::GenerateMessage(HIMC hIMC, LPDWORD lpdwTransKey,LPGENEMSG lpGeneMsg)
- {
- LPINPUTCONTEXT lpIMC;
- if( (lpIMC = ImmLockIMC(hIMC)) == NULL )
- return FALSE;
- if (IsWindow(lpIMC->hWnd))
- {
- LPDWORD lpdw;
- if (!(lpIMC->hMsgBuf = ImmReSizeIMCC(lpIMC->hMsgBuf,
- sizeof(DWORD) * (lpIMC->dwNumMsgBuf +1) * 3)))
- return FALSE;
- if (!(lpdw = (LPDWORD)ImmLockIMCC(lpIMC->hMsgBuf)))
- return FALSE;
-
- lpdw += (lpIMC->dwNumMsgBuf) * 3;
- *((LPGENEMSG)lpdw) = *lpGeneMsg;
- ImmUnlockIMCC(lpIMC->hMsgBuf);
- lpIMC->dwNumMsgBuf++;
- ImmGenerateMessage(hIMC);
- }
- ImmUnlockIMC(hIMC);
- return TRUE;
- }
- //把转换后的汉字发到接收程序中使用内部机制.
- BOOL CmyFC::IMESenChiApp(HIMC hIMC, char *ss)
- {
- //内部发送在首次发送时可能失效,因此暂时不用
- if(strlen(ss)<2)
- {
- GENEMSG GnMsg;
- LPCOMPOSITIONSTRING lpCompStr;
- LPINPUTCONTEXT lpIMC;
- lpIMC = ImmLockIMC(hIMC);
- lpCompStr = (LPCOMPOSITIONSTRING)ImmLockIMCC(lpIMC->hCompStr);
- if(strlen(ss))
- {
- strcpy(GETLPRESULTSTR(lpCompStr),ss);
- //_tcscpy(GETLPRESULTSTR(lpCompStr),"高点");
- lpCompStr->dwResultStrLen =strlen(ss);
- //{
- // char sss[100];
- // sprintf(sss,"%d",strlen(ss));
- // MessageBox(0,sss,0,0);
- //}
- GnMsg.msg = WM_IME_COMPOSITION;//
- GnMsg.wParam = 0;
- GnMsg.lParam = GCS_RESULTSTR;
- GenerateMessage(hIMC, 0,(LPGENEMSG)&GnMsg);
- }
- }
- else
- {
- //向获得焦点的窗口发送字符串
- //发送过多的字符有可能失去挂钩
- int i;
- for(i=0;i<(int)strlen(ss);)
- {
- if(ss[i]<0)
- {
- SendMessage(GetFocus(), WM_IME_CHAR, MAKEWORD(ss[i+1],ss[i]), 0);
- i+=2;
- }
- else
- {
- SendMessage(GetFocus(), WM_IME_CHAR, MAKEWORD(ss[i],0), 1);
- if(ss[i]==13&&ss[i+1]==10)
- i++;
- i++;
- }
- }
- }
- return TRUE;
- }