CMyWnd.cpp
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:32k
- #include "stdafx.h"
- #include "stdio.h"
- #include "CMyWnd.h"
- #include "windows.h"
- #include "GIF.h"
- #include "string.h"
- #include "math.h"
- CGIF m_Gif;
- POINT pst;
- int tt;
- int EDIT1_NUM;
- char EDIT1_txt[200];
- char EDIT2_txt[200];
- #include "DllManager.h"
- extern DllManager ChLib;//定义在主DLL中
- BOOL WINAPI About(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam )
- {
- switch (message)
- {
- case WM_INITDIALOG:
- SetDlgItemText(hDlg,IDC_EDIT1,EDIT1_txt);
- SetDlgItemText(hDlg,IDC_EDIT2,EDIT2_txt);
- SetWindowPos(hDlg, 0, 400,300,0, 0, 21); //SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER //16/1/4
- return TRUE;
- case WM_COMMAND:
- switch(wParam) {
- case IDOK:
- GetDlgItemText(hDlg,IDC_EDIT1,EDIT1_txt,2);
- EDIT1_NUM=GetDlgItemInt(hDlg,IDC_EDIT1,0,FALSE);
- EndDialog(hDlg,IDOK);
- break;
- case IDCANCEL:
- EndDialog(hDlg,IDCANCEL);
- break;
- default:
- break;
- }
- break;
- }
- return FALSE;
- }
- //////////////////////////////////////////////////////////
- // 窗口的初始化
- //由于在类建立时还没有建立窗口,因此m_hWnd没有有效值。
- // 类建立时还不能初始化,只有调用了CREATE后才可以。
- CMyWnd::initalizeWin()
- {
- WindDC=GetDC(m_hWnd);
- myResM.InitResManager(WindDC,hInst,WinWidth, WinHeight);
- DeleteObject(SelectObject(WindDC, hUIFont));
- TextH=GetTabbedTextExtent(WindDC,"1",1,0,0)/0x10000;
- SetWindowRgn(m_hWnd,WinRGN1,TRUE);
- Texthdc = CreateCompatibleDC(WindDC);
- Texthdcbmp=CreateCompatibleBitmap(WindDC,WinWidth,WinHeight);
- DeleteObject(SelectObject(Texthdc, hUIFont));
- DeleteObject(SelectObject(Texthdc,Texthdcbmp));
- SetBkMode(Texthdc,TRANSPARENT);
- }
- int CMyWnd::ClearWin()
- {
- static int nullflag=0;
- stopflash=0;
- settxt("");
- inputWind->showtxt[0]=0;
- myPaintTxt(0,actSetstr);
- inputWind->myPaintTxt(0,actSetstr);
- return 0;
- }
- int CMyWnd::SetShowString(char*MindleStr,char*InputStr)
- {
- static int nullflag=0;
- stopflash=0;
- settxt(MindleStr);
- {
- int i,len;
- if(InputStr!=NULL)
- {
- len=strlen(InputStr);
- for(i=0;i<len;i++)
- inputWind->showtxt[i]=InputStr[i];
- inputWind->showtxt[i]=0;
- }
- else
- inputWind->showtxt[0]=0;
- }
- /*
- if(InputStr!=NULL)
- strcpy(cmywnd->inputWind->showtxt,InputStr);
- else
- cmywnd->inputWind->showtxt[0]=0;
- */
- myPaintTxt(0,actSetstr);
- inputWind->myPaintTxt(0,actSetstr);
- if(inputWind->showtxt[0]==0)
- nullflag++;
- else
- nullflag=0;
- if(nullflag>1)
- {
- ShowWindow(m_hWnd,SW_HIDE);
- if(nullflag>2)
- ShowWindow(inputWind->m_hWnd,SW_HIDE);
- }
- else
- {
- ShowWindow(m_hWnd,SW_SHOWNOACTIVATE);
- ShowWindow(inputWind->m_hWnd,SW_SHOWNOACTIVATE);
- }
- return 0;
- }
- //键盘过滤,0为不过滤
- BOOL CMyWnd::myImeProcessKey(char *SendCH,char*Control,HIMC hIMC,UINT vKey,LPARAM lKeyData,CONST LPBYTE lpbKeyState)
- {
- LONG fRet;
- int mykey,lon;
- try{
- fRet=inmyImeProcessKey(SendCH,Control,hIMC,vKey,lKeyData,lpbKeyState);
- if(fRet==0)
- {
- mykey=(int)vKey;
- if(mykey>=32&&mykey<=126)
- myResM.Chtime.appnum(1);//计数一次
- }
- myQQWind->disabledailtimer();
- lon=strlen(SendCH);
- myResM.Chtime.appnum(lon/2);//计数一次
- if(lon==2)
- myResM.ChAutoword.AppOne(SendCH);
- } catch (...) {
- MessageBox(0,"myImeProcessKey","有错误发生",0);
- }
- return fRet;
- }
- //键盘过滤,0为不过滤
- BOOL CMyWnd::inmyImeProcessKey(char *SendCH,char*Control,HIMC hIMC,UINT vKey,LPARAM lKeyData,CONST LPBYTE lpbKeyState)
- {
- GENEMSG GnMsg;
- LONG lRet = 0L;
- int mykey;
- BOOL fRet = FALSE, fCompStr = FALSE;
- static BOOL fPressOther = FALSE;
- char ss[1000]="";
- unsigned char kbByte[256];
- HWND hSoftKbdWnd=NULL;
- mykey=(int)vKey;
- //sprintf(ss,"%d",mykey);
- //MessageBox (0,ss,0,0);
- if (ChLib.LoadErr!=0)
- {
- MessageBox(0,"请立即保存,系统可能崩溃!?","发生严重错误!",0);
- return FALSE;
- }
- GetKeyboardState(kbByte);
- //GetAsyncKeyState上一次调用以来,如键已被按过,则位0设为1;
- //否则设为0。如键目前处于按下状态,则位8设为1;如抬起,则为0。
- //按住Ctrl 、Shift(10)或Alt时不进行编 VK_ATTN VK_CONTROL
- if (lpbKeyState[VK_ATTN] & 0x80)
- return FALSE;
- ///////////////////////////////////////
- // 增词控制
- if (lpbKeyState[VK_CONTROL] & 0x80 ||ConWind->controlflag==1)
- {
- if ( mykey==192)
- {
- if(mydd.appdictbool==0)
- myQQWind->settxt("造 词 中");
- else
- myQQWind->settxt(" 词 语 ");
- strcpy(ChLib.Control,"AppDict");
- mydd.AppSetDict(hIMC);
- ConWind->controlflag=0;
- fRet=1;
- }
- else
- fRet=0;
- return fRet;
- }
- //////////////////////////////////////////////
- //软键盘功能
- {
- hSoftKbdWnd=ConWind->keyboard->CIMEhSoftKbdWnd;//试探性取数据
- GetWindowText(hSoftKbdWnd,ss,2);
- if(ss[0]!=0)
- { //试探性取数据,正式获取数据
- GetWindowText(hSoftKbdWnd,ss,200);
- return SoftKbdProcess(ss,mykey,SendCH);
- }
- }
-
- if(kbByte[VK_CAPITAL]&1)//大写字母打开时将不进行输入处理
- return 0;
- //sprintf(ss,"%d",mykey);
- //MessageBox (0,ss,0,0);
- ////////////////////////////////////////////////////
- //以下为转换功能
- if(GetIsUpdate()) //查看软件是否需要更新字库
- ChLib.DLLstart(1);
-
- if(ChLib.Linputbuf[0]!=0) //进行翻页功能
- {
- if(mykey==33)
- {
- ChLib.getnextpage(ChLib.LMidtems,0);
- SetShowString(ChLib.LMidtems,ChLib.Linputbuf);
- //MessageBox (0,DllMns.LMidtems,0,0);
- return 1;
- }
- if(mykey==34)
- {
- ChLib.getnextpage(ChLib.LMidtems,1);
- SetShowString(ChLib.LMidtems,ChLib.Linputbuf);
- return 1;
- }
- }
- fRet=ChLib.keyprogress(mykey,ChLib.Linputbuf, ChLib.SendCH,ChLib.SendEN,ChLib.LMidtems,ChLib.Control);
- if(ChLib.Linputbuf[0]==0)
- SetShowString("","");
- else
- SetShowString(ChLib.LMidtems,ChLib.Linputbuf);
- //MessageBox(0,DllMns.LMidtems,DllMns.Linputbuf,0);
- if(mydd.appdictbool==1)
- {
- if(ChLib.SendCH[0]!=0)
- mydd.AppOne(ChLib.SendCH);
- }
- /////////////////////////////////////////////////
- // 提示窗口控制功能
- // 下面为获得光标位置,并设置提示窗口位置
- if(fRet!=0)
- {
- POINT ptSrc;
- LPINPUTCONTEXT lpIMC;
- //告诉系统开始接收位置
- GnMsg.msg = WM_IME_STARTCOMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, 0,(LPGENEMSG)&GnMsg);
- //发结束消息,不然会出现ATL功能键的异常。
- GnMsg.msg = WM_IME_ENDCOMPOSITION;
- GnMsg.wParam = 0;
- GnMsg.lParam = 0;
- GenerateMessage(hIMC, 0,(LPGENEMSG)&GnMsg);
- if (!(lpIMC = ImmLockIMC(hIMC)))//锁存数据
- return fRet;
- ptSrc = lpIMC->cfCompForm.ptCurrentPos;
- if(ptSrc.x<-10000||ptSrc.x>10000)
- {
- GetCaretPos(&ptSrc);
- }
- //char Lss[100];
- //sprintf(Lss,"%ld y%ld",ptSrc.x,ptSrc.y);
- //MessageBox(0,Lss,0,0);
- MyMoveWinInput(lpIMC->hWnd,ptSrc.x,ptSrc.y);
- ImmUnlockIMC(hIMC);
- } //位置测试结束
- strcpy(SendCH,ChLib.SendCH);
- ChLib.SendCH[0]=0;
- strcpy(Control,ChLib.Control);
- ChLib.Control[0]=0;
- return fRet;
- }
- CMyWnd::CMyWnd(DWORD himc)
- {
- int i;
- POINT pp[10];
- void* vp=(void*)this;
- ChLib.SetIMEModle(myResM.CurModleNum);
- savehimc=himc;
- myQQWind =new QQHwnd(vp);
- //myQQtimer =new QQHwnd(vp);
- inputWind=new inputHwnd( vp );
- ConWind =new ConHwnd( vp,himc);
- stopflash=0;
- x=y=50;
- resavehight=4;
- for(i=0;i<50;i++)
- Arrppc[i] =NULL;
- TimePPch=NULL;
- StartPPch=NULL;
- WinStartPos=myResM.ReadRegPos("CMyWnd");
- hUIFont = CreateFont(19, 0, 0, 0, FW_NORMAL,
- FALSE, FALSE, FALSE, ANSI_CHARSET,
- OUT_TT_PRECIS, CLIP_TT_ALWAYS, ANTIALIASED_QUALITY,
- DEFAULT_PITCH, "宋体");
- strcpy(inputWind->showtxt,"");
- settxt("名称:极速五笔 1.;版权:王华 1.;发行:2006.12.28 1.;E-m:whln669@sohu.com 1.;版本:2.10 1.;");
- m_hWnd=NULL;
- WinHeight=100;
- WinWidth=170;
- conh=&(inputWind->ControlHeight);
- pp[0].x=0; pp[0].y=0;
- pp[1].x=WinWidth; pp[1].y=0;
- pp[2].x=WinWidth; pp[2].y=WinHeight;
- pp[3].x=20; pp[3].y=WinHeight;
- pp[4].x=20; pp[4].y=40;
- pp[5].x=0; pp[5].y=20;
- pp[6].x=0; pp[6].y=0;
- //文本区
- TextRGN=CreatePolygonRgn(pp,7,1);
- WinRGN1=CreatePolygonRgn(pp,7,1);
- WinRGN2=CreatePolygonRgn(pp,7,1);
- fCanMove = FALSE;
- saveWM_LButton=0;
- saveCurLine=0;
- }
- CMyWnd::~CMyWnd()
- {
- //MessageBox(0,"~CMyWnd",0,0);
- try{
- //strcpy(showtxt,"");
- KillTimer(m_hWnd,1);
- KillTimer(m_hWnd,2);
- KillTimer(m_hWnd,3);
- delete inputWind;
- delete ConWind;//软键盘的释放也可能引起致使错误
- delete myQQWind;
- DeleteObject(hUIFont);
- DeleteDC (Texthdc);
- DeleteObject(Texthdcbmp);
- DeleteObject (WinRGN1);
- DeleteObject (WinRGN2);
- DeleteObject (TextRGN);
- //可能在窗口处理程序中本窗口已被删除。
- //让程序暂时进行处理,以防止无效访问已经退出的代码段
- if(IsWindow(m_hWnd)){
- ReleaseDC(m_hWnd,WindDC);
- //SetWindowLong(m_hWnd,GWL_WNDPROC,(long)endProc);
- DestroyWindow(m_hWnd);
- //m_hWnd=NULL;
- }
- } catch (...) {
- MessageBox(0,"~CMyWnd","有错误发生",0);
- }
- }
- BOOL CMyWnd::Create(LPCTSTR szClassName, LPCTSTR szTitle, HINSTANCE hInstance, HWND hWndParent , DWORD dwStyle ,DWORD dwExStyle, HMENU hMenu )
- {
- // 初始化全局字串
- WNDCLASSEX wcex;
- ChLib.hInstance=hInstance;
- //MessageBox(0,"Main create",0,0);
- wcex.cbSize = sizeof(WNDCLASSEX);
- wcex.style = CS_IME;
- wcex.lpfnWndProc = InitProc;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 12;
- wcex.hInstance = hInstance;
- wcex.hIcon = 0;
- wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
- wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wcex.lpszMenuName = 0;
- wcex.lpszClassName = szClassName;
- wcex.hIconSm = 0;
- hInst=hInstance;
-
- RegisterClassEx(&wcex);
- {
- m_hWnd=CreateWindowEx( 0,
- szClassName,NULL,
- WS_POPUP|WS_DISABLED,// | WS_DISABLED,WS_SIZEBOX
- WinStartPos.x,WinStartPos.y,WinWidth,WinHeight,
- hWndParent,NULL,hInstance,this);
- SetWindowLong(m_hWnd,8,(DWORD)hWndParent);//FIGWL_SVRWND
- ShowWindow(m_hWnd,SW_SHOWNOACTIVATE);
- UpdateWindow(m_hWnd);
- }
- //MessageBox(0,"Main create",0,0);
- myHwndParent=hWndParent;
- myQQWind->Create("QQ","QQ",hInstance,hWndParent,dwStyle,dwExStyle,hMenu);
- inputWind->Create("inputWind",szTitle,hInstance,hWndParent,dwStyle,dwExStyle,hMenu);
- ConWind->Create("ConHwnd",szTitle,hInstance,hWndParent,dwStyle,dwExStyle,hMenu);
- Main_hWnd=&m_hWnd;
- Cont_hWnd=&ConWind->m_hWnd;
- inpu_hWnd=&inputWind->m_hWnd;
- inputWind->Main_hWnd=&m_hWnd;
- inputWind->Cont_hWnd=&ConWind->m_hWnd;
- inputWind->inpu_hWnd=&inputWind->m_hWnd;
- ConWind->Main_hWnd=&m_hWnd;
- ConWind->Cont_hWnd=&ConWind->m_hWnd;
- ConWind->inpu_hWnd=&inputWind->m_hWnd;
- DrawFrame();
- //SetTimer(m_hWnd,1,30,0);
- return m_hWnd != NULL;
- }
- CMyWnd::SetAllWinAttrib(unsigned char Lclarity)
- {
- myset.mySetWindow(m_hWnd, RGB(255,255,255),Lclarity,LWA_ALPHA|LWA_COLORKEY);
- myset.mySetWindow(inputWind->m_hWnd,RGB(255,255,255),Lclarity,LWA_ALPHA|LWA_COLORKEY);
- myset.mySetWindow(ConWind->m_hWnd, RGB(255,255,255),Lclarity,LWA_ALPHA|LWA_COLORKEY);
- myset.mySetWindow(myQQWind->m_hWnd, RGB(255,255,255),Lclarity,LWA_ALPHA|LWA_COLORKEY);
- }
- ////////////////////////////////////////////////////////
- // 增加边框
- void CMyWnd::DrawFrame()
- {
- int i,line1,line2,line3,mudle1;
- int flowerx,flowery;
- BitBlt(myResM.BackDC,0,0,WinWidth,WinHeight,myResM.reBackDC,0,0,SRCCOPY);//SRCCOPY
- if(myResM.frameflage[0]=='1')
- {
- line1=110;
- line2=114;
- line3=110;
- mudle1=190;
- for(i=0;i<20;i++)//竖线
- TransparentBlt2(myResM.BackDC,20, 38+i*3,5,5,myResM.oldBackDC,mudle1,line2,5,5,RGB(255,255,255));
- for(i=0;i<8;i++) //竖线
- TransparentBlt2(myResM.BackDC,0, i*3, 5,5,myResM.oldBackDC,mudle1,line2,5,5,RGB(255,255,255));
- for(i=0;i<35;i++)//竖线
- BitBlt(myResM.BackDC,WinWidth-4,i*3,5,5,myResM.oldBackDC,mudle1,line2,SRCCOPY);
- for(i=0;i<8;i++)//斜线
- TransparentBlt2(myResM.BackDC,i*3,18+i*3,5,5,myResM.oldBackDC,mudle1,line1,5,5,RGB(255,255,255));
- for(i=0;i<60;i++) //横线
- {
- BitBlt(myResM.BackDC,i*3,0, 5,5,myResM.oldBackDC,mudle1,line3,SRCCOPY);
- BitBlt(myResM.BackDC,i*3,96,5,5,myResM.oldBackDC,mudle1,line3,SRCCOPY);
- }
- }
- //绘制窗花
- if(myResM.flowerflage[0]=='1')
- {
- flowerx=180;
- flowery=130;
- TransparentBlt2(myResM.BackDC,144,0,30,30,myResM.oldBackDC,flowerx,flowery,30,30,RGB(255,255,255));
- flowery=166;
- TransparentBlt2(myResM.BackDC,144,80,30,30,myResM.oldBackDC,flowerx,flowery,30,30,RGB(255,255,255));
- }
- return;
- }
- LRESULT WINAPI CMyWnd::WindowProc(UINT uMsg,UINT wParam,LONG lParam)
- {
- POINT pt;
- RECT Rect;
- COLORREF tColor;
- int t,st;
- static dely;
- char gifname[256];
- static int QQtimenum;
- try {
- switch (uMsg)
- {
- case WM_CREATE:
- //半透明不能和水波共处,否则会出现窗口刷新异常
- //myset.mySetWindow(m_hWnd,RGB(255,255,255),myResM.clarityflage,LWA_ALPHA|LWA_COLORKEY);
- initalizeWin();
- myset.mySetWindow(m_hWnd,RGB(255,255,255),myResM.clarityflage,LWA_ALPHA|LWA_COLORKEY);
- GetModuleFileName(hInst,gifname,255);
- myGetPath(gifname); //取路径 动画
- SetTimer(m_hWnd,3,1000,NULL);//
- SetTimer(m_hWnd,4,30,NULL);//
- strcat(gifname,"1.gif");
- if(m_Gif.LoadGIF(gifname))
- ;//MessageBox(0,"map","m_Gif.LoadGIF",0);
- else
- SetTimer(m_hWnd,2,100,NULL);
- DrawFrame();
-
- break;
- case WM_TIMER:
- if(stopflash==0){
- if(wParam==2)
- {
- KillTimer(m_hWnd,2);
-
- if(x>90)
- x--;
- if(x<90)
- x++;
- if(y>50)
- y--;
- if(y<50)
- y++;
- pt.x=x-30;
- pt.y=y-30;
-
- if (m_Gif.GetImageInfo (Rect,tColor,tt-1)){
- BitBlt (WindDC,0,0,WinWidth, WinHeight,Texthdc,0,0,SRCCOPY);
- }else{
- //if(m_Gif.m_ImageList.m_nCount<0)
- // MessageBox(0,"header",0,0);
- GetModuleFileName(hInst,gifname,255);
- myGetPath(gifname); //取路径 动画
- strcat(gifname,"1.gif");
- m_Gif.LoadGIF( gifname);
- }
- if (!m_Gif.ShowImage (WindDC,pt,tt++)){
- tt = 0;
- //m_Gif.ShowImage (WindDC,pt,tt++);
- }
-
- SetTimer(m_hWnd,2,100,NULL);
- }
- if(wParam==1){
- if(myResM.scrollflage[0]!='1')
- KillTimer(m_hWnd,1);
- TimeShowText(0);
- if (!m_Gif.GetImageInfo (Rect,tColor,tt-1))
- BitBlt (WindDC,0,0,WinWidth, WinHeight,Texthdc,0,0,SRCCOPY);
- }
- if(wParam==3){
- char temss[15];
- myResM.Chtime.apptime();
- sprintf(temss,"速度:%d",myResM.Chtime.GetAverage());
- myQQWind->settxttimer(m_hWnd,100,0,temss);
- }
- }
- break;
- case WM_PAINT://绘制窗口
- myPaintTxt(0,saveWM_LButton);
- break;
- case WM_SETCURSOR:
- if ((HIWORD(lParam) == WM_MOUSEMOVE))
- {
- if(myResM.scrollflage[0]=='1')
- SetTimer(m_hWnd,1,20,NULL);
- SetCapture(m_hWnd);
- //SetWindowLong(m_hWnd,4,1);//GWL_HINSTANCE DWL_MSGRESULT
- }
- else
- return DefWindowProc(m_hWnd,uMsg,wParam,lParam);
- break;
- case WM_RBUTTONDOWN:
- {
- //char ss[100];
- //sprintf(ss,"%d",0);
- //MessageBox(0,ss,"dd",0);
- }
- break;
- case WM_RBUTTONUP:
- y=lParam/0x10000;
- x=lParam%0x10000;
- st=getRgnFlage(x,y);
- switch(st)
- {
- case 1:
- Popup();
- break;
- case 4:
- selectback();
- break;
- }
- break;
- case WM_LBUTTONDOWN:
- y=lParam/0x10000;
- x=lParam%0x10000;
- st=getRgnFlage(x,y);
- GetCursorPos( &pt );
- GetWindowRect(m_hWnd,&WinRect);
- Cursordif.x = pt.x - WinRect.left;//得到相对位置
- Cursordif.y = pt.y - WinRect.top;
- fCanMove=1;
- saveWM_LButton=1;
- if(st==1)
- {
- t=y/TextH+1;
- myPaintTxt(t,saveWM_LButton);
- }
- break;
- case WM_LBUTTONUP:
- y=lParam/0x10000;
- x=lParam%0x10000;
- st=getRgnFlage(x,y);
- if( fCanMove && saveWM_LButton==0)
- {
- GetCursorPos( &pt );
- pt.x=pt.x - Cursordif.x;
- pt.y=pt.y - Cursordif.y;
- MyWinMove(pt);
- }
- fCanMove = FALSE;
- if(st==2)
- {
- if(saveWM_LButton==1)
- {
- myQQWind->settxt(m_hWnd,x,y,"",0);
- ShowWindow(m_hWnd, SW_HIDE);
- ShowWindow(inputWind->m_hWnd, SW_HIDE);
- }
-
- }
- if(st==1)
- {
- t=y/TextH;
- saveCurLine=t+1;
- if(saveWM_LButton==1&&inputWind->showtxt[0]!=0)
- {
- keybd_event(49 + t, 0, 0, 1);
- }
- myPaintTxt(0,saveWM_LButton);
- saveWM_LButton=0;
- }
- if(st==3)
- {
- myResM.Chtime.reset();
- }
- break;
-
- case WM_MOUSEMOVE:
- saveWM_LButton=0;
- y=lParam/0x10000;
- x=lParam%0x10000;
- t=y/TextH+1;
- saveCurLine=t;
- Txx=0;
- if(fCanMove==TRUE)
- {
- QQtimenum=0;
- myQQWind->settxt(m_hWnd,x,y,"",0);
- GetCursorPos( &pt );//取得光标位置
- pt.x=pt.x - Cursordif.x;
- pt.y=pt.y - Cursordif.y;
- MyWinMove(pt);
- myPaintTxt(0,saveWM_LButton);
- //使用SetWindowPos作移动时会改变集焦。可用MoveWindow解决。
- //在不移动时可以使用它。
- }
- else
- {
- st=getRgnFlage(x,y);
- if(st==4)
- {
- myQQWind->settxt(m_hWnd,x,y,"选择图片",1);
- //光标的设置
- SetCursor(LoadCursor(NULL,MAKEINTRESOURCE(32649))); //根据选择区域设置光标
- }
- if(st==3)
- {
- myQQWind->settxt(m_hWnd,x,y,"重设计数器",1);
- //光标的设置
- SetCursor(LoadCursor(NULL,MAKEINTRESOURCE(32649))); //根据选择区域设置光标
- }
- if(st==2)
- {
- myPaintTxt(0,0);
- myQQWind->settxt(m_hWnd,x,y,"隐藏窗口",1);
- //光标的设置
- SetCursor(LoadCursor(NULL,MAKEINTRESOURCE(32649))); //根据选择区域设置光标
- }
- if(st==1)
- {
- QQtimenum++;
- if(QQtimenum>20)
- {
- if(QQtimenum>60)
- {
- QQtimenum=0;
- myQQWind->settxt(m_hWnd,x,y,"",0);
- }
- else
- {
- if(QQtimenum>40)
- myQQWind->settxt(m_hWnd,x,y,"PageUp/PageDown翻頁",2);
- else
- myQQWind->settxt(m_hWnd,x,y,"鼠标左键可选择输入",2);
- }
- }
- //光标的设置
- myMouseMove(t,saveWM_LButton); //根据选择区域设置光标
- }
- }
- //测试鼠标是否移出窗口
- if(PtInRegion(WinRGN2,x,y)==0)
- {
- QQtimenum=0;
- myQQWind->settxt(m_hWnd,x,y,"",0);
- KillTimer(m_hWnd,1);
- myPaintTxt(0,0);
- }
- if(fCanMove==FALSE)
- {
- //SetWindowLong(m_hWnd,4,0);
- ReleaseCapture();
- }
- break;
- case WM_DESTROY:
- //SendMessage(m_hWnd,WM_CLOSE,0,0);
- if(myHwndParent==NULL)
- {
- //PostQuitMessage(0);
- }
- else
- {
- //SetWindowLong(m_hWnd,GWL_WNDPROC,(long)endProc);
- if(IsWindow(m_hWnd))
- DestroyWindow(m_hWnd);
- }
- break;
- default:
- return DefWindowProc(m_hWnd,uMsg,wParam,lParam);
- break;
- }
- return 0;
-
- } catch (...) {
- MessageBox(0,"CMyWnd::WindowProc","有错误发生",0);
- }
- return 1;
- }
- int CMyWnd::getRgnFlage(long x,long y)
- {
- int ret=0;
- long rgb,r,g,b;
- rgb=GetPixel(myResM.oldBackDC,x,y+109);
- r=GetRValue(rgb);
- g=GetGValue(rgb);
- b=GetBValue(rgb);
- if(r==255 && g==0 && b==0)
- ret=1;
- if(r==0 && g==255 && b==0)
- ret=2;
- if(r==0 && g==0 && b==255)
- ret=3;
- if(r==0 && g==0 && b==0)
- ret=4;
- return ret;
- }
- //根据选择区域设置光标
- CMyWnd::myMouseMove(int linemove,int act)
- {
- PAINTSTRUCT ps;
- SetBkMode(WindDC,TRANSPARENT);
- BeginPaint(m_hWnd, &ps);
- SetCursor(LoadCursor(NULL,MAKEINTRESOURCE(32649)));
- myPaintTxt(linemove,act);
- EndPaint(m_hWnd, &ps);
- }
-
- CMyWnd::TimeShowText(int line)
- {
- HDC hdc;
- int t;
- int lineposy;
- static len;
- static SIZE sz;
- hdc=Texthdc;
- if(saveCurLine<=0)
- return 0;
- if(page.Chistr[saveCurLine-1][0]==0)
- return 0;
-
- {
- StartPPch=page.Chistr[saveCurLine-1];
- TimePPch=StartPPch;
- len=strlen(TimePPch);
- GetTextExtentExPoint(hdc,TimePPch,len,WinWidth,&t,0,&sz);
- }
- t=Txx+sz.cx;
- if(t<0)
- Txx=WinWidth-TextH;
- lineposy=resavehight+(saveCurLine-1)*TextH;
- //清除掉文本区
- BitBlt(hdc,0,lineposy,WinWidth,TextH,myResM.BackDC,0,lineposy,SRCCOPY);
- if(saveWM_LButton==0)
- BitBlt(hdc,0,lineposy,WinWidth,TextH,myResM.LinebarDC,0,0,SRCAND);
- else
- BitBlt(hdc,0,lineposy,WinWidth,TextH,myResM.LinebarDC1,0,0,SRCCOPY);
-
- DeleteObject(SelectObject(hdc, hUIFont));
- SetTextColor(hdc,RGB(0,100,0));
- if(saveCurLine==1)
- TextOut(hdc,Txx,lineposy, TimePPch,len);
- else
- TextOut(hdc,Txx+20,lineposy, TimePPch,len);
- Txx-=1;
- return 0;
- }
- int CMyWnd::myPaintTxt(int linemove ,int act )
- {
- int line=0;
- char shtemss[1500];
- PAINTSTRUCT ps;
- HDC hdc;
- RECT LoWinRect;
- long h,w;
- GetWindowRect(m_hWnd,&LoWinRect);
- w=LoWinRect.right-LoWinRect.left;
- h=LoWinRect.bottom-LoWinRect.top;
- //清除掉文本区
- hdc=Texthdc;
- BitBlt(hdc,0,0,WinWidth,WinHeight,myResM.BackDC,0,0,SRCCOPY);
- if(linemove>0 && linemove<6)
- {
- if(act==0)
- BitBlt(hdc,0,resavehight+(linemove-1)*TextH,WinWidth,TextH,myResM.LinebarDC,0,0,SRCAND);
- else
- BitBlt(hdc,0,resavehight+(linemove-1)*TextH,WinWidth,TextH,myResM.LinebarDC1,0,0,SRCCOPY);
- }
- for(line=0;line<5&&page.Chistr[line][0]!=0;line++)
- {
- // MessageBox(0,ss,"dd",0);
- if(page.Proprity[line]=='1')
- SetTextColor(hdc,RGB(0,0,255));
- if(page.Proprity[line]=='2')
- SetTextColor(hdc,RGB(0,0,0));
- if(page.Proprity[line]=='3')
- SetTextColor(hdc,RGB(0,100,0));
- sprintf(shtemss,"%d:%s%s",line+1,page.Chistr[line],page.Enstr[line]);
- if(line==0)
- TextOut(hdc,5,resavehight+line*TextH, shtemss,strlen(shtemss));
- else
- TextOut(hdc,25,resavehight+line*TextH, shtemss,strlen(shtemss));
- }
- BeginPaint(m_hWnd, &ps);
- WindDC=GetDC(m_hWnd);
- BitBlt(WindDC,0,0,WinWidth,WinHeight,hdc,0,0,SRCCOPY);
- EndPaint(m_hWnd, &ps);
- // if(line<3)
- // MoveWindow(m_hWnd,LoWinRect.left,LoWinRect.top,w,ControlHeight+TextH*2,TRUE);
- // else
- // MoveWindow(m_hWnd,LoWinRect.left,LoWinRect.top,WinWidth,WinHeight,TRUE);
- }
- //特殊字符处理,
- int CMyWnd:: specsif(char *ss)
- {
- int i,t,t1,t2,len;
- //特殊字符处理,以便支持特殊字符了输入
- len=strlen(ss);
- if(len>=4)
- {
- t=-1;
- for(i=0;i<len;i++)
- {
- t++;
- t1=t2=-1;
- if(ss[i]=='0' && (ss[i+1]=='x'||ss[i+1]=='X') && i<len-2 )
- {
- if(ss[i+2]>='0' && ss[i+2]<='9')
- t1=ss[i+2]-'0';
- if(ss[i+2]>='a' && ss[i+2]<='f')
- t1=ss[i+2]-'a'+10;
- if(ss[i+2]>='A' && ss[i+2]<='F')
- t1=ss[i+2]-'A'+10;
- if(ss[i+3]>='0' && ss[i+3]<='9')
- t2=ss[i+3]-'0';
- if(ss[i+3]>='a' && ss[i+3]<='f')
- t2=ss[i+3]-'a'+10;
- if(ss[i+3]>='A' && ss[i+3]<='F')
- t2=ss[i+3]-'A'+10;
- }
- if(t1!=-1 && t2!=-1)
- {
- //char tem[100];
- //sprintf(tem,"%d %d",t1,t2);
- t1=t1*16+t2;
- ss[t]=t1;
- //MessageBox(0,tem,ss,0);
- i=i+3;
- }
- else
- ss[t]=ss[i];
- }
- ss[t+1]=0;
- }
- return 0;
- }
- //设置需要显示的字符串
- int CMyWnd:: settxt(char *ss)
- {
- int i,len,line=0;
- char *ppc;
- if(ss!=NULL)
- strcpy(showtxt,ss);
- else
- showtxt[0]=0;
- ppc=showtxt;
- len=strlen(ppc);
- for(i=0;i<5;i++)
- {
- page.Enstr[i][0]=0;
- page.Chistr[i][0]=0;
- page.Proprity[i]=0;
- }
- for(i=0;i<len;i++)
- {
- if(showtxt[i]==';')
- {
- showtxt[i]=0;
- strcpy(page.Enstr[line],ppc);
- ppc=&showtxt[i+1];
- line++;
- if(line==5)
- break;
- }
- if(showtxt[i]==' ')
- {
- showtxt[i]=0;
- strcpy(page.Chistr[line],ppc);
- //特殊字符处理
- specsif(page.Chistr[line]);
- page.Proprity[line]=showtxt[i+1];
- ppc=&showtxt[i+2];
- }
- }
-
- return 0;
- }
- int CMyWnd::MyWinMove(POINT pt)
- {
- POINT pt1;
- pt1=pt;
- myResM.WriteRegPos("CMyWnd",pt);
- myResM.WriteRegPos("ConHwnd",pt);
- pt1.y-=inputWind->ControlHeight;
- myResM.WriteRegPos("inputHwnd",pt1);
- SetWindowPos(m_hWnd, 0, pt.x, pt.y,0, 0, 21);
- SetWindowPos(ConWind->m_hWnd, 0, pt.x-31, pt.y+15,0, 0, 21);
- SetWindowPos(inputWind->m_hWnd,0, pt1.x, pt1.y,0, 0, 21);
- return 0;
- }
- int CMyWnd::RedrawWin()
- {
- RECT upwin;
- GetWindowRect(m_hWnd,&upwin);
- upwin.bottom=upwin.bottom-inputWind->ControlHeight;
- RedrawWindow(m_hWnd,0,0,RDW_VALIDATE|RDW_NOCHILDREN|RDW_INVALIDATE|RDW_ERASENOW|RDW_ERASE);//RDW_ERASE
- return 0;
- }
- //链接到目标地址
- int CMyWnd::selectback()
- {
- char gg[512]="";
- char filter[100]="图片形文件 (*.*)|*.bmp";
- if(browseFile(gg,255, 0,0,filter,NULL))//m_hWnd
- {
- char dd[512]="";
- myfileExtname(gg,dd);
- strupr(dd);
- if(strcmp(dd,"BMP")==0||strcmp(dd,"JPG")==0){
- RegSaveString("backpic",gg);
- myResM.loadback();
- }else{
- MessageBox(0,gg,"文件类型应为bmp或jpg,请重新选择。",0);
- }
- }
- DrawFrame();
- myPaintTxt(0,0);
- return 0;
- }
- //链接到目标地址
- HINSTANCE GotoURL(LPCTSTR url, int showcmd)
- {
- // 调用函数ShellExecute()
- // HINSTANCE result = (HINSTANCE)ShellExecute(NULL, "open", url, NULL,NULL, showcmd);
- return 0;
- }
- //返回所选菜单项
- long CMyWnd::Popup()
- {
- long iMenu, nMenus,result,retabout;
- POINT p ;
- char buffer [256]="";
- long flag=0;
- HMENU hMenu;
- int CurentKbdNum=0;
- char MenuName[20][256]={"词语管理","锁定背景","跟踪灵敏","选择背景","透 明 度","增加边框","输入模式"
- ,"滚动显示","四码段词","自动造词","窗 花"," 帮 助 ","关于极速"};
- GetCursorPos(&p);
- hMenu = CreatePopupMenu();
- nMenus = 13;
- for(iMenu = 1 ;iMenu<=nMenus;iMenu++)
- {
- flag=0;
- if(2==iMenu)
- {
- char dd[500];
- RegReadString("backpic",dd);
- //MessageBox(0,"ddd",dd,0);
- if(dd[0]!=0)
- flag|=MF_CHECKED;
- }
- switch (iMenu)
- {
- case 1:
- flag|=MF_ENABLED;
- break;
- case 2:
- flag|=MF_ENABLED;
- break;
- case 3:
- flag|=MF_ENABLED;
- break;
- case 4:
- flag|=MF_ENABLED;
- break;
- case 5:
- flag|=MF_ENABLED;
- break;
- case 6:
- if(myResM.frameflage[0]=='1')
- flag=MF_ENABLED|MF_CHECKED;
- else
- flag=MF_ENABLED;
- break;
- case 7:
- flag|=MF_ENABLED;
- break;
- case 8:
- if(myResM.scrollflage[0]=='1')
- {
- SetTimer(m_hWnd,1,20,NULL);
- flag=MF_ENABLED|MF_CHECKED;
- }
- else
- {
- flag=MF_ENABLED;
- }
- break;
- case 10:
- if(myResM.autoword[0]=='1')
- {
- flag=MF_ENABLED|MF_CHECKED;
- }
- else
- {
- flag=MF_ENABLED;
- }
- break;
- case 11:
- if(myResM.flowerflage[0]=='1')
- {
- flag=MF_ENABLED|MF_CHECKED;
- }
- else
- {
- flag=MF_ENABLED;
- }
- break;
- case 12:
- flag|=MF_ENABLED;
- break;
- case 13:
- flag|=MF_ENABLED;
- break;
- default:
- flag=MF_GRAYED|MF_DISABLED;
- break;
- }
- if(iMenu==8)
- flag|=MF_MENUBREAK|MF_MENUBARBREAK;
-
- AppendMenu (hMenu, flag, iMenu, MenuName[iMenu-1]);
- if(iMenu!=7)
- AppendMenu (hMenu, MF_SEPARATOR, iMenu, "");
- }
- iMenu = TrackPopupMenu(hMenu, TPM_RIGHTBUTTON + TPM_LEFTALIGN + TPM_NONOTIFY + TPM_RETURNCMD, p.x, p.y, 0, GetForegroundWindow(), 0);
- //得到菜单的选择字符串
- result = GetMenuString(hMenu, (iMenu - 1), buffer, strlen(buffer), MF_BYPOSITION);
-
- DestroyMenu(hMenu);
- if(iMenu>0)
- {
- switch (iMenu)
- {
- case 1:
- {
- char AppPath[500];
- int i;
- GetModuleFileName(hInst,AppPath,256);
- for(i=strlen(AppPath)-1;i>=0;i--)
- {
- if(AppPath[i]=='\')
- {
- AppPath[i]=0;
- strcat(AppPath,"\词语管理.exe ShowMessageBox");
- break;
- }
- }
- WinExec(AppPath,1);
- break;
- }
- case 2:
- myResM.FixBackPic();
- {
- char dd[500]="";
- //RegReadString("backpic",dd);
- //MessageBox(0,"dd",dd,0);
- }
- break;
- case 3:
- if(myResM.traceflage[0]>'0' && myResM.traceflage[0]<='9')
- EDIT1_txt[0]=myResM.traceflage[0];
- else
- EDIT1_txt[0]='0';
- EDIT1_txt[1]=0;
- strcpy(EDIT2_txt," 跟踪灵敏度设10个级别:0立即移动,1为20个单位,……,8为160个单位,9锁定,默认为3。以下为当前灵敏度");
- retabout=DialogBox(hInst,MAKEINTRESOURCE(IDD_DIALOG1),0,About);
- if(retabout==IDOK)
- {
- myResM.traceflage[0]=EDIT1_txt[0];
- myResM.traceflage[1]=0;
- if(myResM.traceflage[0]>'0' && myResM.traceflage[0]<='9')
- RegSaveString("traceflage",myResM.traceflage);
- else
- RegSaveString("traceflage","0");
- }
- break;
- case 4:
- selectback();
- break;
- case 5:
- {
- char tem[20];
- sprintf(tem,"%d",myResM.clarityflage);
- strcpy(EDIT1_txt,tem);
- strcpy(EDIT2_txt," 透明度设置,值越小透明度越高,可以是1-255中的一个值。当前的值为:");
- retabout=DialogBox(hInst,MAKEINTRESOURCE(IDD_DIALOG1),0,About);
- if(retabout==IDOK)
- {
- myResM.clarityflage=EDIT1_NUM;
- if(myResM.clarityflage==0||myResM.clarityflage>255)
- myResM.clarityflage=200;
- WriteReg("clarityflage",(DWORD)myResM.clarityflage);
- SetAllWinAttrib(myResM.clarityflage);
- }
- }
- break;
- case 6:
- if(myResM.frameflage[0]=='1')
- {
- RegSaveString("frameflage","0");
- myResM.frameflage[0]='0';
- }
- else
- {
- myResM.RegSaveString("frameflage","1");
- myResM.frameflage[0]='1';
- }
- DrawFrame();
- break;
- case 7:
- GotoURL("www.cctv.com",1);
- ConWind->ModlePopup(myResM.CurModleNum);
- break;
- case 8:
- if(myResM.scrollflage[0]=='1')
- {
- RegSaveString("scrollflage","0");
- myResM.scrollflage[0]='0';
- }
- else
- {
- myResM.RegSaveString("scrollflage","1");
- myResM.scrollflage[0]='1';
- }
- break;
- case 10:
- if(myResM.autoword[0]=='1')
- {
- RegSaveString("autoword","0");
- myResM.autoword[0]='0';
- }
- else
- {
- myResM.RegSaveString("autoword","1");
- myResM.autoword[0]='1';
- }
- break;
- case 11:
- if(myResM.flowerflage[0]=='1')
- {
- RegSaveString("flowerflage","0");
- myResM.flowerflage[0]='0';
- }
- else
- {
- myResM.RegSaveString("flowerflage","1");
- myResM.flowerflage[0]='1';
- }
- DrawFrame();
- break;
- case 12:
- WinExec("hh c:\jsime\jsime.CHM",1);
- //WinHelp(NULL,"c:\jsime\jsime.hlp",HELP_CONTENTS,0);
- break;
- case 13:
- strcpy(EDIT1_txt,"E-MAIL:whln669@sohu.com ");
- strcpy(EDIT2_txt," 首先感谢各位用户使用《极速五笔》,本软件是由王华设计开发,如对本软件有意见和建议,或需要得到帮助,请发电子邮件与本人联系。谢谢!");
- DialogBox(hInst,MAKEINTRESOURCE(IDD_DIALOG1),0,About);
-
- break;
- default:
- MessageBox(0,"过两天补上","功能暂时未编码",0);
- break;
- }
- }
- return 0;
- }
- //////////////////////////////////////////////////////////////////////////////
- // 内部函数
- // 需要类CMyWnd支持
- int CMyWnd::MyMoveWinInput(HWND hWnd ,long x,long y)
- {
- RECT LoWinRect,ParentWinRect,screenrc;
- long h,w,temy;
- static int savy;;
- int trace;
- //char ss[100];
- //sprintf(ss,"%d",cmywnd->m_hWnd);
- //MessageBox(0,"Main create",ss,0);
- temy=y;
-
- SystemParametersInfo(SPI_GETWORKAREA,0, &screenrc,0);
- GetWindowRect(m_hWnd,&LoWinRect);
- if(IsWindow(hWnd))
- {
- GetWindowRect(hWnd,&ParentWinRect);
- }
- else
- {
- ParentWinRect.right=0;
- ParentWinRect.left=0;
- ParentWinRect.top=0;
- ParentWinRect.bottom=0;
- }
- w=LoWinRect.right-LoWinRect.left;
- h=LoWinRect.bottom-LoWinRect.top;
- if((x>10000 && y>10000)||(x<=0 && y<=0))
- return 0;
- x=x+ParentWinRect.left;
- y=y+ParentWinRect.top+inputWind->ControlHeight;
- //如果座标远离窗口时才移动。
- trace=(int)(myResM.traceflage[0]-'0');
- if(trace<9)
- {
- int t,con;
- trace=trace*20;
- t=LoWinRect.left-x;
- if(t> trace || t<-trace|| savy!=temy )
- {
- savy=temy;
- con=inputWind->ControlHeight;
- if(x<screenrc.left )
- x=screenrc.left;
- if( x>screenrc.right-w)
- x=screenrc.right-w;
- if( y<screenrc.top )
- y=screenrc.top;
- if(y>screenrc.bottom-h-con )
- {
- //y=screenrc.bottom-h;
- y=y-con-h-40;
- MoveWindow(m_hWnd,x,y,w,h,TRUE);
- y=y+h;
- x=x+20;
- MoveWindow(inputWind->m_hWnd,x,y,w,con,TRUE);
- }
- else
- {
- y=y+10;
- MoveWindow(inputWind->m_hWnd,x,y,w,con,TRUE);
- y=y+con;
- MoveWindow(m_hWnd,x,y,w,h,TRUE);
- }
- // SetWindowPos(ConWind->m_hWnd, 0, x,y,0, 0, 21); //SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER //16/1/4
- }
- }
- return 0;
- }