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

输入法编程

开发平台:

Visual C++

  1. #include "stdafx.h"
  2. #include "stdio.h"
  3. #include "CMyWnd.h"
  4. #include "windows.h"
  5. #include "GIF.h"
  6. #include "string.h"
  7. #include "CMyMenu.h"
  8. #include "math.h" 
  9. CGIF m_Gif;
  10. POINT pst;
  11. int tt;
  12. #include "DllManager.h"
  13. extern DllManager ChLib;//定义在主DLL中
  14. /*int  EDIT1_NUM;
  15. char EDIT1_txt[200];
  16. char EDIT2_txt[200];
  17. BOOL WINAPI About(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam )
  18. {
  19. switch (message)
  20. {
  21. case WM_INITDIALOG:
  22. SetDlgItemText(hDlg,IDC_EDIT1,EDIT1_txt);
  23. SetDlgItemText(hDlg,IDC_EDIT2,EDIT2_txt);
  24. SetWindowPos(hDlg, 0, 400,300,0, 0, 21); //SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER  //16/1/4
  25. return TRUE;
  26. case WM_COMMAND:
  27. switch(wParam) {
  28. case IDOK:
  29. GetDlgItemText(hDlg,IDC_EDIT1,EDIT1_txt,2);
  30. EDIT1_NUM=GetDlgItemInt(hDlg,IDC_EDIT1,0,FALSE);
  31. EndDialog(hDlg,IDOK);
  32. break;
  33. case IDCANCEL:
  34. EndDialog(hDlg,IDCANCEL);
  35. break;
  36. default:
  37. break;
  38. }
  39. break;
  40. }
  41.     return FALSE;
  42. }*/
  43. //////////////////////////////////////////////////////////
  44. //   窗口的初始化
  45. //由于在类建立时还没有建立窗口,因此m_hWnd没有有效值。
  46. //  类建立时还不能初始化,只有调用了CREATE后才可以。
  47. CMyWnd::initalizeWin()
  48. {
  49. WindDC=GetDC(m_hWnd);
  50. myResM.InitResManager(WindDC,hInst,WinWidth, WinHeight);
  51. DeleteObject(SelectObject(WindDC, hUIFont));
  52. TextH=GetTabbedTextExtent(WindDC,"1",1,0,0)/0x10000; 
  53. SetWindowRgn(m_hWnd,WinRGN1,TRUE);
  54. Texthdc = CreateCompatibleDC(WindDC);
  55. Texthdcbmp=CreateCompatibleBitmap(WindDC,WinWidth,WinHeight);
  56. DeleteObject(SelectObject(Texthdc, hUIFont));
  57. DeleteObject(SelectObject(Texthdc,Texthdcbmp));
  58. SetBkMode(Texthdc,TRANSPARENT);
  59. }
  60. int  CMyWnd::ClearWin()
  61. {
  62. static int nullflag=0;
  63. stopflash=0;
  64. settxt("");
  65. inputWind->showtxt[0]=0;
  66. myPaintTxt(0,actSetstr);
  67. inputWind->myPaintTxt(0,actSetstr);
  68. return 0;
  69. }
  70. int  CMyWnd::SetShowString(char*MindleStr,char*InputStr)
  71. {
  72. static int nullflag=0;
  73. stopflash=0;
  74. settxt(MindleStr);
  75. {
  76. int i,len;
  77. if(InputStr!=NULL)
  78. {
  79. len=strlen(InputStr);
  80. for(i=0;i<len;i++)
  81. inputWind->showtxt[i]=InputStr[i];
  82. inputWind->showtxt[i]=0;
  83. }
  84. else
  85. inputWind->showtxt[0]=0;
  86. }
  87. /*
  88. if(InputStr!=NULL)
  89. strcpy(cmywnd->inputWind->showtxt,InputStr);
  90. else
  91. cmywnd->inputWind->showtxt[0]=0;
  92. */
  93. myPaintTxt(0,actSetstr);
  94. inputWind->myPaintTxt(0,actSetstr);
  95. if(inputWind->showtxt[0]==0)
  96. nullflag++;
  97. else
  98. nullflag=0;
  99. if(nullflag>1)
  100. {
  101. ShowWindow(m_hWnd,SW_HIDE);
  102. if(nullflag>2)
  103. ShowWindow(inputWind->m_hWnd,SW_HIDE);
  104. }
  105. else
  106. {
  107. ShowWindow(m_hWnd,SW_SHOWNOACTIVATE);
  108. ShowWindow(inputWind->m_hWnd,SW_SHOWNOACTIVATE);
  109. }
  110. return 0;
  111. }
  112. //键盘过滤,0为不过滤
  113. BOOL CMyWnd::myImeProcessKey(char *SendCH,char*Control,HIMC hIMC,UINT vKey,LPARAM lKeyData,CONST LPBYTE lpbKeyState)
  114. {
  115. LONG fRet;
  116. int mykey,lon;
  117. try{
  118. fRet=inmyImeProcessKey(SendCH,Control,hIMC,vKey,lKeyData,lpbKeyState);
  119. if(fRet==0)
  120. {
  121. mykey=(int)vKey;
  122. if(mykey>=32&&mykey<=126)
  123. myResM.Chtime.appnum(1);//计数一次
  124. }
  125. myQQWind->disabledailtimer();
  126. lon=strlen(SendCH);
  127. myResM.Chtime.appnum(lon/2);//计数一次
  128. if(lon==2)
  129. myResM.ChAutoword.AppOne(SendCH);
  130.   } catch (...) {
  131.        MessageBox(0,"myImeProcessKey","有错误发生",0);
  132.   }
  133.     return fRet;
  134. }
  135. //键盘过滤,0为不过滤
  136. BOOL CMyWnd::inmyImeProcessKey(char *SendCH,char*Control,HIMC hIMC,UINT vKey,LPARAM lKeyData,CONST LPBYTE lpbKeyState)
  137. {
  138. GENEMSG GnMsg;
  139. LONG lRet = 0L;
  140. int mykey;
  141.     BOOL fRet = FALSE, fCompStr = FALSE;
  142. static BOOL fPressOther = FALSE;
  143. char ss[1000]="";
  144. unsigned char kbByte[256];
  145. HWND hSoftKbdWnd=NULL;
  146.     mykey=(int)vKey;
  147. //sprintf(ss,"%d",mykey);
  148.     //MessageBox (0,ss,0,0);
  149.    if (ChLib.LoadErr!=0)
  150.    {
  151.    MessageBox(0,"请立即保存,系统可能崩溃!?","发生严重错误!",0);
  152.    return FALSE;
  153.    }
  154. GetKeyboardState(kbByte);
  155. //GetAsyncKeyState上一次调用以来,如键已被按过,则位0设为1;
  156.     //否则设为0。如键目前处于按下状态,则位8设为1;如抬起,则为0。
  157. //按住Ctrl 、Shift(10)或Alt时不进行编 VK_ATTN VK_CONTROL
  158. if (lpbKeyState[VK_ATTN] & 0x80)
  159.         return FALSE;
  160. ///////////////////////////////////////
  161. //  增词控制
  162. if (lpbKeyState[VK_CONTROL] & 0x80 ||ConWind->controlflag==1)
  163. {
  164. if ( mykey==192)
  165. {
  166. if(mydd.appdictbool==0)
  167. myQQWind->settxt("造 词 中");
  168. else
  169. myQQWind->settxt(" 词  语 ");
  170.  strcpy(ChLib.Control,"AppDict");
  171.  mydd.AppSetDict(hIMC);
  172.  ConWind->controlflag=0;
  173.  fRet=1;
  174. }
  175. else
  176. fRet=0;
  177. return fRet;
  178. }
  179.     //////////////////////////////////////////////
  180. //软键盘功能
  181. {
  182. hSoftKbdWnd=ConWind->keyboard->CIMEhSoftKbdWnd;//试探性取数据
  183. GetWindowText(hSoftKbdWnd,ss,2);
  184. if(ss[0]!=0)
  185. { //试探性取数据,正式获取数据
  186. GetWindowText(hSoftKbdWnd,ss,200);
  187. return SoftKbdProcess(ss,mykey,SendCH);
  188. }
  189. }
  190. if(kbByte[VK_CAPITAL]&1)//大写字母打开时将不进行输入处理
  191. return 0;
  192. //sprintf(ss,"%d",mykey);
  193.     //MessageBox (0,ss,0,0);
  194.     ////////////////////////////////////////////////////
  195. //以下为转换功能
  196. if(GetIsUpdate())                   //查看软件是否需要更新字库
  197. ChLib.DLLstart(1);
  198.  
  199. if(ChLib.Linputbuf[0]!=0)    //进行翻页功能
  200. {
  201. if(mykey==33)
  202. {
  203. ChLib.getnextpage(ChLib.LMidtems,0);
  204. SetShowString(ChLib.LMidtems,ChLib.Linputbuf);
  205.             //MessageBox (0,DllMns.LMidtems,0,0);
  206. return 1;
  207. }
  208. if(mykey==34)
  209. {
  210. ChLib.getnextpage(ChLib.LMidtems,1);
  211. SetShowString(ChLib.LMidtems,ChLib.Linputbuf);
  212. return 1;
  213. }
  214. }
  215. fRet=ChLib.keyprogress(mykey,ChLib.Linputbuf, ChLib.SendCH,ChLib.SendEN,ChLib.LMidtems,ChLib.Control);
  216. if(ChLib.Linputbuf[0]==0)
  217. SetShowString("","");
  218. else
  219. SetShowString(ChLib.LMidtems,ChLib.Linputbuf);
  220. //MessageBox(0,DllMns.LMidtems,DllMns.Linputbuf,0);
  221. if(mydd.appdictbool==1)
  222. {
  223. if(ChLib.SendCH[0]!=0)
  224. mydd.AppOne(ChLib.SendCH);
  225. }
  226.     /////////////////////////////////////////////////
  227. //   提示窗口控制功能
  228. //   下面为获得光标位置,并设置提示窗口位置
  229. if(fRet!=0)
  230. POINT ptSrc;
  231. LPINPUTCONTEXT lpIMC;
  232.  //告诉系统开始接收位置
  233. GnMsg.msg    = WM_IME_STARTCOMPOSITION;
  234. GnMsg.wParam = 0;
  235. GnMsg.lParam = 0;
  236. GenerateMessage(hIMC, 0,(LPGENEMSG)&GnMsg);
  237. //发结束消息,不然会出现ATL功能键的异常。
  238. GnMsg.msg    = WM_IME_ENDCOMPOSITION;
  239. GnMsg.wParam = 0;
  240. GnMsg.lParam = 0;
  241. GenerateMessage(hIMC, 0,(LPGENEMSG)&GnMsg);
  242. if (!(lpIMC = ImmLockIMC(hIMC)))//锁存数据
  243.    return fRet;
  244. ptSrc =  lpIMC->cfCompForm.ptCurrentPos;
  245. if(ptSrc.x<-10000||ptSrc.x>10000)
  246. {
  247. GetCaretPos(&ptSrc);
  248. }
  249. //char Lss[100];
  250. //sprintf(Lss,"%ld   y%ld",ptSrc.x,ptSrc.y);
  251. //MessageBox(0,Lss,0,0);
  252. MyMoveWinInput(lpIMC->hWnd,ptSrc.x,ptSrc.y);
  253. ImmUnlockIMC(hIMC);
  254. }   //位置测试结束
  255. strcpy(SendCH,ChLib.SendCH);
  256. ChLib.SendCH[0]=0;
  257. strcpy(Control,ChLib.Control);
  258. ChLib.Control[0]=0;
  259.     return fRet;
  260. }
  261. CMyWnd::CMyWnd(DWORD himc)
  262. {
  263. int i;
  264. POINT pp[10];
  265. void* vp=(void*)this;
  266. ChLib.SetIMEModle(myResM.CurModleNum);
  267. savehimc=himc;
  268. myQQWind =new QQHwnd(vp);
  269. //myQQtimer =new QQHwnd(vp);
  270. inputWind=new inputHwnd( vp );
  271. ConWind  =new ConHwnd( vp,himc);
  272. stopflash=0;
  273. x=y=50;
  274. resavehight=4;
  275. for(i=0;i<50;i++)
  276. Arrppc[i] =NULL;
  277. TimePPch=NULL;
  278. StartPPch=NULL;
  279. WinStartPos=myResM.ReadRegPos("CMyWnd");
  280. hUIFont = CreateFont(19, 0, 0, 0, FW_NORMAL,
  281. FALSE, FALSE, FALSE, ANSI_CHARSET,
  282. OUT_TT_PRECIS, CLIP_TT_ALWAYS, ANTIALIASED_QUALITY,
  283. DEFAULT_PITCH, "宋体");
  284.     strcpy(inputWind->showtxt,"");
  285. settxt("名称:极速五笔 1.;版权:王华 1.;发行:2006.12.28 1.;E-m:whln669@sohu.com 1.;版本:2.10 1.;");
  286. m_hWnd=NULL;
  287. WinHeight=100;
  288. WinWidth=170;
  289. conh=&(inputWind->ControlHeight);
  290. pp[0].x=0; pp[0].y=0;
  291. pp[1].x=WinWidth; pp[1].y=0;
  292. pp[2].x=WinWidth; pp[2].y=WinHeight;
  293. pp[3].x=20; pp[3].y=WinHeight;
  294. pp[4].x=20; pp[4].y=40;
  295. pp[5].x=0; pp[5].y=20;
  296. pp[6].x=0;      pp[6].y=0;
  297. //文本区
  298. TextRGN=CreatePolygonRgn(pp,7,1);
  299. WinRGN1=CreatePolygonRgn(pp,7,1);
  300. WinRGN2=CreatePolygonRgn(pp,7,1);
  301. fCanMove = FALSE;
  302. saveWM_LButton=0;
  303. saveCurLine=0;
  304. }
  305. CMyWnd::~CMyWnd()
  306. {
  307. //MessageBox(0,"~CMyWnd",0,0);
  308. try{
  309. //strcpy(showtxt,"");
  310. KillTimer(m_hWnd,1);
  311. KillTimer(m_hWnd,2);
  312. KillTimer(m_hWnd,3);
  313. delete inputWind;
  314. delete ConWind;//软键盘的释放也可能引起致使错误
  315. delete myQQWind;
  316. DeleteObject(hUIFont);
  317. DeleteDC (Texthdc);
  318. DeleteObject(Texthdcbmp);
  319. DeleteObject (WinRGN1);
  320. DeleteObject (WinRGN2);
  321. DeleteObject (TextRGN);
  322. //可能在窗口处理程序中本窗口已被删除。
  323. //让程序暂时进行处理,以防止无效访问已经退出的代码段
  324. if(IsWindow(m_hWnd)){
  325. ReleaseDC(m_hWnd,WindDC);
  326. //SetWindowLong(m_hWnd,GWL_WNDPROC,(long)endProc);
  327. DestroyWindow(m_hWnd); 
  328. //m_hWnd=NULL;
  329. }
  330.   } catch (...) {
  331.        MessageBox(0,"~CMyWnd","有错误发生",0);
  332.   }
  333. }
  334. BOOL CMyWnd::Create(LPCTSTR szClassName, LPCTSTR szTitle, HINSTANCE hInstance, HWND hWndParent , DWORD dwStyle ,DWORD dwExStyle, HMENU hMenu )
  335. {
  336. // 初始化全局字串
  337. WNDCLASSEX wcex;
  338. ChLib.hInstance=hInstance;
  339. //MessageBox(0,"Main create",0,0);
  340. wcex.cbSize = sizeof(WNDCLASSEX); 
  341. wcex.style = CS_IME;
  342. wcex.lpfnWndProc = InitProc;
  343. wcex.cbClsExtra = 0;
  344. wcex.cbWndExtra = 12;
  345. wcex.hInstance = hInstance;
  346. wcex.hIcon = 0;
  347. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  348. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  349. wcex.lpszMenuName = 0;
  350. wcex.lpszClassName = szClassName;
  351. wcex.hIconSm = 0;
  352. hInst=hInstance;
  353. RegisterClassEx(&wcex);
  354. {
  355.    m_hWnd=CreateWindowEx( 0,
  356. szClassName,NULL,
  357. WS_POPUP|WS_DISABLED,// | WS_DISABLED,WS_SIZEBOX
  358. WinStartPos.x,WinStartPos.y,WinWidth,WinHeight,
  359. hWndParent,NULL,hInstance,this);
  360. SetWindowLong(m_hWnd,8,(DWORD)hWndParent);//FIGWL_SVRWND
  361. ShowWindow(m_hWnd,SW_SHOWNOACTIVATE);
  362. UpdateWindow(m_hWnd);
  363. }
  364. //MessageBox(0,"Main create",0,0);
  365. myHwndParent=hWndParent;
  366. myQQWind->Create("QQ","QQ",hInstance,hWndParent,dwStyle,dwExStyle,hMenu);
  367. inputWind->Create("inputWind",szTitle,hInstance,hWndParent,dwStyle,dwExStyle,hMenu);
  368. ConWind->Create("ConHwnd",szTitle,hInstance,hWndParent,dwStyle,dwExStyle,hMenu);
  369. Main_hWnd=&m_hWnd;
  370. Cont_hWnd=&ConWind->m_hWnd;
  371. inpu_hWnd=&inputWind->m_hWnd;
  372. inputWind->Main_hWnd=&m_hWnd;
  373. inputWind->Cont_hWnd=&ConWind->m_hWnd;
  374. inputWind->inpu_hWnd=&inputWind->m_hWnd;
  375. ConWind->Main_hWnd=&m_hWnd;
  376. ConWind->Cont_hWnd=&ConWind->m_hWnd;
  377. ConWind->inpu_hWnd=&inputWind->m_hWnd;
  378. DrawFrame();
  379. //SetTimer(m_hWnd,1,30,0);
  380. return m_hWnd != NULL;
  381. }
  382. CMyWnd::SetAllWinAttrib(unsigned char Lclarity)
  383. {
  384. myset.mySetWindow(m_hWnd,   RGB(255,255,255),Lclarity,LWA_ALPHA|LWA_COLORKEY);
  385. myset.mySetWindow(inputWind->m_hWnd,RGB(255,255,255),Lclarity,LWA_ALPHA|LWA_COLORKEY);
  386. myset.mySetWindow(ConWind->m_hWnd,  RGB(255,255,255),Lclarity,LWA_ALPHA|LWA_COLORKEY);
  387. myset.mySetWindow(myQQWind->m_hWnd, RGB(255,255,255),Lclarity,LWA_ALPHA|LWA_COLORKEY);
  388. }
  389. ////////////////////////////////////////////////////////
  390. //   增加边框
  391. void CMyWnd::DrawFrame()
  392. {
  393. int i,line1,line2,line3,mudle1;
  394. int flowerx,flowery;
  395. BitBlt(myResM.BackDC,0,0,WinWidth,WinHeight,myResM.reBackDC,0,0,SRCCOPY);//SRCCOPY
  396. if(myResM.frameflage[0]=='1')
  397. {
  398. line1=110;
  399. line2=114;
  400. line3=110;
  401. mudle1=190;
  402. for(i=0;i<20;i++)//竖线
  403.    TransparentBlt2(myResM.BackDC,20, 38+i*3,5,5,myResM.oldBackDC,mudle1,line2,5,5,RGB(255,255,255));
  404. for(i=0;i<8;i++) //竖线
  405.    TransparentBlt2(myResM.BackDC,0,  i*3, 5,5,myResM.oldBackDC,mudle1,line2,5,5,RGB(255,255,255));
  406. for(i=0;i<35;i++)//竖线
  407.    BitBlt(myResM.BackDC,WinWidth-4,i*3,5,5,myResM.oldBackDC,mudle1,line2,SRCCOPY);
  408. for(i=0;i<8;i++)//斜线
  409.    TransparentBlt2(myResM.BackDC,i*3,18+i*3,5,5,myResM.oldBackDC,mudle1,line1,5,5,RGB(255,255,255));
  410. for(i=0;i<60;i++) //横线
  411. {
  412.    BitBlt(myResM.BackDC,i*3,0, 5,5,myResM.oldBackDC,mudle1,line3,SRCCOPY);
  413.    BitBlt(myResM.BackDC,i*3,96,5,5,myResM.oldBackDC,mudle1,line3,SRCCOPY);
  414. }
  415. }
  416. //绘制窗花
  417. if(myResM.flowerflage[0]=='1')
  418. {
  419. flowerx=180;
  420. flowery=130;
  421. TransparentBlt2(myResM.BackDC,144,0,30,30,myResM.oldBackDC,flowerx,flowery,30,30,RGB(255,255,255));
  422. flowery=166;
  423. TransparentBlt2(myResM.BackDC,144,80,30,30,myResM.oldBackDC,flowerx,flowery,30,30,RGB(255,255,255));
  424. }
  425. return;
  426. }
  427.  LRESULT WINAPI CMyWnd::WindowProc(UINT uMsg,UINT wParam,LONG lParam)
  428.  {
  429.   POINT pt;
  430.   RECT Rect;
  431.   COLORREF tColor;
  432.   int t,st;
  433.   static dely;
  434.   char gifname[256];
  435.   static int QQtimenum;
  436.   try {
  437.     switch (uMsg)
  438.     {
  439. case WM_CREATE:
  440. //半透明不能和水波共处,否则会出现窗口刷新异常
  441. //myset.mySetWindow(m_hWnd,RGB(255,255,255),myResM.clarityflage,LWA_ALPHA|LWA_COLORKEY);
  442. initalizeWin();
  443. myset.mySetWindow(m_hWnd,RGB(255,255,255),myResM.clarityflage,LWA_ALPHA|LWA_COLORKEY);
  444. GetModuleFileName(hInst,gifname,255);
  445. myGetPath(gifname);   //取路径 动画
  446. SetTimer(m_hWnd,3,1000,NULL);//
  447. SetTimer(m_hWnd,4,30,NULL);//
  448. strcat(gifname,"1.gif");
  449. if(m_Gif.LoadGIF(gifname))
  450. ;//MessageBox(0,"map","m_Gif.LoadGIF",0);
  451. else
  452. SetTimer(m_hWnd,2,100,NULL);
  453. DrawFrame();
  454.  
  455. break;
  456. case WM_TIMER:
  457.            if(stopflash==0){
  458. if(wParam==2)
  459. {
  460. KillTimer(m_hWnd,2);
  461. if(x>90)
  462. x--;
  463. if(x<90)
  464. x++;
  465. if(y>50)
  466. y--;
  467. if(y<50)
  468. y++;
  469. pt.x=x-30;
  470. pt.y=y-30;
  471. if (m_Gif.GetImageInfo (Rect,tColor,tt-1)){
  472.      BitBlt (WindDC,0,0,WinWidth, WinHeight,Texthdc,0,0,SRCCOPY);
  473. }else{
  474. //if(m_Gif.m_ImageList.m_nCount<0)
  475. // MessageBox(0,"header",0,0);
  476. GetModuleFileName(hInst,gifname,255);
  477. myGetPath(gifname);   //取路径 动画
  478. strcat(gifname,"1.gif");
  479. m_Gif.LoadGIF( gifname);
  480. }
  481. if (!m_Gif.ShowImage (WindDC,pt,tt++)){
  482. tt = 0;
  483. //m_Gif.ShowImage (WindDC,pt,tt++);
  484. }
  485. SetTimer(m_hWnd,2,100,NULL);
  486. }
  487. if(wParam==1){
  488. if(myResM.scrollflage[0]!='1')
  489. KillTimer(m_hWnd,1);
  490. TimeShowText(0);
  491. if (!m_Gif.GetImageInfo (Rect,tColor,tt-1))
  492.      BitBlt (WindDC,0,0,WinWidth, WinHeight,Texthdc,0,0,SRCCOPY);
  493. }
  494.     if(wParam==3){
  495. char temss[15];
  496. myResM.Chtime.apptime();
  497. sprintf(temss,"速度:%d",myResM.Chtime.GetAverage());
  498. myQQWind->settxttimer(m_hWnd,100,0,temss);
  499. }
  500.    }
  501. break;
  502. case WM_PAINT://绘制窗口
  503. myPaintTxt(0,saveWM_LButton);
  504. break;
  505.         case WM_SETCURSOR:
  506. if ((HIWORD(lParam) == WM_MOUSEMOVE))
  507. {
  508. if(myResM.scrollflage[0]=='1')
  509. SetTimer(m_hWnd,1,20,NULL);
  510. SetCapture(m_hWnd);
  511. //SetWindowLong(m_hWnd,4,1);//GWL_HINSTANCE DWL_MSGRESULT
  512. }
  513. else 
  514. return DefWindowProc(m_hWnd,uMsg,wParam,lParam);
  515. break;
  516.         case WM_RBUTTONDOWN:
  517. {
  518. //char ss[100];
  519. //sprintf(ss,"%d",0);
  520. //MessageBox(0,ss,"dd",0);
  521. }
  522. break;
  523.         case WM_RBUTTONUP:
  524. y=lParam/0x10000;
  525. x=lParam%0x10000;
  526. st=getRgnFlage(x,y);
  527. switch(st)
  528. {
  529. case 1:
  530. {  CMyMenu  dd(this); 
  531. dd.Popup();
  532. }
  533. break;
  534. case 4:
  535. selectback();
  536. break;
  537. }
  538. break;
  539.         case WM_LBUTTONDOWN:
  540. y=lParam/0x10000;
  541. x=lParam%0x10000;
  542. st=getRgnFlage(x,y);
  543. GetCursorPos( &pt );
  544. GetWindowRect(m_hWnd,&WinRect);
  545. Cursordif.x = pt.x - WinRect.left;//得到相对位置
  546. Cursordif.y = pt.y - WinRect.top;
  547. fCanMove=1;
  548. saveWM_LButton=1;
  549. if(st==1)
  550. {
  551. t=y/TextH+1;
  552. myPaintTxt(t,saveWM_LButton);
  553. }
  554. break;
  555.         case WM_LBUTTONUP:
  556. y=lParam/0x10000;
  557. x=lParam%0x10000;
  558. st=getRgnFlage(x,y);
  559. if( fCanMove && saveWM_LButton==0) 
  560. {
  561. GetCursorPos( &pt );
  562. pt.x=pt.x - Cursordif.x;
  563. pt.y=pt.y - Cursordif.y;
  564. MyWinMove(pt);
  565. }
  566. fCanMove = FALSE;
  567. if(st==2)
  568. {
  569. if(saveWM_LButton==1)
  570. {
  571. myQQWind->settxt(m_hWnd,x,y,"",0);
  572. ShowWindow(m_hWnd, SW_HIDE);
  573. ShowWindow(inputWind->m_hWnd, SW_HIDE);
  574. }
  575. }
  576. if(st==1)
  577. {
  578. t=y/TextH;
  579. saveCurLine=t+1;
  580. if(saveWM_LButton==1&&inputWind->showtxt[0]!=0)
  581. {
  582. keybd_event(49 + t, 0, 0, 1);
  583. }
  584. myPaintTxt(0,saveWM_LButton);
  585. saveWM_LButton=0;
  586. }
  587.             if(st==3)
  588. {
  589. myResM.Chtime.reset();
  590. }
  591. break;
  592.         
  593.         case WM_MOUSEMOVE:
  594. saveWM_LButton=0;
  595. y=lParam/0x10000;
  596. x=lParam%0x10000;
  597. t=y/TextH+1;
  598. saveCurLine=t;
  599. Txx=0;
  600. if(fCanMove==TRUE)
  601. {
  602. QQtimenum=0;
  603. myQQWind->settxt(m_hWnd,x,y,"",0);
  604. GetCursorPos( &pt );//取得光标位置
  605. pt.x=pt.x - Cursordif.x;
  606. pt.y=pt.y - Cursordif.y;
  607. MyWinMove(pt);
  608. myPaintTxt(0,saveWM_LButton);
  609. //使用SetWindowPos作移动时会改变集焦。可用MoveWindow解决。
  610. //在不移动时可以使用它。
  611. }
  612. else
  613. {
  614. st=getRgnFlage(x,y);
  615. if(st==4)
  616. {
  617. myQQWind->settxt(m_hWnd,x,y,"选择图片",1);
  618. //光标的设置
  619. SetCursor(LoadCursor(NULL,MAKEINTRESOURCE(32649)));    //根据选择区域设置光标
  620. }
  621. if(st==3)
  622. {
  623. myQQWind->settxt(m_hWnd,x,y,"重设计数器",1);
  624. //光标的设置
  625. SetCursor(LoadCursor(NULL,MAKEINTRESOURCE(32649)));    //根据选择区域设置光标
  626. }
  627. if(st==2)
  628. {
  629.    myPaintTxt(0,0);
  630.    myQQWind->settxt(m_hWnd,x,y,"隐藏窗口",1);
  631. //光标的设置
  632. SetCursor(LoadCursor(NULL,MAKEINTRESOURCE(32649)));    //根据选择区域设置光标
  633. }
  634. if(st==1)
  635. {
  636. QQtimenum++;
  637. if(QQtimenum>20)
  638. {
  639. if(QQtimenum>60)
  640. {
  641.    QQtimenum=0;
  642.    myQQWind->settxt(m_hWnd,x,y,"",0);
  643. }
  644. else
  645. {
  646. if(QQtimenum>40)
  647. myQQWind->settxt(m_hWnd,x,y,"PageUp/PageDown翻頁",2);
  648. else
  649. myQQWind->settxt(m_hWnd,x,y,"鼠标左键可选择输入",2);
  650. }
  651. }
  652. //光标的设置
  653. myMouseMove(t,saveWM_LButton);    //根据选择区域设置光标
  654. }
  655. }
  656.    //测试鼠标是否移出窗口
  657. if(PtInRegion(WinRGN2,x,y)==0)
  658. {
  659. QQtimenum=0;
  660. myQQWind->settxt(m_hWnd,x,y,"",0);
  661. KillTimer(m_hWnd,1);
  662. myPaintTxt(0,0);
  663. }
  664. if(fCanMove==FALSE)
  665. {   
  666. //SetWindowLong(m_hWnd,4,0);
  667. ReleaseCapture();
  668. }
  669. break;
  670. case WM_DESTROY:
  671. //SendMessage(m_hWnd,WM_CLOSE,0,0);
  672. if(myHwndParent==NULL)
  673. {
  674. //PostQuitMessage(0);
  675. }
  676. else
  677. {
  678. //SetWindowLong(m_hWnd,GWL_WNDPROC,(long)endProc);
  679. if(IsWindow(m_hWnd))
  680. DestroyWindow(m_hWnd);
  681. }
  682. break;
  683.         default:
  684.                 return DefWindowProc(m_hWnd,uMsg,wParam,lParam);
  685.             break;
  686.     }
  687.     return 0;
  688.    
  689.   } catch (...) {
  690.   MessageBox(0,"CMyWnd::WindowProc","有错误发生",0);
  691.   }
  692.    return 1;
  693. }
  694. int CMyWnd::getRgnFlage(long x,long y)
  695. {
  696. int ret=0;
  697. long rgb,r,g,b;
  698. rgb=GetPixel(myResM.oldBackDC,x,y+109);
  699. r=GetRValue(rgb);
  700. g=GetGValue(rgb);
  701. b=GetBValue(rgb);
  702. if(r==255 && g==0 && b==0)
  703. ret=1;
  704. if(r==0 && g==255 && b==0)
  705. ret=2;
  706. if(r==0 && g==0 && b==255)
  707. ret=3;
  708. if(r==0 && g==0 && b==0)
  709. ret=4;
  710.    return ret;
  711. }
  712. //根据选择区域设置光标
  713. CMyWnd::myMouseMove(int linemove,int act)
  714. {
  715. PAINTSTRUCT ps;
  716. SetBkMode(WindDC,TRANSPARENT);
  717. BeginPaint(m_hWnd, &ps);
  718.    SetCursor(LoadCursor(NULL,MAKEINTRESOURCE(32649)));
  719.    myPaintTxt(linemove,act);
  720. EndPaint(m_hWnd, &ps);
  721. }
  722.  
  723. CMyWnd::TimeShowText(int line)
  724. {
  725. HDC hdc;
  726. int t;
  727. int lineposy;
  728. static len;
  729. static SIZE sz;
  730. hdc=Texthdc;
  731. if(saveCurLine<=0)
  732. return 0;
  733. if(page.Chistr[saveCurLine-1][0]==0)
  734. return 0;
  735.  
  736. {
  737. StartPPch=page.Chistr[saveCurLine-1];
  738. TimePPch=StartPPch;
  739. len=strlen(TimePPch);
  740. GetTextExtentExPoint(hdc,TimePPch,len,WinWidth,&t,0,&sz);
  741. }
  742. t=Txx+sz.cx;
  743. if(t<0)
  744. Txx=WinWidth-TextH;
  745. lineposy=resavehight+(saveCurLine-1)*TextH;
  746.     //清除掉文本区
  747. BitBlt(hdc,0,lineposy,WinWidth,TextH,myResM.BackDC,0,lineposy,SRCCOPY);
  748. if(saveWM_LButton==0)
  749. BitBlt(hdc,0,lineposy,WinWidth,TextH,myResM.LinebarDC,0,0,SRCAND);
  750. else
  751. BitBlt(hdc,0,lineposy,WinWidth,TextH,myResM.LinebarDC1,0,0,SRCCOPY);
  752. DeleteObject(SelectObject(hdc, hUIFont));
  753. SetTextColor(hdc,RGB(0,100,0));
  754. if(saveCurLine==1)
  755. TextOut(hdc,Txx,lineposy, TimePPch,len);
  756. else
  757. TextOut(hdc,Txx+20,lineposy, TimePPch,len);
  758. Txx-=1;
  759. return 0;
  760. }
  761. int CMyWnd::myPaintTxt(int linemove ,int act )
  762. {
  763. int line=0;
  764. char shtemss[1500];
  765. PAINTSTRUCT ps;
  766. HDC hdc;
  767.    RECT LoWinRect;
  768. long h,w;
  769. GetWindowRect(m_hWnd,&LoWinRect); 
  770.    w=LoWinRect.right-LoWinRect.left;
  771. h=LoWinRect.bottom-LoWinRect.top;
  772.     //清除掉文本区
  773. hdc=Texthdc;
  774. BitBlt(hdc,0,0,WinWidth,WinHeight,myResM.BackDC,0,0,SRCCOPY);
  775. if(linemove>0 && linemove<6)
  776. {
  777. if(act==0)
  778. BitBlt(hdc,0,resavehight+(linemove-1)*TextH,WinWidth,TextH,myResM.LinebarDC,0,0,SRCAND);
  779. else
  780. BitBlt(hdc,0,resavehight+(linemove-1)*TextH,WinWidth,TextH,myResM.LinebarDC1,0,0,SRCCOPY);
  781. }
  782. for(line=0;line<5&&page.Chistr[line][0]!=0;line++)
  783. {
  784. // MessageBox(0,ss,"dd",0);
  785. if(page.Proprity[line]=='1')
  786. SetTextColor(hdc,RGB(0,0,255));
  787.     if(page.Proprity[line]=='2')
  788. SetTextColor(hdc,RGB(0,0,0));
  789.     if(page.Proprity[line]=='3')
  790. SetTextColor(hdc,RGB(0,100,0));
  791. sprintf(shtemss,"%d:%s%s",line+1,page.Chistr[line],page.Enstr[line]);
  792. if(line==0)
  793. TextOut(hdc,5,resavehight+line*TextH, shtemss,strlen(shtemss));
  794. else
  795. TextOut(hdc,25,resavehight+line*TextH, shtemss,strlen(shtemss));
  796. }
  797. BeginPaint(m_hWnd, &ps);
  798.     WindDC=GetDC(m_hWnd);
  799. BitBlt(WindDC,0,0,WinWidth,WinHeight,hdc,0,0,SRCCOPY);
  800. EndPaint(m_hWnd, &ps);
  801. // if(line<3)
  802. // MoveWindow(m_hWnd,LoWinRect.left,LoWinRect.top,w,ControlHeight+TextH*2,TRUE);
  803. // else
  804. // MoveWindow(m_hWnd,LoWinRect.left,LoWinRect.top,WinWidth,WinHeight,TRUE);
  805. }
  806. //特殊字符处理,
  807. int CMyWnd:: specsif(char *ss)
  808. {
  809. int i,t,t1,t2,len;
  810. //特殊字符处理,以便支持特殊字符了输入
  811. len=strlen(ss);
  812. if(len>=4)
  813. {
  814. t=-1;
  815. for(i=0;i<len;i++)
  816. {
  817. t++;
  818. t1=t2=-1;
  819. if(ss[i]=='0' && (ss[i+1]=='x'||ss[i+1]=='X') && i<len-2 )
  820. {
  821. if(ss[i+2]>='0' && ss[i+2]<='9')
  822. t1=ss[i+2]-'0';
  823. if(ss[i+2]>='a' && ss[i+2]<='f')
  824. t1=ss[i+2]-'a'+10;
  825. if(ss[i+2]>='A' && ss[i+2]<='F')
  826. t1=ss[i+2]-'A'+10;
  827. if(ss[i+3]>='0' && ss[i+3]<='9')
  828. t2=ss[i+3]-'0';
  829. if(ss[i+3]>='a' && ss[i+3]<='f')
  830. t2=ss[i+3]-'a'+10;
  831. if(ss[i+3]>='A' && ss[i+3]<='F')
  832. t2=ss[i+3]-'A'+10;
  833. }
  834. if(t1!=-1 && t2!=-1)
  835. {
  836. //char tem[100];
  837. //sprintf(tem,"%d %d",t1,t2);
  838. t1=t1*16+t2;
  839. ss[t]=t1;
  840. //MessageBox(0,tem,ss,0);
  841. i=i+3;
  842. }
  843. else
  844. ss[t]=ss[i];
  845. }
  846. ss[t+1]=0;
  847. }
  848. return 0;
  849. }
  850. //设置需要显示的字符串
  851. int CMyWnd:: settxt(char *ss)
  852. {
  853. int i,len,line=0;
  854. char *ppc;
  855. if(ss!=NULL)
  856. strcpy(showtxt,ss);
  857. else
  858. showtxt[0]=0;
  859. ppc=showtxt;
  860. len=strlen(ppc);
  861. for(i=0;i<5;i++)
  862. {
  863. page.Enstr[i][0]=0;
  864. page.Chistr[i][0]=0;
  865. page.Proprity[i]=0;
  866. }
  867. for(i=0;i<len;i++)
  868. {
  869. if(showtxt[i]==';')
  870. {
  871. showtxt[i]=0;
  872. strcpy(page.Enstr[line],ppc);
  873. ppc=&showtxt[i+1];
  874. line++;
  875. if(line==5)
  876. break;
  877. }
  878. if(showtxt[i]==' ')
  879. {
  880. showtxt[i]=0;
  881. strcpy(page.Chistr[line],ppc);
  882. //特殊字符处理
  883. specsif(page.Chistr[line]);
  884. page.Proprity[line]=showtxt[i+1];
  885. ppc=&showtxt[i+2];
  886. }
  887. }
  888. return 0;
  889. }
  890. int CMyWnd::MyWinMove(POINT pt)
  891. {
  892. POINT pt1;
  893. pt1=pt;
  894. myResM.WriteRegPos("CMyWnd",pt);
  895. myResM.WriteRegPos("ConHwnd",pt);
  896. pt1.y-=inputWind->ControlHeight;
  897. myResM.WriteRegPos("inputHwnd",pt1);
  898. SetWindowPos(m_hWnd, 0,  pt.x, pt.y,0, 0, 21);
  899. SetWindowPos(ConWind->m_hWnd,  0, pt.x-31, pt.y+15,0, 0, 21);
  900. SetWindowPos(inputWind->m_hWnd,0, pt1.x, pt1.y,0, 0, 21);
  901. return 0;
  902. }
  903. int CMyWnd::RedrawWin()
  904. {
  905. RECT  upwin;
  906. GetWindowRect(m_hWnd,&upwin);
  907. upwin.bottom=upwin.bottom-inputWind->ControlHeight;
  908. RedrawWindow(m_hWnd,0,0,RDW_VALIDATE|RDW_NOCHILDREN|RDW_INVALIDATE|RDW_ERASENOW|RDW_ERASE);//RDW_ERASE
  909. return 0;
  910. }
  911. //链接到目标地址
  912. int CMyWnd::selectback()
  913. {
  914. char gg[512]="";
  915. char filter[100]="图片形文件 (*.*)|*.bmp";
  916. if(browseFile(gg,255, 0,0,filter,NULL))//m_hWnd
  917. {
  918. char dd[512]="";
  919. myfileExtname(gg,dd);
  920. strupr(dd);
  921. if(strcmp(dd,"BMP")==0||strcmp(dd,"JPG")==0){
  922. RegSaveString("backpic",gg);
  923. myResM.loadback();
  924. }else{
  925. MessageBox(0,gg,"文件类型应为bmp或jpg,请重新选择。",0);
  926. }
  927. }
  928. DrawFrame();
  929. myPaintTxt(0,0);
  930.     return 0;
  931. }
  932. //////////////////////////////////////////////////////////////////////////////
  933. //  内部函数
  934. //  需要类CMyWnd支持
  935. int CMyWnd::MyMoveWinInput(HWND hWnd ,long x,long y)
  936. {
  937. RECT LoWinRect,ParentWinRect,screenrc;
  938. long h,w,temy;
  939. static int savy;;
  940. int trace;
  941. //char ss[100];
  942. //sprintf(ss,"%d",cmywnd->m_hWnd);
  943. //MessageBox(0,"Main create",ss,0);
  944. temy=y;
  945. SystemParametersInfo(SPI_GETWORKAREA,0, &screenrc,0);
  946. GetWindowRect(m_hWnd,&LoWinRect); 
  947. if(IsWindow(hWnd))
  948. {
  949. GetWindowRect(hWnd,&ParentWinRect); 
  950. }
  951. else
  952. {
  953. ParentWinRect.right=0;
  954. ParentWinRect.left=0;
  955. ParentWinRect.top=0;
  956. ParentWinRect.bottom=0;
  957. }
  958. w=LoWinRect.right-LoWinRect.left;
  959. h=LoWinRect.bottom-LoWinRect.top;
  960. if((x>10000 && y>10000)||(x<=0 && y<=0))
  961. return 0;
  962. x=x+ParentWinRect.left;
  963. y=y+ParentWinRect.top+inputWind->ControlHeight;
  964. //如果座标远离窗口时才移动。
  965. trace=(int)(myResM.traceflage[0]-'0');
  966. if(trace<9)
  967. {
  968. int t,con;
  969. trace=trace*20;
  970. t=LoWinRect.left-x;
  971. if(t> trace || t<-trace|| savy!=temy )
  972. {
  973. savy=temy;
  974. con=inputWind->ControlHeight;
  975. if(x<screenrc.left )
  976. x=screenrc.left;
  977. if( x>screenrc.right-w)
  978. x=screenrc.right-w;
  979. if( y<screenrc.top )
  980. y=screenrc.top;
  981. if(y>screenrc.bottom-h-con )
  982. {
  983. //y=screenrc.bottom-h;
  984. y=y-con-h-40;
  985. MoveWindow(m_hWnd,x,y,w,h,TRUE);
  986. y=y+h;
  987. x=x+20;
  988. MoveWindow(inputWind->m_hWnd,x,y,w,con,TRUE);
  989. }
  990. else
  991. {
  992. y=y+10;
  993. MoveWindow(inputWind->m_hWnd,x,y,w,con,TRUE);
  994. y=y+con;
  995. MoveWindow(m_hWnd,x,y,w,h,TRUE);
  996. }
  997. // SetWindowPos(ConWind->m_hWnd, 0, x,y,0, 0, 21); //SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER  //16/1/4
  998. }
  999. }
  1000. return 0;
  1001. }