Solved

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

Posted on 2004-09-09
4
571 Views
Last Modified: 2012-05-05
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

But

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 ?

Thanks

Marc
0
Comment
Question by:mridey
4 Comments
 

Author Comment

by:mridey
ID: 12023095
I found a solution on the dotnet247 forum.
After I create the .Net control, I call SetParent Win32 using:

\\\
[DllImport("USER32.DLL")]
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.
0
 
LVL 8

Expert Comment

by:Razzie_
ID: 12024935
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 :)
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 12269943
PAQed - no points refunded (of 500)

Computer101
E-E Admin
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now