?
Solved

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

Posted on 2004-09-09
4
Medium Priority
?
593 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

762 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