zoukankan      html  css  js  c++  java
  • 钩子

    在client.cpp中包含wgdlg.h
    CDLGWG * GameForm = NULL; HWND GameHwnd = NULL; //钩子回调函数 LRESULT CALLBACK GameProc(int nCode,WPARAM wParam,LPARAM lParam) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); PMSG pMsg=(PMSG)lParam; if (pMsg->message==WM_KEYUP) { if (pMsg->wParam==VK_HOME) { if (GameForm==NULL) { GameHwnd = pMsg->hwnd; GameForm=new CDLGWG(); GameForm->Create(IDD_DIALOG_WG); GameForm->ShowWindow(TRUE); } else if (GameForm->IsWindowVisible()) { GameForm->ShowWindow(FALSE); } else { GameForm->ShowWindow(TRUE); } } } return CallNextHookEx(0,nCode,wParam,lParam); } //安装钩子 void StartHook() { AFX_MANAGE_STATE(AfxGetStaticModuleState()); HWND hGame = FindWindow(_T("TianLongBaBu WndClass"),NULL); if (hGame==0) { MessageBox(NULL,_T("未找到游戏"),_T("提示"),NULL); return; } DWORD tid=GetWindowThreadProcessId(hGame,NULL); ::SetWindowsHookEx(WH_GETMESSAGE,GameProc,::GetModuleHandle(_T("GameDll.dll")),tid); } ; GameDll.def : 声明 DLL 的模块参数。 LIBRARY EXPORTS ; 此处可以是显式导出 StartHook //调用钩子处导出函数声明 #pragma comment(lib,"GameDll.lib") _declspec(dllimport) void StartHook();

    //退出时不保证游戏崩溃
    在dll头文件中类的重写属性中添加退出事件

    int CGameDllApp::ExitInstance()

    {  

     if (GameHwnd!=0)

     {   

        delete GameForm;   

        GameForm= NULL;  

    }

     return CWinApp::ExitInstance();

    }

  • 相关阅读:
    使用阿里云ECS安装HDFS的小问题
    退役回忆录嘤嘤嘤
    2018 ICPC北京 H ac自动机
    Educational Codeforces Round 54 (Rated for Div. 2) DE
    sa learning
    网络流learning
    Python模块logging
    Python模块unittest
    Linux /dev/shm
    Shell 字符串操作
  • 原文地址:https://www.cnblogs.com/wumac/p/4222314.html
Copyright © 2011-2022 走看看