ConHwnd.cpp
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:13k
- #include "stdafx.h"
- #include "stdio.h"
- #include "ConHwnd.h"
- #include "windows.h"
- #include "CMyWnd.h"
- #include "tool\mytool.h"
- #include "QQHwnd.h"
- extern DllManager ChLib;//定义在主DLL中
- //窗口的初始化
- ConHwnd::initalizeWin()
- {
-
- strcpy(ModleName[0],"基本优先");
- strcpy(ModleName[1],"扩展优先");
- strcpy(ModleName[2],"五笔模式");
- strcpy(ModleName[3],"扩展模式");
- WindDC=GetDC(m_hWnd);
- DeleteObject(SelectObject(WindDC, hUIFont));
- Texthdc = CreateCompatibleDC(WindDC);
- Texthdcbmp=CreateCompatibleBitmap(WindDC,WinWidth,WinHeight);
- DeleteObject(SelectObject(Texthdc, hUIFont));
- DeleteObject(SelectObject(Texthdc,Texthdcbmp));
- SetBkMode(Texthdc,TRANSPARENT);
- TextH=GetTabbedTextExtent(WindDC,"1",1,0,0)/0x10000;
- SetWindowRgn(m_hWnd,WinRGN1,TRUE);
- BackhBmp=(HBITMAP)LoadBitmap(hInst,MAKEINTRESOURCE(IDB_contrl));
- 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);
- }
- ConHwnd::ConHwnd(void*CMthis,DWORD himc)
- {
- POINT pp[100];
- int offsetx,offsety;
- HRGN TemRGN;
- Main_CWnd=(CMyWnd*)CMthis;
- fCanMove=0;
- myResM=&((CMyWnd*)Main_CWnd)->myResM;
- WinStartPos=ReadRegPos("ConHwnd");
- WinStartPos.x=WinStartPos.x-31;
- WinStartPos.y=WinStartPos.y+15;
- WinHeight=120;
- WinWidth=100;
- controlflag=0;
- offsetx=31;
- offsety=5;
- pp[0].x=offsetx; pp[0].y=offsety;
- pp[1].x=offsetx; pp[1].y=offsety+80;
- pp[2].x=offsetx+23; pp[2].y=offsety+80;
- pp[3].x=offsetx+23; pp[3].y=offsety+20;
-
- TemRGN=CreatePolygonRgn(pp,4,1);
- WinRGN1=CreateEllipticRgn(4,62,55,113);
- CombineRgn(WinRGN1,WinRGN1,TemRGN,RGN_OR);
- DeleteObject(TemRGN);
- TemRGN=CreatePolygonRgn(pp,4,1);
- WinRGN2=CreateEllipticRgn(4,62,55,113);
- CombineRgn(WinRGN2,WinRGN2,TemRGN,RGN_OR);
- DeleteObject(TemRGN);
- hUIFont = CreateFont(20, 0, 0, 0, FW_NORMAL,
- FALSE, FALSE, FALSE, ANSI_CHARSET,
- OUT_TT_PRECIS, CLIP_TT_ALWAYS, ANTIALIASED_QUALITY,
- DEFAULT_PITCH, "宋体");
- myHwndParent=NULL;
- // it's NULL context.
- keyboard =new CIMESoftKbd;
- keyboard->initalize(himc);
- }
- ConHwnd::~ConHwnd()
- {
- try{
- //如果不消毁窗口当主程序,退出时窗口依然在运行,会引起系统崩溃
- DeleteObject (WinRGN1);
- DeleteObject (WinRGN2);
- DeleteObject(hUIFont);
- DeleteDC (BackDC);
- DeleteObject(BackhBmp);
- DeleteDC (reBackDC);
- DeleteObject(reBackhBmp);
- DeleteDC (Texthdc);
- DeleteObject(Texthdcbmp);
- delete keyboard;//软键盘的释放也可能引起致使错误,暂不释放。
- //可能在窗口处理程序中本窗口已被删除。
- //让程序暂时进行处理,以防止无效访问已经退出的代码段
- if(IsWindow(m_hWnd)){
- ReleaseDC(m_hWnd,WindDC);
- //SetWindowLong(m_hWnd,GWL_WNDPROC,(long)endProc);
- DestroyWindow(m_hWnd);
- //m_hWnd=NULL;
- }
- } catch (...) {
- MessageBox(0,"~ConHwnd","有错误发生",0);
- }
- }
- BOOL ConHwnd::Create(LPCTSTR szClassName, LPCTSTR szTitle, HINSTANCE hInstance, HWND hWndParent , DWORD dwStyle ,DWORD dwExStyle, HMENU hMenu )
- {
- // 初始化全局字串
- WNDCLASSEX wcex;
- 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);
- ShowWindow(m_hWnd,SW_SHOWNOACTIVATE);
- UpdateWindow(m_hWnd);
- }
- myHwndParent=hWndParent;
- return m_hWnd != NULL;
- }
- LRESULT WINAPI ConHwnd::WindowProc(UINT uMsg,UINT wParam,LONG lParam)
- {
- POINT pt;
- int st;
- long x,y;
- static int moveflage=0;
- QQHwnd *QQ;
- static int QQtimenum;
- QQ=((CMyWnd*)Main_CWnd)->myQQWind;
- try {
- switch (uMsg)
- {
- case WM_CREATE:
- //myset.mySetWindow(m_hWnd,RGB(255,255,255),200,LWA_ALPHA|LWA_COLORKEY);
- initalizeWin();
- myset.mySetWindow(m_hWnd,RGB(255,255,255),myResM->clarityflage,LWA_ALPHA|LWA_COLORKEY);
- break;
- case WM_PAINT://绘制窗口
- myPaintTxt(0);
- break;
- case WM_SETCURSOR:
- if ((HIWORD(lParam) == WM_MOUSEMOVE))
- {
- GetCursorPos( &pt );
- GetWindowRect(m_hWnd,&WinRect);
- WinSIZE.cx = WinRect.right - WinRect.left;
- WinSIZE.cy = WinRect.bottom - WinRect.top;
- Cursordif.x = pt.x - WinRect.left;//得到相对位置
- Cursordif.y = pt.y - WinRect.top;
- SetCapture(m_hWnd);
- //SetWindowLong(m_hWnd,4,1);//GWL_HINSTANCE DWL_MSGRESULT
- //SetCursor(LoadCursor(NULL,MAKEINTRESOURCE(IDC_ARROW)));
- }
- else
- return DefWindowProc(m_hWnd,uMsg,wParam,lParam);
- break;
- case WM_LBUTTONDOWN:
- fCanMove = TRUE;
- moveflage=0;
- break;
-
- case WM_RBUTTONUP:
- GetCursorPos( &pt );//取得光标位置
- y=lParam/0x10000;
- x=lParam%0x10000;
- st=getRgnFlage(x,y);
- if(st==3)
- {
- keyboard->Popup();
- }
- if(st==6)
- {
- ModlePopup(myResM->CurModleNum);
- }
- break;
- case WM_TIMER:
- break;
- case WM_LBUTTONUP:
- GetCursorPos( &pt );//取得光标位置
- y=lParam/0x10000;
- x=lParam%0x10000;
- if( fCanMove)
- {
- GetCursorPos( &pt );
- pt.x=pt.x - Cursordif.x;
- pt.y=pt.y - Cursordif.y;
- MoveWindow(m_hWnd,pt.x,pt.y,WinSIZE.cx,WinSIZE.cy,TRUE);
- WriteRegPos("ConHwnd",pt);
- fCanMove = FALSE;
- }
- if(moveflage<3)//有大量移动就不进行操作
- {
- st=getRgnFlage(x,y);
- switch(st)
- {
- case 1:
- case 2:
- TranStr(st);
- break;
- case 3:
- keyboard->ShowSoftKbd();
- break;
- case 4:
- controlflag=1;
- keybd_event(192,0,0,0);
- keybd_event(192,0,KEYEVENTF_KEYUP,0);
- break;
- case 5:
- ShowWindow(((CMyWnd*)Main_CWnd)->m_hWnd, SW_HIDE);
- ShowWindow(((CMyWnd*)Main_CWnd)->inputWind->m_hWnd, SW_HIDE);
-
- break;
- case 6://模式设置
- {
- char buffer[5];
- myResM->CurModleNum++;
- if(myResM->CurModleNum>4)
- myResM->CurModleNum=1;
- ChLib.SetIMEModle(myResM->CurModleNum);
- buffer[0]=myResM->CurModleNum+0x30;
- buffer[1]=0;
- RegSaveString("CurModleNum",buffer);
- ((CMyWnd*)Main_CWnd)->ClearWin();
- QQ->settxt(m_hWnd,x,y,ModleName[myResM->CurModleNum-1],2);
- }
- break;
- case 7:
- RECT Rect;
- GetWindowRect(m_hWnd,&Rect);
- if(Rect.bottom-Rect.top>20)
- MoveWindow(m_hWnd,Rect.left,Rect.top,WinWidth,20,TRUE);
- else
- MoveWindow(m_hWnd,Rect.left,Rect.top,WinWidth,WinHeight,TRUE);
- ShowWindow(((CMyWnd*)Main_CWnd)->m_hWnd, SW_HIDE);
- ShowWindow(((CMyWnd*)Main_CWnd)->inputWind->m_hWnd, SW_HIDE);
-
- break;
- default:
- break;
- }
-
- }
- myPaintTxt(0);
- break;
-
- case WM_MOUSEMOVE:
- moveflage++;
- GetCursorPos( &pt );//取得光标位置
- y=lParam/0x10000;
- x=lParam%0x10000;
- st=getRgnFlage(x,y);
- if(fCanMove==TRUE)
- {
- myPaintTxt(st);
- MoveWindow(m_hWnd,pt.x - Cursordif.x, pt.y - Cursordif.y, WinSIZE.cx,WinSIZE.cy,TRUE);
- //使用SetWindowPos作移动时会改变集焦。可用MoveWindow解决。
- //在不移动时可以使用它。
- QQ->settxt(m_hWnd,x,y,"",0);
- }
- else
- {
- if(st==0)
- SetCursor(LoadCursor(NULL,MAKEINTRESOURCE(IDC_SIZEALL )));
- else
- SetCursor(LoadCursor(NULL,MAKEINTRESOURCE(IDC_ARROW)));
-
- switch(st)
- {
- case 1:
- {
- if(QQtimenum<15)
- {
- QQtimenum++;
- QQ->settxt(m_hWnd,x,y,"万能转换",4);
- }
- else
- {
- QQ->settxt(m_hWnd,x,y,"请选择内容",3);
- }
- }
- break;
- case 2:
- QQ->settxt(m_hWnd,x,y,"当前日期",4);
- break;
- case 3:
- QQ->settxt(m_hWnd,x,y,"软 键 盘",2);
- break;
- case 4:
- if(((CMyWnd*)Main_CWnd)->mydd.appdictbool==1)
- QQ->settxt(m_hWnd,x,y,"造 词 中",3);
- else
- QQ->settxt(m_hWnd,x,y," 词 语 ",3);
- break;
- case 5:
- QQ->settxt(m_hWnd,x,y,"隐藏窗口",3);
- break;
- case 6:
- QQ->settxt(m_hWnd,x,y,ModleName[myResM->CurModleNum-1],2);
- break;
- case 7:
- QQ->settxt(m_hWnd,x,y,"隐藏",2);
- break;
- default:
- QQtimenum=0;
- QQ->settxt(m_hWnd,x,y,"",0);
- break;
- }
- myPaintTxt(st);
- //测试鼠标是否移出窗口
- if(PtInRegion(WinRGN2,x,y)==0)
- {
- QQ->settxt(m_hWnd,x,y,"",0);
- myPaintTxt(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;
- }
- } catch (...) {
- MessageBox(0,"ConHwndWindowProc","有错误发生",0);
- }
- return 0;
- }
- //确定指定位置所在的区域
- int ConHwnd::getRgnFlage(long x,long y)
- {
- int ret=0;
- long rgb,r,g,b;
- rgb=GetPixel(BackDC,x+63,y);
- 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==255 && g==255 && b==0)
- ret=4;
- if(r==0 && g==255 && b==255)
- ret=5;
- if(r==255 && g==0 && b==255)
- ret=6;
- if(r==0 && g==0 && b==128)
- ret=7;
- return ret;
- }
- int ConHwnd::myPaintTxt(int select )
- {
- PAINTSTRUCT ps;
- HDC hdc;
- static savselect=-1;
- int wd,wh,offsety=0,offsetx;
- wd=WinWidth;
- wh=WinHeight;
- offsetx=30;
- offsety=-10;
- hdc=Texthdc;
- if(select!=savselect)
- {
- savselect=select;
- BitBlt(BackDC,0,0,wd,wh,reBackDC,0,0,SRCCOPY);//SRCCOPY
- //清除掉文本区
- if(select==0)
- {
- BitBlt(hdc,0,0,wd,wh,BackDC,0,0,SRCCOPY);
- }
- else
- {
- switch(select)
- {
- case 1:
- offsety=-10;
- MoveToEx(BackDC,offsetx+5,offsety+25,NULL);
- LineTo(BackDC,offsetx+20,offsety+40);
- LineTo(BackDC,offsetx+20,offsety+55);
- LineTo(BackDC,offsetx+5,offsety+40);
- LineTo(BackDC,offsetx+5,offsety+25);
- break;
- case 2:
- offsety=15;
- MoveToEx(BackDC,offsetx+5,offsety+25,NULL);
- LineTo(BackDC,offsetx+20,offsety+40);
- LineTo(BackDC,offsetx+20,offsety+55);
- LineTo(BackDC,offsetx+5,offsety+40);
- LineTo(BackDC,offsetx+5,offsety+25);
- break;
- case 3:
- TransparentBlt2(BackDC,30,65,25,35,BackDC,5,174,25,35,RGB(255,255,255));
- break;
- case 4:
- TransparentBlt2(BackDC,7,62,35,25,BackDC,2,117,35,25,RGB(255,255,255));
- break;
- case 5:
- TransparentBlt2(BackDC,4,76,25,35,BackDC,5,213,25,35,RGB(255,255,255));
- break;
- case 6:
- TransparentBlt2(BackDC,17,88,35,25,BackDC,2,144,35,25,RGB(255,255,255));
-
- break;
- case 7:
- TransparentBlt2(BackDC,33,10,10,10,BackDC,96,10,10,10,RGB(255,255,255));
- break;
- default:
- break;
- }
- }
- }
- BitBlt(hdc,0,0,wd,wh,BackDC,0,0,SRCCOPY);
- BeginPaint(m_hWnd, &ps);
- WindDC=GetDC(m_hWnd);
- BitBlt(WindDC,0,0,wd,wh,hdc,0,0,SRCCOPY);
- ReleaseDC(m_hWnd,WindDC);
- EndPaint(m_hWnd, &ps);
- }
- int ConHwnd::RedrawWin()
- {
- RedrawWindow(m_hWnd,0,0,RDW_VALIDATE|RDW_NOCHILDREN|RDW_INVALIDATE|RDW_ERASENOW|RDW_ERASE);//RDW_ERASE
- return 0;
- }
- int ConHwnd::TranStr(int selet)
- {
- HIMC hUICurIMC;
- char buf[1001]="";
- mytool jjj;
- int tt=0,rr=0;
- hUICurIMC= (HIMC)GetWindowLong(myHwndParent,IMMGWL_IMC);
- if(hUICurIMC)
- {
- jjj.TranComStr(selet,buf);
- //{
- // char ss[1001]="";
- //sprintf(ss,"%d",strlen(buf));
- //MessageBox(0,ss,"d",0);
- //buf[80]=0;
- //}
- IMESenChiApp(hUICurIMC,buf);
- }
- return 0;
- }
- HMENU ConHwnd::createModlePopup(int LCurModleNum,int dis_index){
- HMENU mhMenu;
- long iMenu;
- long flag=0;
- mhMenu = CreatePopupMenu();
- for(iMenu = 0 ;iMenu<4;iMenu++)
- {
- flag=0;
- if(LCurModleNum-1==iMenu)
- flag|=MF_CHECKED;
- else
- flag|=MF_ENABLED;
- AppendMenu (mhMenu, flag, iMenu+dis_index, ModleName[iMenu]);
- }
- return mhMenu;
- }
- int ConHwnd::setModle(int LCurModleNum){
- char buffer [3]="";
- ChLib.SetIMEModle(LCurModleNum);
- myResM->CurModleNum=LCurModleNum;
- buffer[0]=myResM->CurModleNum+0x30;
- buffer[1]=0;
- RegSaveString("CurModleNum",buffer);
- ((CMyWnd*)Main_CWnd)->ClearWin();
- return 0;
- }
- long ConHwnd::ModlePopup(int LCurModleNum)
- {
- long iMenu, result;
- POINT p ;
- char buffer [3]="";
- long flag=0;
- HMENU hMenu;
- GetCursorPos(&p);
- hMenu = createModlePopup(LCurModleNum,1);
- iMenu = TrackPopupMenu(hMenu, TPM_RIGHTBUTTON + TPM_LEFTALIGN + TPM_NONOTIFY + TPM_RETURNCMD, p.x, p.y, 0, GetForegroundWindow(), 0);
- //得到菜单的选择字符串
- result = GetMenuString(hMenu, iMenu, buffer, strlen(buffer), MF_BYPOSITION);
- DestroyMenu(hMenu);
- if(iMenu>0)
- {
- setModle(iMenu);
- }
- return iMenu;
- }