云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 第4章钩子函数和窗口子类化

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

  • 62 次阅读
  • 3 次下载
  • 2026/4/23 23:09:00

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章钩子函数和窗口子类化 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

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->hC

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com