发布时间 : 星期六 文章第4章钩子函数和窗口子类化更新完毕开始阅读a478eed3240c844769eaee1b
pInfo->wmClientMsgs[pInfo->nClientWnds++]=wmMsg; bAddedWndToList=TRUE; }
ReleaseSharedMemPtr(); returnbAddedWndToList; }
STDAPI_(BOOL)SIRemoveClientWindow(HWNDhWnd) {
intloop;
BOOLbFoundWndInList=FALSE;
SharedMemory*pInfo=GetSharedMemPtr(); for(loop=0;loop
pInfo->hClientWnds[pInfo->nClientWnds-1]; pInfo->wmClientMsgs[loop]=
pInfo->wmClientMsgs[pInfo->nClientWnds-1]; pInfo->nClientWnds--; bFoundWndInList=TRUE; break; }
ReleaseSharedMemPtr(); returnbFoundWndInList; }
STDAPI_(void)SIGetMinRect(RECT*pRect) {
SharedMemory*pMem=GetSharedMemPtr(); *pRect=pMem->rMinRect; ReleaseSharedMemPtr(); }
/******Shell-窗口获得******/
HWNDGetShellWnd(constchar*pClasses) {
HWNDh=NULL; while(*pClasses){
charBuffer[512],*pBuffer=Buffer; while(*pClasses&&(*pClasses!=';')) *pBuffer++=*pClasses++; *pBuffer='\\0'; if(*pClasses==';') pClasses++;
h=FindWindowEx(h,NULL,Buffer,NULL); if(h==NULL) returnNULL;
}
returnh; }
/*shell-子类化变量*/
staticLONGg_OrgShellWndProc=0; staticBOOLg_bShellSubclassed=FALSE; staticUINTwm_ShellHook,wm_DecCount;
voidUnsubclassShell(void);/*functionprototype*/
/*新的子类化窗口过程*/
LRESULTCALLBACKShellHookCatcher(HWNDhWnd,UINTMsg, WPARAMwParam,LPARAMlParam) {
intloop;
if(Msg==WM_DESTROY)/*forciblyun-subclasswindow*/ UnsubclassShell();
if(Msg==wm_ShellHook){
/*制作一个SharedMemory结构的副本*/
SharedMemory*pGlobalCopy=GetSharedMemPtr(); SharedMemoryMyCopy=*pGlobalCopy; ReleaseSharedMemPtr();
if(wParam==HSHELL_GETMINRECT){
LRESULTBaseClassResult=CallWindowProc( (WNDPROC)g_OrgShellWndProc,hWnd, Msg,wParam,lParam);
typedefstructtagInternalShellStruct {
HWNDhWin;
SMALL_RECTMinRect; }InternalShellStruct;
InternalShellStruct*p=(InternalShellStruct*)lParam; SharedMemory*pGlobalCopy=GetSharedMemPtr(); pGlobalCopy->rMinRect.left=p->MinRect.Left; pGlobalCopy->rMinRect.top=p->MinRect.Top; pGlobalCopy->rMinRect.right=p->MinRect.Right;
pGlobalCopy->rMinRect.bottom=p->MinRect.Bottom; ReleaseSharedMemPtr();
for(loop=0;loop
for(loop=0;loop MyCopy.wmClientMsgs[loop],wParam,lParam); } } elseif(Msg==wm_DecCount){ SharedMemory*pInfo=GetSharedMemPtr(); intnUsers=pInfo->nUsers; ReleaseSharedMemPtr(); if(nUsers==0) UnsubclassShell(); return0; } returnCallWindowProc((WNDPROC)g_OrgShellWndProc, hWnd,Msg,wParam,lParam); } BOOLSubclassShell(void) { HWNDh; if(!g_bShellSubclassed){ g_bShellSubclassed=TRUE; wm_ShellHook=RegisterWindowMessage(\wm_DecCount=RegisterWindowMessage(\h=GetShellWnd(\if(!h)//mustbeWin98orWin95withIE4 h=GetShellWnd( \if(h){ SharedMemory*pInfo; SetupSharedMemMap(); pInfo=GetSharedMemPtr(); pInfo->hShellHookCatcher=h; ReleaseSharedMemPtr(); g_OrgShellWndProc=GetWindowLong(h,GWL_WNDPROC); SetWindowLong(h,GWL_WNDPROC,(LONG)ShellHookCatcher); /****子类化其他窗口*/ returnTRUE; } else returnFALSE; } else returnFALSE; } voidUnsubclassShell(void) { if(g_bShellSubclassed){ SharedMemory*p=GetSharedMemPtr(); HWNDh=p->hShellHookCatcher; ReleaseSharedMemPtr(); SetWindowLong(h,GWL_WNDPROC,g_OrgShellWndProc); g_bShellSubclassed=FALSE; /****恢复原来的窗口过程*/ ShutdownSharedMemMap(); } } LONGRegDeleteKey2(HKEYhKeyParent,LPCTSTRlpszKeyChild) { FILETIMEtime; charbuffer[256]; DWORDdwSize; HKEYhKeyChild; longresult=RegOpenKeyEx(hKeyParent,lpszKeyChild,0, KEY_ALL_ACCESS,&hKeyChild); if(result!=ERROR_SUCCESS) returnresult; dwSize=sizeof(buffer); while(RegEnumKeyEx(hKeyChild,0,buffer,&dwSize,NULL, NULL,NULL,&time)==ERROR_SUCCESS){ result=RegDeleteKey2(hKeyChild,buffer); if(result!=ERROR_SUCCESS){ RegCloseKey(hKeyChild); returnresult; } dwSize=sizeof(buffer); } RegCloseKey(hKeyChild); returnRegDeleteKey(hKeyParent,lpszKeyChild); } char*CLSIDstring(REFCLSIDclsid,char*buf,intbufsize) { LPOLESTRpWideCLSID=NULL; HRESULThresult=StringFromCLSID(clsid,&pWideCLSID); assert(SUCCEEDED(hresult)&&(pWideCLSID!=NULL)); assert(bufsize>=39); wcstombs(buf,pWideCLSID,bufsize); CoTaskMemFree(pWideCLSID); returnbuf;