QQHwnd.cpp
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:9k
- #include "stdafx.h"
- #include "stdio.h"
- #include "QQHwnd.h"
- #include "windows.h"
- #include "CMyWnd.h"
- QQHwnd::QQHwnd(void*CMthis)
- {
- POINT pp[100];
- Main_CWnd=(CMyWnd*)CMthis;
- strcpy(showtxt,"");
- fCanMove=0;
- dailtimershow=0;
- WinWidth=200;
- WinHeight=20;
- pp[0].x=0; pp[0].y=20;
- pp[1].x=170; pp[1].y=20;
- pp[2].x=170; pp[2].y=0;
- pp[3].x=0; pp[3].y=0;
- WinRGN1=CreatePolygonRgn(pp,4,1);
- WinRGN2=CreatePolygonRgn(pp,4,1);
-
- if(ValIsWinNT==1)
- {
- hUIFont = CreateFont(12, 0, 0, 0, FW_NORMAL,
- FALSE, FALSE, FALSE, ANSI_CHARSET,
- OUT_TT_PRECIS, CLIP_TT_ALWAYS, ANTIALIASED_QUALITY,
- DEFAULT_PITCH, "宋体");
- }
- else
- {
- hUIFont = CreateFont(16, 0, 0, 0, FW_NORMAL,
- FALSE, FALSE, FALSE, ANSI_CHARSET,
- OUT_TT_PRECIS, CLIP_TT_ALWAYS, ANTIALIASED_QUALITY,
- DEFAULT_PITCH, "宋体");
- }
- }
- QQHwnd::~QQHwnd()
- {
- try{
-
- // MessageBox(0,"~inputHwnd",0,0);
- DeleteObject(hUIFont);
- DeleteObject (WinRGN1);
- DeleteObject (WinRGN2);
- //可能在窗口处理程序中本窗口已被删除。
- //让程序暂时进行处理,以防止无效访问已经退出的代码段
- 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 QQHwnd::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
- 0,0,WinWidth,WinHeight,
- hWndParent,NULL,hInstance,this);
- ShowWindow(m_hWnd,SW_HIDE);
- //UpdateWindow(m_hWnd);
- }
- myHwndParent=hWndParent;
- return m_hWnd != NULL;
- }
- LRESULT WINAPI QQHwnd::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))
- {
- ShowWindow(m_hWnd, SW_HIDE);//收到鼠标立即隐藏
- 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 );
- pt.x=pt.x - Cursordif.x;
- pt.y=pt.y - Cursordif.y;
- 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,"QQHwnd","IsWindow",0);
- }
- return 0;
- }
- //窗口的初始化
- QQHwnd::initalizeWin()
- {
- WindDC=GetDC(m_hWnd);
- DeleteObject(SelectObject(WindDC, hUIFont));
- SetBkMode(WindDC,TRANSPARENT);
- //
- if(!MyIsWinNT())
- SetWindowRgn(m_hWnd,WinRGN1,TRUE);
- }
- int QQHwnd::myPaintTxt(int flag,int act )
- {
- PAINTSTRUCT ps;
- //清除掉文本区
- BeginPaint(m_hWnd, &ps);
- if(ValIsWinNT==1)
- {
- BitBlt(WindDC,0,0,WinWidth,WinHeight ,((CMyWnd*)Main_CWnd)->myResM.oldBackDC,10, 0,SRCCOPY);
- TextOut(WindDC,2,2, showtxt,strlen(showtxt));
- }
- else
- {
- WindDC=GetDC(m_hWnd);
- SetBkMode(WindDC,TRANSPARENT);
- DeleteObject(SelectObject(WindDC, hUIFont));
- BitBlt(WindDC,0,0,WinWidth,WinHeight ,((CMyWnd*)Main_CWnd)->myResM.oldBackDC,10, 0,SRCCOPY);
- TextOut(WindDC,2,2, showtxt,strlen(showtxt));
- ReleaseDC(m_hWnd,WindDC);
- }
- EndPaint(m_hWnd, &ps);
- }
- //设置需要显示的字符串
- // flage 1234上下左右
- int QQHwnd:: settxt(HWND phwnd,long x,long y,char *ss,int flage)
- {
- int len,line=0,t;
- char *ppc;
- long h,w;
- static int timenum=0;
- SIZE sz;
- RECT FullWinRect,phwndWinRect,CurWinRect;
- GetWindowRect(GetDesktopWindow(),&FullWinRect);
- GetWindowRect(phwnd,&phwndWinRect);
- GetWindowRect(m_hWnd,&CurWinRect);
- dailtimershow=5;
- //MessageBox(0,"inputError","IsWindow",0);
- if(ss!=NULL)
- strcpy(showtxt,ss);
- else
- {
- timenum=0;
- ShowWindow(m_hWnd, SW_HIDE);
- showtxt[0]=0;
- }
- if(showtxt[0]==0)
- {
- timenum=0;
- ShowWindow(m_hWnd, SW_HIDE);
- }
- else
- {
- if(timenum<5)
- {
- timenum++;
- return 0;
- }
- else
- {
- ppc=showtxt;
- len=strlen(ppc);
- if(ValIsWinNT==1)
- {
- GetTextExtentExPoint(WindDC,showtxt,len,100,&t,0,&sz);
- }
- else
- {
- WindDC=GetDC(m_hWnd);
- DeleteObject(SelectObject(WindDC, hUIFont));
- GetTextExtentExPoint(WindDC,showtxt,len,100,&t,0,&sz);
- ReleaseDC(m_hWnd,WindDC);
- }
- w=sz.cx+4;
- h=sz.cy+4;
- switch(flage)
- {
- case 1:
- y=y+phwndWinRect.top-20;
- x=x+phwndWinRect.left;
- break;
- case 2:
- y=y+phwndWinRect.top+20;
- x=x+phwndWinRect.left;
- break;
- case 3:
- y=y+phwndWinRect.top;
- x=x+phwndWinRect.left-(CurWinRect.right-CurWinRect.left)-20;
- break;
- case 4:
- y=y+phwndWinRect.top;
- x=x+phwndWinRect.left+20;
- break;
- default:
- break;
- }
- // InvalidateRect(m_hWnd,NULL,FALSE);
- MoveWindow(m_hWnd,x,y,w,h,TRUE);
- myPaintTxt(0,0 );
- ShowWindow(m_hWnd, SW_SHOWNOACTIVATE);
- }
- }
- return 0;
- }
- int QQHwnd:: disabledailtimer()
- {
- if(dailtimershow>0)
- dailtimershow--;
- return dailtimershow;
- }
- int QQHwnd:: settxttimer(HWND phwnd,long x,long y,char *ss)
- {
- int len,line=0,t;
- char *ppc;
- long h,w;
- SIZE sz;
- if(dailtimershow==0)
- {
- RECT FullWinRect,phwndWinRect,CurWinRect;
- GetWindowRect(GetDesktopWindow(),&FullWinRect);
- GetWindowRect(phwnd,&phwndWinRect);
- GetWindowRect(m_hWnd,&CurWinRect);
- //MessageBox(0,"inputError","IsWindow",0);
- if(ss!=NULL)
- strcpy(showtxt,ss);
- else
- {
- ShowWindow(m_hWnd, SW_HIDE);
- showtxt[0]=0;
- }
- if(showtxt[0]==0)
- {
- ShowWindow(m_hWnd, SW_HIDE);
- }
- else
- {
- ppc=showtxt;
- len=strlen(ppc);
- if(ValIsWinNT==1)
- {
- GetTextExtentExPoint(WindDC,showtxt,len,100,&t,0,&sz);
- }
- else
- {
- WindDC=GetDC(m_hWnd);
- DeleteObject(SelectObject(WindDC, hUIFont));
- GetTextExtentExPoint(WindDC,showtxt,len,100,&t,0,&sz);
- ReleaseDC(m_hWnd,WindDC);
- }
- w=sz.cx+4;
- h=sz.cy+4;
- y=y+phwndWinRect.top-h;
- x=x+phwndWinRect.left;
- MoveWindow(m_hWnd,x,y,w,h,TRUE);
- myPaintTxt(0,0 );
- ShowWindow(m_hWnd, SW_SHOWNOACTIVATE);
- }
- }
- return 0;
- }
- //设置需要显示的字符串
- int QQHwnd:: settxt(char *ss)
- {
- int len,line=0,t;
- char *ppc;
- long h,w;
- SIZE sz;
- RECT CurWinRect;
- GetWindowRect(m_hWnd,&CurWinRect);
- //MessageBox(0,"inputError","IsWindow",0);
- if(ss!=NULL)
- strcpy(showtxt,ss);
- else
- {
- ShowWindow(m_hWnd, SW_HIDE);
- showtxt[0]=0;
- }
- if(showtxt[0]==0)
- {
- ShowWindow(m_hWnd, SW_HIDE);
- }
- else
- {
- ppc=showtxt;
- len=strlen(ppc);
- if(ValIsWinNT==1)
- {
- GetTextExtentExPoint(WindDC,showtxt,len,100,&t,0,&sz);
- }
- else
- {
- WindDC=GetDC(m_hWnd);
- DeleteObject(SelectObject(WindDC, hUIFont));
- GetTextExtentExPoint(WindDC,showtxt,len,100,&t,0,&sz);
- ReleaseDC(m_hWnd,WindDC);
- }
- w=sz.cx+4;
- h=sz.cy+4;
- MoveWindow(m_hWnd,CurWinRect.left,CurWinRect.top,w,h,TRUE);
- myPaintTxt(0,0);
- }
- return 0;
- }
- int QQHwnd::RedrawWin()
- {
- RedrawWindow(m_hWnd,0,0,RDW_VALIDATE|RDW_NOCHILDREN|RDW_INVALIDATE|RDW_ERASENOW|RDW_ERASE);//RDW_ERASE
- return 0;
- }
- //判断系统是否NT