jsIME.cpp
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:6k
源码类别:

输入法编程

开发平台:

Visual C++

  1. // jsIME.cpp : Defines the entry point for the DLL application.
  2. //
  3. #include "stdafx.h"
  4. #include "Windows.h"
  5. #include "stdio.h"
  6. #include "windef.h"
  7. #include "DllManager.h"
  8. #include "resource.h"
  9. #include "jsIME.h"
  10.    
  11. char szWindowClass[100];
  12. char szHello[100];
  13. int myMouseDown;
  14. RECT MdWinRect;
  15. int BnNum ;
  16. POINT Mdnpoint;
  17. POINT TxTpoint;
  18. HINSTANCE  myhInst;
  19. DllManager DllMns;
  20. int  myFullErr=0;
  21. int myCreatWind (HINSTANCE hInstance,HWND ParetHWND ,int x,int y, int w,int h,int nCmdShow);
  22. BOOL InitInstance(HWND ParetHWND ,int x,int y, int w,int h, int nCmdShow);
  23. void  DrawUIBorder( LPRECT lprc );//用指定的矩形画一个虚框
  24. void Paint(HWND hWnd);
  25. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  26. void SetTXT(char *ss);
  27. extern HIMC savehIMC;
  28. HWND UIhWnd;
  29. HWND MainhWnd ;  //此变量外部程序要用来控制窗口状态 
  30. HWND outMainhWnd;
  31. HWND hSoftKbdWnd=NULL;
  32. BOOL IMERegisterClass( HINSTANCE hInstance );
  33. LONG NotifyHandle(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  34. LRESULT WINAPI UIWndProc(HWND hWnd, UINT message,WPARAM wParam, LPARAM lParam);
  35. BOOL WINAPI DllMain (
  36.  HINSTANCE    hInstDLL,
  37.  DWORD        dwFunction,
  38.  LPVOID       lpNot)
  39. {
  40.      switch(dwFunction)
  41.     {
  42. case DLL_PROCESS_ATTACH:
  43. myhInst = hInstDLL;
  44. DllMns.hInstance= hInstDLL;
  45. strcpy(szWindowClass,"MeIME");
  46. sprintf(szHello,"");
  47. IMERegisterClass(myhInst);
  48.      //MessageBox (0,"start",0,0);
  49. break;
  50.     case DLL_PROCESS_DETACH:
  51. UnregisterClass(szWindowClass,myhInst);
  52. UnregisterClass(UICLASSNAME,myhInst);
  53. break;
  54.     case DLL_THREAD_DETACH:
  55. break;
  56. }
  57.     return TRUE;
  58. }
  59. BOOL IMERegisterClass( HINSTANCE hInstance )
  60. {
  61.    WNDCLASSEX wc;
  62.    
  63.     // 注册 UI窗口类.
  64.     wc.cbSize         = sizeof(WNDCLASSEX);
  65.     wc.style          = CS_FREEPY | CS_IME;
  66.     wc.lpfnWndProc    = (WNDPROC)UIWndProc;
  67.     wc.cbClsExtra     = 0;
  68.     wc.cbWndExtra     = 8;
  69.     wc.hInstance      = hInstance;
  70.     wc.hCursor        = LoadCursor( NULL, IDC_ARROW );
  71.     wc.hIcon          = NULL;
  72.     wc.lpszMenuName   = (LPTSTR)NULL;
  73.     wc.lpszClassName  = UICLASSNAME;
  74.     wc.hbrBackground  = NULL;
  75.     wc.hIconSm        = NULL;
  76.     if( RegisterClassEx( (LPWNDCLASSEX)&wc )==0 )
  77.         return FALSE;
  78.     return TRUE;
  79. }
  80. //* IME UI 窗口处理程序
  81. //* 如果形成多的乱码错误就在于此
  82. LRESULT WINAPI UIWndProc(HWND hWnd, UINT message,WPARAM wParam, LPARAM lParam)
  83. {
  84.     HIMC           hUICurIMC;
  85.     LPINPUTCONTEXT lpIMC;
  86.     LONG           lRet = 0L;
  87. long *hWinC, *lpWinC;
  88. char ss[100];
  89. sprintf(ss,"%d",message);//131,0,1156360
  90.  try {
  91.     hUICurIMC = (HIMC)GetWindowLong(hWnd,IMMGWL_IMC);
  92. if (!hUICurIMC)
  93.     {
  94.         switch (message)
  95.         {
  96. case WM_IME_STARTCOMPOSITION:
  97. case WM_IME_ENDCOMPOSITION:
  98. case WM_IME_COMPOSITION:
  99. case WM_IME_NOTIFY:
  100. case WM_IME_CONTROL:
  101. case WM_IME_COMPOSITIONFULL:
  102. case WM_IME_SELECT:
  103. case WM_IME_CHAR:
  104. return 0L;
  105. default:
  106. break;
  107.         }
  108.     }
  109. switch (message)
  110.     {
  111. case WM_CREATE:
  112. //启动提示窗口。
  113. outMainhWnd=hWnd;
  114. strcpy(szWindowClass,"MeIME");
  115. if(myFullErr==0)
  116. myFullErr=DllMns.mgDllStart();
  117.    if(myFullErr==0)
  118.    {
  119. long *hh,*lphh;
  120. //hUICurIMC在建立时为空0.
  121. hh = (long*)GlobalAlloc(GHND,sizeof(LONG));
  122. lphh = (long*)GlobalLock(hh);
  123. if(lphh!=NULL)
  124. {
  125. *lphh=DllMns.CreateWin("ddt","ddd",hWnd,savehIMC);//
  126. SetWindowLong(hWnd,sizeof(LONG),(DWORD)hh);
  127. }
  128. GlobalUnlock(hh);
  129.    }
  130. break;
  131. case WM_DESTROY:
  132.     try {
  133.            //MessageBox (0,"ImeDestroy",0,0);
  134. hWinC = (long*)GetWindowLong(hWnd,IMMGWL_PRIVATE);
  135. lpWinC = (long*)GlobalLock(hWinC);
  136. if(lpWinC!=NULL)
  137. {
  138. DllMns.hmainWin=*lpWinC;
  139. DllMns.mgDllEnd();
  140. }
  141. GlobalUnlock(hWinC);
  142.     GlobalFree(hWinC);
  143.   } catch (...) {
  144.   MessageBox(0,"Error mgDllEnd",0,0);
  145.   }
  146. break;
  147. case WM_IME_NOTIFY:
  148.     lRet = NotifyHandle( hWnd,message,wParam,lParam);
  149. break;
  150. case WM_IME_SETCONTEXT:
  151.     try {
  152. if (wParam)
  153. {
  154. hWinC = (long*)GetWindowLong(hWnd,IMMGWL_PRIVATE);
  155. lpWinC = (long*)GlobalLock(hWinC);
  156. if(lpWinC!=NULL)
  157. DllMns.hmainWin=*lpWinC;
  158. if (hUICurIMC)
  159. {
  160. // 输入上下文被改变, 如果有子窗口,必须更新显示
  161. lpIMC = ImmLockIMC(hUICurIMC);
  162. if (lpIMC){
  163. DllMns.mgUpDateaWin(hUICurIMC);
  164. }
  165. else
  166. DllMns.mgHideAllWin();
  167. ImmUnlockIMC(hUICurIMC);
  168. }
  169. else   // 输入上下文是空.
  170. DllMns.mgHideAllWin();
  171. GlobalUnlock(hWinC);
  172. }
  173.   } catch (...) {
  174.   MessageBox(0,"whJSIME.dll WM_IME_SETCONTEXT",0,0);
  175.   }
  176. break;
  177. case WM_IME_COMPOSITION:
  178. DllMns.mgUpDateaWin(hUICurIMC);
  179. break;
  180. case WM_IME_ENDCOMPOSITION:
  181. //if(!(wParam==0&&lParam==0))
  182. //DllMns.mgHideWin();
  183. break;
  184. default:
  185. return DefWindowProc(hWnd,message,wParam,lParam);
  186.     }
  187. } catch (...) {
  188.  MessageBox(0,"Error whJSIME.dll IME UIWndProc",0,0);
  189. }
  190.     return lRet ;
  191. }
  192. ///////////////////////////////////////////////////
  193. LONG NotifyHandle(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  194. {  
  195. HIMC           hUICurIMC;
  196.     LPINPUTCONTEXT lpIMC;
  197. long *hh,*lphh;
  198. char ss[1000]="";
  199.     hUICurIMC = (HIMC)GetWindowLong(hWnd,IMMGWL_IMC);
  200. if (!(lpIMC = ImmLockIMC(hUICurIMC)))
  201.         return 0L;
  202. hh = (long*)GetWindowLong(hWnd,IMMGWL_PRIVATE);
  203. lphh = (long*)GlobalLock(hh);
  204. if(lphh!=NULL)//确定窗口类
  205. {
  206. DllMns.hmainWin=*lphh;
  207. //sprintf(ss,"%d",*lphh);
  208. //MessageBox (0,ss,0,0);
  209. }
  210.    switch (wParam)
  211.     {
  212. case IMN_CLOSESTATUSWINDOW:
  213. DllMns.mgHideAllWin();
  214. break;
  215. case IMN_OPENSTATUSWINDOW:
  216. DllMns.mgUpDateaWin(hUICurIMC);
  217. //MessageBox (0,"IMC_SETOPENSTATUS",0,0);
  218. break;
  219. case IMN_SETCONVERSIONMODE:
  220. break;
  221. case IMN_SETCOMPOSITIONWINDOW:
  222. break;
  223. case IMN_SETOPENSTATUS:
  224. break;
  225.    }
  226. GlobalUnlock(hh);
  227.     ImmUnlockIMC(hUICurIMC);
  228.     return 0;
  229. }