1

Win32 SetParent() への呼び出しを使用して、別のアプリケーションのメイン ウィンドウの親を変更する C# WPF アプリケーションを開発しています。このアウトプロセスの子ウィンドウへのハンドルは、HwndHost から派生した FormHost という名前のクラスによってラップされます。親を変更したウィンドウのメッセージが FormHost に配信されないという 1 つのことを除いて、すべてが正常に機能しています。MSDN のドキュメントには、HwndHost ウィンドウ プロシージャ WndProc() はアウト プロセス ウィンドウでは使用できないことが明確に記載されています。別の方法である MessageHook も機能しません。また、2 つのウィンドウの入力処理を結合するために、AttachThreadInput() を呼び出してみました。運がない。助言がありますか?

4

1 に答える 1

2

The process that is reparenting the window cannot directly subclass the message procedure of an out-of-process window. It would have to inject its own window procedure code into the address space of the window's owning process, subclass the window within that address space, and then finally use an IPC mechanism of your choosing to communicate back to the reparenting process as needed.

For the actual injection, you can either:

1) put the actual window procedure code into a DLL, use CreateRemoteThread() to load the DLL into the window's owning process, and then have the DLL's DllEntryPoint() subclass the window (you would have to store the HWND handle in global memory somewhere so the DLL can find it).

2) put the actual window procedure code into a block of memory allocated within the address space of the window's owning process by using VirtualAllocEx() and WriteProcessMemory(), then use CreateRemoteThread() to perform the actual subclass of the window using that memory block as the window procedure.

于 2009-09-03T19:52:33.357 に答える