-3

In our application we have a dialog (CDialog) which is shown from the C++ MFC unmanaged world.

My Win-Forms modal dialog (C#) needs to set the unmanaged dialog as owner and thus as parent.

I don't know the handle or anything else about the C++ window.

My question is - how can I find the currently active window from the unmanaged MFC and set that as the owner of my modal dialog.

GerForegroundWindow delivers active window in the whole session, not within my application.

I would really appreciate any help from your side.

  • Can you tell us what research you have done to try and do this? Of the methods found why didn't they work? – AresCaelum Jul 18 '17 at 18:31
  • 1
    Hello and welcome to SO!, please check out the [documentation about asking question](https://stackoverflow.com/help/how-to-ask). I'm pretty sure a question about finding current active window has already been asked. Furthermore, you formulated a good question in your message, why not use it in the title ? – John-Philip Jul 18 '17 at 18:32
  • Possible duplicate of [How do I get the title of the current active window using c#?](https://stackoverflow.com/questions/115868/how-do-i-get-the-title-of-the-current-active-window-using-c) – AresCaelum Jul 18 '17 at 18:33
  • Well I indeed tried GerForegroundWindow. It gives me the top most window of current session (if visual studio is active, it returns visual studio as topmost window). But I need the current active window within my program. – stackoverflow_user_ Jul 18 '17 at 18:51

1 Answers1

0

Solved it by using GetActiveWindow. To create the owner I then used NativeWindow.FromHandle and passed the handle retrieved from GetActiveWindow

Thanks!