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

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

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

  • 62 次阅读
  • 3 次下载
  • 2025/12/3 7:19:27

{

caseWM_DESTROY: {

PostQuitMessage(0); break; }

caseWM_APP+1024: {

if(w_param==125) {

SendKeys(\SendReturnKey(2); SendKeys(\SendReturnKey(3); SendKeys(\SendReturnKey(2); SendKeys(\SendReturnKey(10); SendKeys(\SendReturnKey(2); SendKeys(\}

if(w_param==126) {

SendKeys(\}

break; }

caseWM_COMMAND: {

if(w_param==BN_CLICKED) {

if(l_param==(long)h_wnd5) {

WinExec(\

hHookedWindow=FindWindow(\未定标题-记事本\if(hHookedWindow==NULL) {

MessageBox(0,\

Notepad.\\r\\nPleaseStartNotepadandtryagain\break; }

HMENUhAppMenu;

hAppMenu=GetMenu(hHookedWindow);

HMENUhAppendMenu;

hAppendMenu=CreateMenu();

AppendMenu(hAppMenu,MF_STRING+MF_POPUP,(unsigned int)hAppendMenu,\

AppendMenu(hAppendMenu,MF_STRING,125,\AppendMenu(hAppendMenu,MF_STRING,126,\HWNDhMenuWnd;

hLib=LoadLibrary(\

hMenuWnd=GetWindow(hHookedWindow,5); DWORDhThread;

hThread=GetWindowThreadProcessId(hHookedWindow,NULL); SetHandle=(sthndl)GetProcAddress(hLib,\UnSubClass=(unsub)GetProcAddress(hLib,\SetHandle(hHookedWindow,hwnd);

FillHandleArray=(filhndl)GetProcAddress(hLib, \

FillHandleArray(hHookedWindow,1); FillHandleArray(hMenuWnd,1);

ShowWindow(hHookedWindow,SW_MINIMIZE); }

if(l_param==(long)h_wnd6) {

UnSubClass(); FreeLibrary(hLib); } }

break; } }

returnDefWindowProc(hwnd,msg2,w_param,l_param); }

钩子实现的代码如下: #include #include usingnamespacestd;

LRESULTCALLBACKWindowProc(HWNDhwnd,UINTuMsg,WPARAMwParam,LPARAM lParam);//窗口回调过程 #pragmadata_seg(\HWNDhTarget=NULL; HWNDhApp=NULL; intnum=0;

booldone=FALSE;

HINSTANCEhInstance=NULL; #pragmadata_seg()

#pragmabss_seg(\HWNDhndll[100]; intform[100];

longOldWndHndl[100]; BOOLblnsubclassed[100]; HHOOKhWinHook; #pragmabss_seg()

BOOLWINAPIDllMain(HANDLEhinstDLL,DWORDfdwReason,LPVOID lpvReserved) {

switch(fdwReason) {

caseDLL_PROCESS_ATTACH:

hInstance=(HINSTANCE)hinstDLL; break;

caseDLL_PROCESS_DETACH: break; }

returnTRUE; }

intWINAPIFillHandleArray(HWNDhwndSubclass,intintFrmNUm) {

hndll[num]=hwndSubclass;//填充数组 form[num]=intFrmNUm;

blnsubclassed[num]=FALSE;//设置子类化状态 num=num+1; return1; }

//取消子类化过程 intWINAPIUnSubclass() {

intcount;

for(count=0;count

if((int)hndll[count]>1) {

SetWindowLong(hndll[count],GWL_WNDPROC,OldWndHndl[count]);} }

return1; }

LRESULTCALLBACKCBTProc(intnCode,WPARAMwParam,LPARAMlParam) {

if(nCode==HCBT_ACTIVATE) {

if((HWND)(wParam)==hTarget) {

intcount;

for(count=0;count

if(blnsubclassed[count]==FALSE) {

if(((int)hndll[count])>1) {

OldWndHndl[count]=SetWindowLong(hndll[count],GWL_WNDPROC, (long)WindowProc); }

blnsubclassed[count]=TRUE; } } } }

if(nCode==HCBT_DESTROYWND) {

if((HWND)wParam==hTarget)

SendNotifyMessage(hApp,WM_APP+1024,(WPARAM)wParam,(LPARAM)lParam); }

returnCallNextHookEx(NULL,nCode,wParam,lParam); }

intWINAPISetHandle(HWNDHandleofTarget,HWNDHandleofApp) {

hTarget=HandleofTarget; hApp=HandleofApp;

hWinHook=SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTProc,hInstance, GetWindowThreadProcessId(hTarget,NULL)); return1; }

LRESULTCALLBACKWindowProc(HWNDhwnd,UINTuMsg,WPARAMwParam, LPARAMlParam) {

longval; intcount;

for(count=0;count

if(HIWORD(wParam)==0)

result=SendNotifyMessage(hApp,WM_APP

+1024,(WPARAM)(LOWORD(wParam)),(LPARAM)uMsg); return

搜索更多关于: 第4章钩子函数和窗口子类化 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

{ caseWM_DESTROY: { PostQuitMessage(0); break; } caseWM_APP+1024: { if(w_param==125) { SendKeys(\SendReturnKey(2); SendKeys(\SendReturnKey(3); SendKeys(\SendReturnKey(2); SendKeys(\SendReturnKey(10); SendKeys(\SendReturnKey(2); SendKeys(\} if(w_param==126) { SendKeys(\} break; } caseWM_COMMAND: { if(w_param==BN_CLICKED) {

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价: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