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

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

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

{

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