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
Community
  • 1
  • 1
Horst Walter
  • 13,663
  • 32
  • 126
  • 228
  • 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 '12 at 10:18
  • I just set the parent window handle when I create it. What would be the correct way, without "oddies"? – Horst Walter Jun 13 '12 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 '12 at 22:16

1 Answers1

3

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

Chris O
  • 5,017
  • 3
  • 35
  • 42