Track.cpp
资源名称:CQQFind.rar [点击查看]
上传用户:cxh888fhc
上传日期:2017-07-08
资源大小:240k
文件大小:3k
源码类别:
钩子与API截获
开发平台:
Visual C++
- #include <windows.h>
- #define DLL_EXPORT extern "C" __declspec(dllexport)
- HINSTANCE g_hinstDll=NULL;
- HHOOK g_hHook=NULL;
- DWORD MOVEMSG=RegisterWindowMessage("MOVEMSG");
- #pragma data_seg(".sdata")
- HWND g_hWnd=NULL;
- #pragma data_seg()
- #pragma comment(linker,"-section:.sdata,rws")
- DLL_EXPORT HHOOK SetFocusHook(HWND hWnd,DWORD dwThread);
- LRESULT CALLBACK CallWndRetProc(
- int nCode, // hook code
- WPARAM wParam, // current-process flag
- LPARAM lParam // address of structure with message data
- );
- BOOL WINAPI DllMain(HINSTANCE hinstDll,DWORD fdwReason,PVOID fImpLoad)
- {
- switch(fdwReason)
- {
- case DLL_PROCESS_ATTACH:
- g_hinstDll=hinstDll;
- break;
- case DLL_THREAD_ATTACH:
- break;
- case DLL_THREAD_DETACH:
- break;
- case DLL_PROCESS_DETACH:
- break;
- }
- return TRUE;
- }
- HHOOK SetFocusHook(HWND hWnd,DWORD dwThread)
- {
- if(g_hHook!=NULL)
- {
- UnhookWindowsHookEx(g_hHook);
- }
- g_hHook=SetWindowsHookEx(WH_CALLWNDPROCRET,CallWndRetProc,g_hinstDll,dwThread);
- g_hWnd=hWnd;
- return g_hHook;
- }
- LRESULT CALLBACK CallWndRetProc(
- int nCode, // hook code
- WPARAM wParam, // current-process flag
- LPARAM lParam // address of structure with message data
- )
- {
- if(nCode<0)
- {
- return CallNextHookEx(NULL,nCode,wParam,lParam);
- }
- CWPRETSTRUCT *p=(CWPRETSTRUCT *)lParam;
- // HDC hDC=GetDC(NULL);
- // static int i=0;
- if(p->message==WM_ACTIVATE)
- {
- WORD fActive=LOWORD(p->wParam);
- if(fActive==WA_ACTIVE||fActive==WA_CLICKACTIVE)
- {
- SetWindowPos(g_hWnd,HWND_TOPMOST,0,0,0,0,SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE);
- // TextOut(hDC,0,i,"WA_ACTIVE",strlen("WA_ACTIVE"));
- // i+=15;
- }
- else if(fActive==WA_INACTIVE)
- {
- if(GetForegroundWindow()!=g_hWnd)
- {
- SetWindowPos(g_hWnd,HWND_BOTTOM,0,0,0,0,SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE);
- }
- // TextOut(hDC,0,i,"WA_INACTIVE",strlen("WA_INACTIVE"));
- // i+=15;
- }
- }
- if(p->message==WM_SIZE)
- {
- if(p->wParam==SIZE_MINIMIZED)
- {
- ShowWindow(g_hWnd,SW_HIDE);
- // TextOut(hDC,0,i,"SIZE_MINIMIZED",strlen("SIZE_MINIMIZED"));
- // i+=15;
- }
- else if(p->wParam==SIZE_RESTORED)
- {
- ShowWindow(g_hWnd,SW_SHOWNA);
- // TextOut(hDC,0,i,"SIZE_RESTORED",strlen("SIZE_RESTORED"));
- // i+=15;
- }
- }
- if(p->message==WM_DESTROY)
- {
- // TextOut(hDC,0,i,"WM_CLOSE",strlen("WM_CLOSE"));
- // i+=15;
- SendMessage(g_hWnd,WM_CLOSE,0,0);
- }
- if(p->message==WM_MOVE)
- {
- //如果出现移动的情况,则及时发送消息给显示标志对话框以便移动.
- SendMessage(g_hWnd,MOVEMSG,wParam,p->lParam);
- }
- // ReleaseDC(NULL,hDC);
- return CallNextHookEx(NULL,nCode,wParam,lParam);
- }