inputHwnd.cpp
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:6k
- #include "stdafx.h"
- #include "stdio.h"
- #include "inputHwnd.h"
- #include "windows.h"
- #include "CMyWnd.h"
- BOOL MyIsWinNT() ;
- inputHwnd::inputHwnd()
- {
- POINT pp[100];
- showtxt[0]=0;
- fCanMove=0;
- WinStartPos=myResM.ReadRegPos("inputHwnd");
- WinHeight=myResM.WinHeight;
- WinWidth=myResM.WinWidth;
- ControlHeight=myResM.ControlHeight;
- pp[0].x=0; pp[0].y=ControlHeight;
- pp[1].x=94; pp[1].y=ControlHeight;
- 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(20, 0, 0, 0, FW_NORMAL,
- FALSE, FALSE, FALSE, ANSI_CHARSET,
- OUT_TT_PRECIS, CLIP_TT_ALWAYS, ANTIALIASED_QUALITY,
- DEFAULT_PITCH, "宋体");
- }
- inputHwnd::~inputHwnd()
- {
- SetWindowLong(m_hWnd,GWL_WNDPROC,(long)endProc);
- DestroyWindow(m_hWnd);
-
- // MessageBox(0,"~inputHwnd",0,0);
- m_hWnd=NULL;
- DeleteObject(hUIFont);
- DeleteObject (WinRGN1);
- //如果不消毁窗口当主程序,退出时窗口依然在运行,会引起系统崩溃
- }
-
- 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),200,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_LBUTTONDOWN:
- fCanMove = TRUE;
- break;
- case WM_LBUTTONUP:
- if( fCanMove)
- {
- GetCursorPos( &pt );
- myResM.WriteRegPos("inputHwnd",pt);
- MoveWindow(m_hWnd,pt.x - Cursordif.x,pt.y - Cursordif.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
- {
- SetWindowLong(m_hWnd,GWL_WNDPROC,(long)endProc);
- DestroyWindow(m_hWnd);
- }
- break;
- default:
- return DefWindowProc(m_hWnd,uMsg,wParam,lParam);
- break;
- }
- } catch (...) {
- if(IsWindow(m_hWnd))
- {
- ShowWindow(m_hWnd,SW_SHOW);
- // MessageBox(0,"inputError","IsWindow",0);
- }
- // 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);
- // DestroyWindow(*Cont_hWnd);
- // MessageBox(0,"inputError","有错误发生",0);
- }
- return 0;
- }
- //窗口的初始化
- inputHwnd::initalizeWin()
- {
- WindDC=GetDC(m_hWnd);
- Texthdc = CreateCompatibleDC(WindDC);
- Texthdcbmp=CreateCompatibleBitmap(WindDC,WinWidth,ControlHeight);
- SelectObject(Texthdc, hUIFont);
- DeleteObject(SelectObject(Texthdc,Texthdcbmp));
- SetBkMode(Texthdc,TRANSPARENT);
- SelectObject(WindDC, hUIFont);
- TextH=GetTabbedTextExtent(WindDC,"1",1,0,0)/0x10000;
- //
- if(!MyIsWinNT())
- SetWindowRgn(m_hWnd,WinRGN1,TRUE);
- BackhBmp=(HBITMAP)LoadBitmap(hInst,MAKEINTRESOURCE(IDB_Back));
- BackDC = CreateCompatibleDC(WindDC);
- DeleteObject(SelectObject(BackDC,BackhBmp));
- }
- int inputHwnd::myPaintTxt(int flag,int act )
- {
- PAINTSTRUCT ps;
- HDC hdc;
- //清除掉文本区
- hdc=Texthdc;
- BitBlt(hdc,0,0,WinWidth,WinHeight,BackDC,0,WinHeight-ControlHeight,SRCCOPY);
- TextOut(hdc,5,0, showtxt,strlen(showtxt));
- /*
- HRGN Rgn1, Rgn2;
- Rgn1 = CreateRectRgn(0, 0, 100, 300);
- BeginPath(WindDC);
- TextOut(hdc,5,0, showtxt,strlen(showtxt));
- EndPath(WindDC);
- Rgn2 = PathToRegion(WindDC);
-
- CombineRgn(Rgn1, Rgn2, WinRGN1, 2);
- SetWindowRgn(WindDC, hRgn, TRUE);
- DeleteObject(hRgn);
- */
- BeginPaint(m_hWnd, &ps);
- BitBlt(WindDC,0,0,WinWidth,WinHeight,hdc,0,0,SRCCOPY);
- 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;
- }
- //判断系统是否NT
- BOOL MyIsWinNT()
- {
- OSVERSIONINFO osvi;
- osvi.dwOSVersionInfoSize = 148;
- GetVersionEx(&osvi);
- if(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
- return 1;
- else
- return 0;
- }