简体   繁体   English

钩前景窗口

[英]Hook foreground window

How can i hook the foreground window? 我如何勾选前景窗口?

Currently I'm trying with 目前我正在尝试

using (Process processTmp = Process.GetCurrentProcess())
{
  using (ProcessModule module = processTmp.MainModule)
  {
    IntPtr hModule = Win32.GetModuleHandle(module.ModuleName);
    uint threadid = Win32.GetWindowThreadProcessId(Win32.GetForegroundWindow(), IntPtr.Zero);

    //WH_CALLWNDPROC = 4
    m_HookId = Win32.SetWindowsHookEx(4, m_HookProcedure, hModule, threadid); 
    if (m_HookId == IntPtr.Zero)
    {
      int tmp =
        Marshal.GetLastWin32Error();
    }
  }
}

But m_HookID is always IntPtr.Zero with error 1428 - Cannot set nonlocal hook without a module handle(ERROR_HOOK_NEEDS_HMOD). 但是m_HookID始终是IntPtr.Zero,错误1428 - 无法在没有模块句柄的情况下设置非本地挂钩(ERROR_HOOK_NEEDS_HMOD)。 So it seems that there is something wrong with hModule. 所以似乎hModule有问题。

Any suggestions? 有什么建议么? Tnx. TNX。

You cannot inject a managed assembly into a process. 您无法将托管程序集注入流程。 A native DLL is required, written in a language like C, C++ or Delphi. 需要一个本机DLL,用C,C ++或Delphi等语言编写。 This project might be useful as a source for the DLL you'll need. 此项目可能是您需要的DLL的源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM