jsIME.cpp
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:6k
- // jsIME.cpp : Defines the entry point for the DLL application.
- //
- #include "stdafx.h"
- #include "Windows.h"
- #include "stdio.h"
- #include "windef.h"
- #include "DllManager.h"
- #include "resource.h"
- #include "jsIME.h"
-
- char szWindowClass[100];
- char szHello[100];
- int myMouseDown;
- RECT MdWinRect;
- int BnNum ;
- POINT Mdnpoint;
- POINT TxTpoint;
- HINSTANCE myhInst;
- DllManager DllMns;
- int myFullErr=0;
- int myCreatWind (HINSTANCE hInstance,HWND ParetHWND ,int x,int y, int w,int h,int nCmdShow);
- BOOL InitInstance(HWND ParetHWND ,int x,int y, int w,int h, int nCmdShow);
- void DrawUIBorder( LPRECT lprc );//用指定的矩形画一个虚框
- void Paint(HWND hWnd);
- LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
- void SetTXT(char *ss);
- extern HIMC savehIMC;
- HWND UIhWnd;
- HWND MainhWnd ; //此变量外部程序要用来控制窗口状态
- HWND outMainhWnd;
- HWND hSoftKbdWnd=NULL;
- BOOL IMERegisterClass( HINSTANCE hInstance );
- LONG NotifyHandle(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
- LRESULT WINAPI UIWndProc(HWND hWnd, UINT message,WPARAM wParam, LPARAM lParam);
- BOOL WINAPI DllMain (
- HINSTANCE hInstDLL,
- DWORD dwFunction,
- LPVOID lpNot)
- {
- switch(dwFunction)
- {
- case DLL_PROCESS_ATTACH:
- myhInst = hInstDLL;
- DllMns.hInstance= hInstDLL;
- strcpy(szWindowClass,"MeIME");
- sprintf(szHello,"");
- IMERegisterClass(myhInst);
- //MessageBox (0,"start",0,0);
- break;
- case DLL_PROCESS_DETACH:
- UnregisterClass(szWindowClass,myhInst);
- UnregisterClass(UICLASSNAME,myhInst);
- break;
- case DLL_THREAD_DETACH:
- break;
- }
- return TRUE;
- }
- BOOL IMERegisterClass( HINSTANCE hInstance )
- {
- WNDCLASSEX wc;
-
- // 注册 UI窗口类.
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = CS_FREEPY | CS_IME;
- wc.lpfnWndProc = (WNDPROC)UIWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 8;
- wc.hInstance = hInstance;
- wc.hCursor = LoadCursor( NULL, IDC_ARROW );
- wc.hIcon = NULL;
- wc.lpszMenuName = (LPTSTR)NULL;
- wc.lpszClassName = UICLASSNAME;
- wc.hbrBackground = NULL;
- wc.hIconSm = NULL;
- if( RegisterClassEx( (LPWNDCLASSEX)&wc )==0 )
- return FALSE;
- return TRUE;
- }
- //* IME UI 窗口处理程序
- //* 如果形成多的乱码错误就在于此
- LRESULT WINAPI UIWndProc(HWND hWnd, UINT message,WPARAM wParam, LPARAM lParam)
- {
- HIMC hUICurIMC;
- LPINPUTCONTEXT lpIMC;
- LONG lRet = 0L;
- long *hWinC, *lpWinC;
- char ss[100];
- sprintf(ss,"%d",message);//131,0,1156360
- try {
- hUICurIMC = (HIMC)GetWindowLong(hWnd,IMMGWL_IMC);
- if (!hUICurIMC)
- {
- switch (message)
- {
- case WM_IME_STARTCOMPOSITION:
- case WM_IME_ENDCOMPOSITION:
- case WM_IME_COMPOSITION:
- case WM_IME_NOTIFY:
- case WM_IME_CONTROL:
- case WM_IME_COMPOSITIONFULL:
- case WM_IME_SELECT:
- case WM_IME_CHAR:
- return 0L;
- default:
- break;
- }
- }
-
- switch (message)
- {
- case WM_CREATE:
- //启动提示窗口。
- outMainhWnd=hWnd;
- strcpy(szWindowClass,"MeIME");
- if(myFullErr==0)
- myFullErr=DllMns.mgDllStart();
-
- if(myFullErr==0)
- {
- long *hh,*lphh;
- //hUICurIMC在建立时为空0.
- hh = (long*)GlobalAlloc(GHND,sizeof(LONG));
- lphh = (long*)GlobalLock(hh);
- if(lphh!=NULL)
- {
- *lphh=DllMns.CreateWin("ddt","ddd",hWnd,savehIMC);//
- SetWindowLong(hWnd,sizeof(LONG),(DWORD)hh);
- }
- GlobalUnlock(hh);
- }
- break;
- case WM_DESTROY:
- try {
- //MessageBox (0,"ImeDestroy",0,0);
- hWinC = (long*)GetWindowLong(hWnd,IMMGWL_PRIVATE);
- lpWinC = (long*)GlobalLock(hWinC);
- if(lpWinC!=NULL)
- {
- DllMns.hmainWin=*lpWinC;
- DllMns.mgDllEnd();
- }
- GlobalUnlock(hWinC);
- GlobalFree(hWinC);
- } catch (...) {
- MessageBox(0,"Error mgDllEnd",0,0);
- }
- break;
- case WM_IME_NOTIFY:
- lRet = NotifyHandle( hWnd,message,wParam,lParam);
- break;
- case WM_IME_SETCONTEXT:
- try {
- if (wParam)
- {
- hWinC = (long*)GetWindowLong(hWnd,IMMGWL_PRIVATE);
- lpWinC = (long*)GlobalLock(hWinC);
- if(lpWinC!=NULL)
- DllMns.hmainWin=*lpWinC;
- if (hUICurIMC)
- {
- // 输入上下文被改变, 如果有子窗口,必须更新显示
- lpIMC = ImmLockIMC(hUICurIMC);
- if (lpIMC){
- DllMns.mgUpDateaWin(hUICurIMC);
- }
- else
- DllMns.mgHideAllWin();
- ImmUnlockIMC(hUICurIMC);
- }
- else // 输入上下文是空.
- DllMns.mgHideAllWin();
- GlobalUnlock(hWinC);
- }
- } catch (...) {
- MessageBox(0,"whJSIME.dll WM_IME_SETCONTEXT",0,0);
- }
- break;
- case WM_IME_COMPOSITION:
- DllMns.mgUpDateaWin(hUICurIMC);
- break;
- case WM_IME_ENDCOMPOSITION:
- //if(!(wParam==0&&lParam==0))
- //DllMns.mgHideWin();
- break;
- default:
- return DefWindowProc(hWnd,message,wParam,lParam);
- }
- } catch (...) {
- MessageBox(0,"Error whJSIME.dll IME UIWndProc",0,0);
- }
- return lRet ;
- }
- ///////////////////////////////////////////////////
- LONG NotifyHandle(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- HIMC hUICurIMC;
- LPINPUTCONTEXT lpIMC;
- long *hh,*lphh;
- char ss[1000]="";
- hUICurIMC = (HIMC)GetWindowLong(hWnd,IMMGWL_IMC);
- if (!(lpIMC = ImmLockIMC(hUICurIMC)))
- return 0L;
- hh = (long*)GetWindowLong(hWnd,IMMGWL_PRIVATE);
- lphh = (long*)GlobalLock(hh);
- if(lphh!=NULL)//确定窗口类
- {
- DllMns.hmainWin=*lphh;
- //sprintf(ss,"%d",*lphh);
- //MessageBox (0,ss,0,0);
- }
- switch (wParam)
- {
- case IMN_CLOSESTATUSWINDOW:
- DllMns.mgHideAllWin();
- break;
- case IMN_OPENSTATUSWINDOW:
- DllMns.mgUpDateaWin(hUICurIMC);
- //MessageBox (0,"IMC_SETOPENSTATUS",0,0);
- break;
- case IMN_SETCONVERSIONMODE:
- break;
- case IMN_SETCOMPOSITIONWINDOW:
- break;
- case IMN_SETOPENSTATUS:
- break;
- }
- GlobalUnlock(hh);
- ImmUnlockIMC(hUICurIMC);
- return 0;
- }