1

I am about to attach a child window to an external application. The child window will be a modeless dialog. Since I do not own the source code of the external application (actually Microsoft FSX), I have no idea how I would hook into the message loop or the callback LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM) of the parent window itself.

My attaching application runs in its own process, so will I need to write my own message loop, or will my callback be invoked by the parent's message pump?

What would be the correct way of getting ahead?

-- Edit as of Answer regarding SetWindowsHookEx function --

Noteworthy:

  1. How to hook external process with SetWindowsHookEx and WH_KEYBOARD
  2. SetWindowsHookEx in C#
  3. Maybe not working, another SetWindowsHookEx Example
3
  • 1
    How are you attaching it? just SetParent? If so, then it uses your message pump and handler, but can cause "oddities".
    – Deanna
    Jun 13, 2012 at 10:18
  • I just set the parent window handle when I create it. What would be the correct way, without "oddies"? Jun 13, 2012 at 11:41
  • 1
    Hosting controls from different processes and UI threads causes problems for focus, activation, etc. There is no standard way to do that without the host process window helping. The best way without its help is DLL injection so it runs in the process and main UI thread.
    – Deanna
    Jun 13, 2012 at 22:16

1 Answer 1

3

SetWindowsHookEx is the API that will allow an external process to capture window messages (among other things).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.