CMyWnd.cpp
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:12k
- #include "stdafx.h"
- #include "stdio.h"
- #include "CMyWnd.h"
- #include "windows.h"
- #include "GIF.h"
- #include "math.h"
- CGIF m_Gif;
- POINT pst;
- int tt;
- CMyWnd::~CMyWnd()
- {
- //strcpy(showtxt,"");
- delete inputWind;
- delete ConWind;
- //让程序暂时进行处理,以防止无效访问已经退出的代码段
- //SetWindowLong(m_hWnd,GWL_WNDPROC,(long)endProc);
- //DestroyWindow(m_hWnd);
- m_hWnd=NULL;
- }
- CMyWnd::CMyWnd()
- {
- int i;
- inputWind=new inputHwnd;
- ConWind=new ConHwnd;
- inputWind->Main_CWnd=(void*)this;
- ConWind->Main_CWnd=(void*)this;
- x=y=50;
- for(i=0;i<50;i++)
- Arrppc[i] =NULL;
- TimePPch=NULL;
- StartPPch=NULL;
- WinStartPos=myResM.ReadRegPos("CMyWnd");
- strcpy(inputWind->showtxt,"");
- settxt("名称:极速五笔 1.;版权:王华 1.;发行:2006.12.28 1.;E-m:whln669@sohu.com 1.;版本:2.10 1.;");
- m_hWnd=NULL;
- WinHeight=myResM.WinHeight;
- WinWidth=myResM.WinWidth;
- ControlHeight=myResM.ControlHeight;
- fCanMove = FALSE;
- saveWM_LButton=0;
- saveCurLine=0;
-
- }
- BOOL CMyWnd::Create(LPCTSTR szClassName, LPCTSTR szTitle, HINSTANCE hInstance, HWND hWndParent , DWORD dwStyle ,DWORD dwExStyle, HMENU hMenu )
- {
- // 初始化全局字串
- WNDCLASSEX wcex;
- //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);
- ShowWindow(m_hWnd,SW_SHOWNOACTIVATE);
- UpdateWindow(m_hWnd);
- }
- // MessageBox(0,"Main create",0,0);
- myHwndParent=hWndParent;
-
- 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;
-
- return m_hWnd != NULL;
- }
- CMyWnd::TimeShowText(int line)
- {
- HDC hdc;
- int t;
- int lineposy;
- static len;
- static SIZE sz;
- hdc=myResM.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=(saveCurLine-1)*TextH;
- //清除掉文本区
- BitBlt(hdc,0,lineposy-ControlHeight+TextH,myResM.WinWidth,TextH+5,myResM.BackDC,0,lineposy-ControlHeight+TextH,SRCCOPY);
- if(saveWM_LButton==0)
- BitBlt(hdc,0,lineposy,myResM.WinWidth,TextH,myResM.LinebarDC,0,0,SRCAND);
- else
- BitBlt(hdc,0,lineposy,myResM.WinWidth,TextH,myResM.LinebarDC1,0,0,SRCCOPY);
-
- SelectObject(hdc, myResM.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;
- }
- LRESULT WINAPI CMyWnd::WindowProc(UINT uMsg,UINT wParam,LONG lParam)
- {
- POINT pt;
- RECT Rect;
- COLORREF tColor;
- int t;
- static dely;
- char gifname[256];
- 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),200,LWA_ALPHA|LWA_COLORKEY);
- GetModuleFileName(hInst,gifname,255);
- myGetPath(gifname); //取路径 动画
- strcat(gifname,"1.gif");
- if(m_Gif.LoadGIF(gifname))
- ;//MessageBox(0,"map","m_Gif.LoadGIF",0);
- else
- SetTimer(m_hWnd,2,100,NULL);
- break;
- case WM_TIMER:
- 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,ControlHeight,myResM.WinWidth, myResM.WinHeight,myResM.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)
- {
- TimeShowText(0);
- if (!m_Gif.GetImageInfo (Rect,tColor,tt-1))
- BitBlt (WindDC,0,ControlHeight,myResM.WinWidth, myResM.WinHeight,myResM.Texthdc,0,0,SRCCOPY);
- }
- break;
- case WM_PAINT://绘制窗口
- myPaintTxt(0,saveWM_LButton);
- break;
- case WM_SETCURSOR:
- if ((HIWORD(lParam) == WM_MOUSEMOVE))
- {
- 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:
- myResM.FixBackPic();
- break;
- case WM_LBUTTONDOWN:
- y=lParam/0x10000;
- x=lParam%0x10000;
- t=(y-ControlHeight)/TextH+1;
- saveWM_LButton=1;
- GetCursorPos( &pt );
- GetWindowRect(m_hWnd,&WinRect);
- Cursordif.x = pt.x - WinRect.left;//得到相对位置
- Cursordif.y = pt.y - WinRect.top;
- myPaintTxt(t,saveWM_LButton);
- fCanMove=1;
- break;
- case WM_LBUTTONUP:
- y=lParam/0x10000;
- x=lParam%0x10000;
- t=(y-ControlHeight)/TextH;
- saveCurLine=t+1;
- if( fCanMove)
- {
- GetCursorPos( &pt );
- pt.x=pt.x - Cursordif.x;
- pt.y=pt.y - Cursordif.y;
- MyWinMove(pt);
- fCanMove = FALSE;
- }
- if(saveWM_LButton==1&&inputWind->showtxt[0]!=0)
- {
- keybd_event(49 + t, 0, 0, 1);
- }
- myPaintTxt(0,saveWM_LButton);
- saveWM_LButton=0;
-
- break;
-
- case WM_MOUSEMOVE:
- saveWM_LButton=0;
- y=lParam/0x10000;
- x=lParam%0x10000;
- t=(y-ControlHeight)/TextH+1;
- saveCurLine=t;
- Txx=0;
- if(fCanMove==TRUE)
- {
- GetCursorPos( &pt );//取得光标位置
- pt.x=pt.x - Cursordif.x;
- pt.y=pt.y - Cursordif.y;
- MyWinMove(pt);
- myPaintTxt(0,saveWM_LButton);
- //使用SetWindowPos作移动时会改变集焦。可用MoveWindow解决。
- //在不移动时可以使用它。
- }
- else
- {
- //光标的设置
- myMouseMove(t,saveWM_LButton); //根据选择区域设置光标
- }
- //测试鼠标是否移出窗口
- if(PtInRegion(myResM.WinRGN2,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);
- DestroyWindow(m_hWnd);
- }
- break;
- default:
- return DefWindowProc(m_hWnd,uMsg,wParam,lParam);
- break;
- }
- return 0;
-
- } catch (...) {
- // delete (CMyWnd*)Main_CWnd;
- // SetWindowLong(*Main_hWnd,GWL_WNDPROC,(long)endProc);
- // DestroyWindow(*Main_hWnd);
- // SetWindowLong(*inpu_hWnd,GWL_WNDPROC,(long)endProc);
- // DestroyWindow(*inpu_hWnd);
- // SetWindowLong(*Cont_hWnd,GWL_WNDPROC,(long)endProc);
- // SetLastError(0);
- //MessageBox(0,"mainError","有错误发生",0);
- }
- return 1;
- }
- //根据选择区域设置光标
- 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::initalizeWin()
- {
- WindDC=GetDC(m_hWnd);
- SelectObject(WindDC, myResM.hUIFont);
- TextH=GetTabbedTextExtent(WindDC,"1",1,0,0)/0x10000;
- myResM.InitResManager(WindDC,hInst);
- SetWindowRgn(m_hWnd,myResM.WinRGN1,TRUE);
- }
-
- 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=myResM.Texthdc;
- BitBlt(hdc,0,0,myResM.WinWidth,myResM.WinHeight,myResM.BackDC,0,0,SRCCOPY);
- if(linemove>0 && linemove<6)
- {
- if(act==0)
- BitBlt(hdc,0,(linemove-1)*TextH,myResM.WinWidth,TextH,myResM.LinebarDC,0,0,SRCAND);
- else
- BitBlt(hdc,0,(linemove-1)*TextH,myResM.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,line*TextH, shtemss,strlen(shtemss));
- else
- TextOut(hdc,25,line*TextH, shtemss,strlen(shtemss));
- }
- BeginPaint(m_hWnd, &ps);
- BitBlt(WindDC,0,ControlHeight,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)
- {
- myResM.WriteRegPos("CMyWnd",pt);
- myResM.WriteRegPos("ConHwnd",pt);
- myResM.WriteRegPos("inputHwnd",pt);
- SetWindowPos(m_hWnd, 0, pt.x, pt.y,0, 0, 21);
- SetWindowPos(ConWind->m_hWnd, 0, pt.x, pt.y,0, 0, 21);
- SetWindowPos(inputWind->m_hWnd,0, pt.x, pt.y,0, 0, 21);
- return 0;
- }
- int CMyWnd::RedrawWin()
- {
- RECT upwin;
- GetWindowRect(m_hWnd,&upwin);
- upwin.bottom=upwin.bottom-ControlHeight;
- RedrawWindow(m_hWnd,0,0,RDW_VALIDATE|RDW_NOCHILDREN|RDW_INVALIDATE|RDW_ERASENOW|RDW_ERASE);//RDW_ERASE
- return 0;
- }
- int CMyWnd::myGetPath(char *filefullname)
- {
- int i,lon;
- lon=strlen(filefullname);
- for(i=lon;i>0;i--)
- if(filefullname[i]=='\')
- {
- filefullname[i+1]=0;
- break;
- }
- return 0;
- }