第一范文网 - 专业文章范例文档资料分享平台

第4章钩子函数和窗口子类化

来源:用户分享 时间:2025/7/23 7:01:44 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

pInfo->wmClientMsgs[pInfo->nClientWnds++]=wmMsg; bAddedWndToList=TRUE; }

ReleaseSharedMemPtr(); returnbAddedWndToList; }

STDAPI_(BOOL)SIRemoveClientWindow(HWNDhWnd) {

intloop;

BOOLbFoundWndInList=FALSE;

SharedMemory*pInfo=GetSharedMemPtr(); for(loop=0;loopnClientWnds;loop++) if(pInfo->hClientWnds[loop]==hWnd){ pInfo->hClientWnds[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;loophWin); returnBaseClassResult; } else {

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;

搜索更多关于: 第4章钩子函数和窗口子类化 的文档
第4章钩子函数和窗口子类化.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c6f10u88ky455t2h95zx7_8.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top