inputHwnd.cpp
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:9k
- #include "stdafx.h"
- #include "stdio.h"
- #include "inputHwnd.h"
- #include "windows.h"
- #include "ResManager.h"
- #include "math.h"
- #include "CMyWnd.h"
- BOOL MyIsWinNT() ;
- inputHwnd::inputHwnd(void*CMthis)
- {
- POINT pp[100];
- Main_CWnd=(CMyWnd*)CMthis;
- myResM=&((CMyWnd*)Main_CWnd)->myResM;
- showtxt[0]=0;
- Saveshowtxt[0]=1;
- fCanMove=0;
- if(myResM->textflage[0]=='1')
- ControlHeight=35;
- else
- ControlHeight=24;
- WinHeight=100;
- WinWidth=170;
- WinStartPos=ReadRegPos("inputHwnd");
- pp[0].x=0; pp[0].y=35;
- pp[1].x=95; pp[1].y=35;
- pp[2].x=70; pp[2].y=0;
- pp[3].x=0; pp[3].y=0;
- WinRGN1=CreatePolygonRgn(pp,4,1);
- WinRGN2=CreatePolygonRgn(pp,4,1);
- hUIFont = CreateFont(25, 0, 0, 0, FW_NORMAL,
- FALSE, FALSE, FALSE, ANSI_CHARSET,
- OUT_TT_PRECIS, CLIP_TT_ALWAYS, ANTIALIASED_QUALITY,
- DEFAULT_PITCH, "宋体");//"Times New Roman"
- }
- inputHwnd::~inputHwnd()
- {
- try{
- DeleteObject(hUIFont);
- DeleteObject (WinRGN1);
- DeleteObject (WinRGN2);
- DeleteDC (BackDC);
- DeleteObject(BackhBmp);
- DeleteDC (Texthdc);
- DeleteObject(Texthdcbmp);
- //可能在窗口处理程序中本窗口已被删除。
- //让程序暂时进行处理,以防止无效访问已经退出的代码段
- if(IsWindow(m_hWnd)){
- ReleaseDC(m_hWnd,WindDC);
- //SetWindowLong(m_hWnd,GWL_WNDPROC,(long)endProc);
- DestroyWindow(m_hWnd);
- //m_hWnd=NULL;
- }
- } catch (...) {
- MessageBox(0,"~inputHwnd","有错误发生",0);
- }
- //如果不消毁窗口当主程序,退出时窗口依然在运行,会引起系统崩溃
- }
-
- BOOL inputHwnd::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,ControlHeight,
- hWndParent,NULL,hInstance,this);
- ShowWindow(m_hWnd,SW_SHOWNOACTIVATE);
- UpdateWindow(m_hWnd);
- //使白色透明掉
- }
- return m_hWnd != NULL;
- }
- LRESULT WINAPI inputHwnd::WindowProc(UINT uMsg,UINT wParam,LONG lParam)
- {
- POINT pt;
- long x,y;
- static int tt;
- 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,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(32649)));
- }
- else
- return DefWindowProc(m_hWnd,uMsg,wParam,lParam);
- break;
- case WM_RBUTTONUP:
- Popup();
- break;
- case WM_LBUTTONDOWN:
- fCanMove = TRUE;
- break;
- case WM_LBUTTONUP:
- if( fCanMove)
- {
- GetCursorPos( &pt );
- pt.x=pt.x - Cursordif.x;
- pt.y=pt.y - Cursordif.y;
- myResM->WriteRegPos("inputHwnd",pt);
- MoveWindow(m_hWnd,pt.x ,pt.y ,WinSIZE.cx,WinSIZE.cy,TRUE);
- fCanMove = FALSE;
- }
- myPaintTxt(0,0);
- break;
-
- case WM_MOUSEMOVE:
- GetCursorPos( &pt );//取得光标位置
- y=lParam/0x10000;
- x=lParam%0x10000;
- if(fCanMove==TRUE)
- {
- MoveWindow(m_hWnd,pt.x - Cursordif.x, pt.y - Cursordif.y, WinSIZE.cx,WinSIZE.cy,TRUE);
- myPaintTxt(0,0);
- //使用SetWindowPos作移动时会改变集焦。可用MoveWindow解决。
- //在不移动时可以使用它。
- }
- //测试鼠标是否移出窗口
- if(PtInRegion(WinRGN2,x,y)==0)
- {
- 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
- {
- if(IsWindow(m_hWnd))
- //SetWindowLong(m_hWnd,GWL_WNDPROC,(long)endProc);
- DestroyWindow(m_hWnd);
- }
- break;
- default:
- return DefWindowProc(m_hWnd,uMsg,wParam,lParam);
- break;
- }
- } catch (...) {
- // MessageBox(0,"inputError","有错误发生",0);
- }
- return 0;
- }
- //窗口的初始化
- inputHwnd::initalizeWin()
- {
- WindDC=GetDC(m_hWnd);
- Texthdc = CreateCompatibleDC(WindDC);
- Texthdcbmp=CreateCompatibleBitmap(WindDC,WinWidth,WinHeight);
- DeleteObject(SelectObject(Texthdc, hUIFont));
- DeleteObject(SelectObject(Texthdc,Texthdcbmp));
- SetBkMode(Texthdc,TRANSPARENT);
- DeleteObject(SelectObject(WindDC, hUIFont));
- TextH=GetTabbedTextExtent(WindDC,"1",1,0,0)/0x10000;
- //
- if(!MyIsWinNT()) //不是NT就进行区域设定
- SetWindowRgn(m_hWnd,WinRGN1,TRUE);
- BackhBmp=(HBITMAP)LoadBitmap(hInst,MAKEINTRESOURCE(IDB_input));
- BackDC = CreateCompatibleDC(WindDC);
- DeleteObject(SelectObject(BackDC,BackhBmp));
- txtpic.StartHDC(WindDC,100,80);
- if(txtpic.loadPic(hInst,IDB_txt)==NULL)
- MessageBox(0,txtpic.Picname,"图片不能装入",0);
- }
- int inputHwnd::myPaintTxt(int flag,int act )
- {
- PAINTSTRUCT ps;
- HDC hdc;
- //清除掉文本区
- hdc=Texthdc;
- if(strcmp(showtxt,Saveshowtxt)!=0)
- {
- if(myResM->textflage[0]!='1')
- {
- BitBlt(hdc,0,0,WinWidth,WinHeight,BackDC,0,0,SRCCOPY);
- TextOut(hdc,5,0, showtxt,strlen(showtxt));
- }
- else
- {
- OutTextPic(showtxt,0,0,hdc,txtpic.hdc,10,20,30,1,myResM->reBackDC);
- }
- strcmp(Saveshowtxt,showtxt);
- }
- BeginPaint(m_hWnd, &ps);
- WindDC=GetDC(m_hWnd);
- BitBlt(WindDC,0,0,WinWidth,WinHeight,hdc,0,0,SRCCOPY);
- ReleaseDC(m_hWnd,WindDC);
- EndPaint(m_hWnd, &ps);
- }
- int inputHwnd::RedrawWin()
- {
- RedrawWindow(m_hWnd,0,0,RDW_VALIDATE|RDW_NOCHILDREN|RDW_INVALIDATE|RDW_ERASENOW|RDW_ERASE);//RDW_ERASE
- return 0;
- }
- int inputHwnd::OutTextPic(char *ss,long x,long y,HDC hDC1,HDC hDC2, long dw , long dh,double a, double zoom,HDC backhdc)
- {
- int i,index;
- static myHDC tt,temtt,pp;
- static int flage=0;
- char temss[100];
- long r,outdw;
- strcpy(temss,ss);
- r=(long)sqrt(dw*dw+dh*dh);
- outdw=dw*2*strlen(temss)+r*2;
- {
- HBRUSH hBrush;
- HRGN hRgn;
- hBrush=(HBRUSH)GetStockObject(WHITE_BRUSH);
- hRgn=CreateRectRgn(0,0,1000,1000);
- FillRgn(hDC1,hRgn, hBrush);
- FillRgn(temtt.hdc ,hRgn, hBrush);
- DeleteObject (hRgn);
- }
- BitBlt(hDC1,0,0,110,ControlHeight,backhdc,0,0,SRCCOPY);
- if(flage==0)
- {
- tt.StartHDC(hDC2,800,800);
- temtt.StartHDC(hDC1,800,800);
- pp.StartHDC(hDC1,800,800);
-
- flage=1;
- }
- strupr(temss);
- for(i=0;i<(int)strlen(temss);i++)
- {
- index=temss[i]-65;
- OutPicture(r,r,tt.hdc,dw*2*index,0,hDC2,dw,dh,a);
- TransparentBlt2(temtt.hdc,dw*2*i,0,dw*2+r,r*2,tt.hdc,0,0,dw*2+r,r*2,RGB(255,255,255));
- //BitBlt(temtt.hdc,dw*2*i,0,dw*2+r,r*2,tt.hdc,0,0,SRCAND);//
- }
- BitBlt(pp.hdc,x,y,outdw,r*2,backhdc,x,y,SRCCOPY);
- TransparentBlt2(pp.hdc,0,0,(int)(outdw*zoom),(int)(r*2*zoom),temtt.hdc,0,0,outdw,r*2,RGB(255,255,255));
- BitBlt(hDC1,x,y,(int)((outdw-r)*zoom),(int)(r*2*zoom),pp.hdc,0,0,SRCCOPY);
- return 0;
- }
- //返回所选菜单项
- long inputHwnd::Popup()
- {
- long iMenu, nMenus,result;//retabout;
- POINT p ;
- char buffer [256]="";
- long flag=0;
- HMENU hMenu;
- int CurentKbdNum=0;
- char MenuName[20][256]={"特效文本","特效显示","旋转角度","自动旋转","背景设置"};
- GetCursorPos(&p);
- hMenu = CreatePopupMenu();
- nMenus = 5;
- for(iMenu = 1 ;iMenu<=nMenus;iMenu++)
- {
- switch (iMenu)
- {
- case 1:
- if(myResM->textflage[0]=='1')
- flag=MF_ENABLED|MF_CHECKED;
- else
- flag=MF_ENABLED;
- break;
- default:
- flag=MF_GRAYED|MF_DISABLED;;
- break;
- }
- AppendMenu (hMenu, flag, iMenu, MenuName[iMenu-1]);
- }
- iMenu = TrackPopupMenu(hMenu, TPM_RIGHTBUTTON + TPM_LEFTALIGN + TPM_NONOTIFY + TPM_RETURNCMD, p.x, p.y, 0, GetForegroundWindow(), 0);
- //得到菜单的选择字符串
- result = GetMenuString(hMenu, (iMenu - 1), buffer, strlen(buffer), MF_BYPOSITION);
-
- DestroyMenu(hMenu);
- if(iMenu>0)
- {
- switch (iMenu)
- {
- case 1:
- {
- RECT Rect;
- GetWindowRect(m_hWnd,&Rect);
- if(myResM->textflage[0]=='1')
- {
- ControlHeight=24;
- RegSaveString("textflage","0");
- myResM->textflage[0]='0';
- MoveWindow(m_hWnd,Rect.left,Rect.top,WinWidth,ControlHeight,TRUE);
- }
- else
- {
- ControlHeight=35;
- RegSaveString("textflage","1");
- myResM->textflage[0]='1';
- MoveWindow(m_hWnd,Rect.left,Rect.top,WinWidth,ControlHeight,TRUE);
- }
- }
- break;
- default:
- MessageBox(0,"过两天补上","功能暂时未编码",0);
- break;
- }
- }
- return 0;
- }