[英]Hooking to MFC object creation globally
我有一个从CWnd继承的X类,我想从应用程序域外部连接到X Create,即程序A必须监视程序B中的X对象实例。有什么办法可以做到这一点?
You can't monitor creation of an object of X (X ctor X::X()
). 您无法监视X对象的创建(X ctor
X::X()
)。
You also can't monitor calls to X::Create
. 您也不能监视对
X::Create
调用。
But there might be a solution for you: 但是可能有一个解决方案:
Since X::Create
calls CWnd::Create
and this creates a window, you can hook up to window creation and might be able to detect when a X's window is created. 由于
X::Create
调用CWnd::Create
并创建了一个窗口,因此您可以进行窗口创建,并且可能能够检测X窗口的创建时间。 But you will only be able to recognize this if there is something special about the windows created like a known window class used to create them. 但是,只有在创建的窗口有一些特殊的东西(例如用于创建它们的已知窗口类)时,您才能识别出这一点。 If this is the case, then:
如果是这样,则:
You already got the right answer in your previous question Hooking window creation in an MFC program . 您在上一个问题中已经获得了正确的答案在MFC程序中挂钩窗口创建 。
You can use SetWindowsHookEx (WH_CBT, lpfn, hMod, dwThreadId) to get notified when windows are created. 您可以使用SetWindowsHookEx (WH_CBT,lpfn,hMod,dwThreadId)在创建窗口时得到通知。
Some things to keep in mind: 注意事项:
SetWindowsHookEx
. SetWindowsHookEx
的进程中。 This is because windows will load/inject your DLL into every process that it monitors for window creation. CallNextHookEx
. CallNextHookEx
。 HCBT_CREATEWND
and the window classes (or whatever) that you are interested in. HCBT_CREATEWND
和您感兴趣的窗口类(或其他)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.