Solved

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

Posted on 2004-09-09
4
586 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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