• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 605
  • Last Modified:

How to insert a .NET control into a non-.NET NativeWindow ?

I'm writing an Office Add-in in C#.
Using Automation, I get the Handle of the main window of the application in which the Add-in is running (in my case, PowerPoint).
I can then navigate the Child windows, hook into message loops and can create additional Windows using the NativeWindow class


I would like to be able to create a .NET control and position it into the application. The problem is that I have non-.NET handles and when I try to call Control.FromHandle(handle), it returns null. Then I can't assign a parent to my .NET control so it's not displayed.

So How do I assign a .NET control to a non-.NET parent window ?


1 Solution
mrideyAuthor Commented:
I found a solution on the dotnet247 forum.
After I create the .Net control, I call SetParent Win32 using:

private static extern IntPtr SetParent(
IntPtr hWndChild, // handle to window
IntPtr hWndNewParent // new parent window

That work.

If you know anything nicier, I'll still award the points.
I don't even think there is another way to do that, although I could be wrong. Might just ask to get your points refunded in the community TA :)
PAQed - no points refunded (of 500)

E-E Admin
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now