473,486 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Making a non .NET window a parent of a .NET one.

Hi,

I am working on a project where by a .NET framework DLL links into a non
..NET application and adds functionality to it. Part of the functionality we
are adding is displayed through a .NET form.

The problem I am having is that I cannot find a way to make my .NET form a
child window of the main application. I have tried using APIs such as:

[DllImport("user32.dll")]
static extern long SetParent(long hWndChild, long hWndNewParent);

However this API, and some of the others, dont seem to work even if you are
just dealing with two .NET forms.

Anyway I was wondering if anyone could point me in the right direction as
I'm sure there must be a way to do it ?

Thanks,

Colin
Jul 19 '05 #1
2 2364
Colin,
[DllImport("user32.dll")]
static extern long SetParent(long hWndChild, long hWndNewParent);

However this API, and some of the others, dont seem to work even if you are
just dealing with two .NET forms.


Try it like this instead.

[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr
hWndNewParent);

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Jul 19 '05 #2
jorich
1 New Member
After much searching I have amalgamated several posts from different sites into this set of routines as there was no one place that gave all the information

In order to get a .NET form to use any other application as its parent you can do the following in vb (Replace Application by the name of your parent APP as it appears in the task list)

In general Declarations:
Expand|Select|Wrap|Line Numbers
  1. Imports System.diagnostics
In the form Declarations:
Expand|Select|Wrap|Line Numbers
  1. Declare Auto Function SetParent Lib "user32" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
In the form load event:
Expand|Select|Wrap|Line Numbers
  1. Dim procs() As Process
  2.         procs = Process.GetProcessesByName("Application Name")
  3.         If (procs.Length <> 0) Then
  4.             For i As Integer = 0 To procs.Length - 1
  5.                 Dim ParentApp As New WindowWrapper(procs(i).MainWindowHandle)
  6.                 SetParent(Me.Handle, ParentApp.Handle)
  7.             Next
  8.         End If

Create a new class as:
Expand|Select|Wrap|Line Numbers
  1. Public Class WindowWrapper
  2.     Implements System.Windows.Forms.IWin32Window
  3.     Private _hwnd As IntPtr
  4.  
  5.     Public Sub New(ByVal handle As IntPtr)
  6.         _hwnd = handle
  7.     End Sub
  8.  
  9.     Public ReadOnly Property Handle() As System.IntPtr Implements System.Windows.Forms.IWin32Window.Handle
  10.         Get
  11.             Return _hwnd
  12.         End Get
  13.     End Property
  14.  
  15.     End Class
Jul 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2289
by: David Hayes | last post by:
I tried finding an answer on http://www.quirksmode.org/ without success. I am attempting a complicated Frames structure. I have made it work in IE, but not Netscape. I begin with three...
4
22151
by: Davey | last post by:
I have a website which has a popup window (this only opens when the user chooses to open it). In the popup window I have a <select> control which lists a selection of "classes". Each class has a...
2
23478
by: Raj | last post by:
Hi All, I have a problem with trying to refresh the parent window from child window in order to update data in the parent window. The sequence of events are 1) I click a button in the parent...
5
346
by: moondaddy | last post by:
I'm going to use an aspx page to display an invoice that customers can print from. Sometimes when I go to a site and navigate to a page I want to print, they will have a button that says something...
1
11530
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
7
2832
by: MrFez | last post by:
Through some investigation it appears that selecting "Every visit to the page" for the IE caching setting "Check for new version of stored pages" causes the window.opener property of child windows...
4
9637
by: Phil Powell | last post by:
I thought this would work but it seems to not work neither in Netscape nor in IE: <script type="text/javascript"> <!-- // OBTAINED FROM http://www.javascripter.net/faq/settinga.htm //...
2
2729
by: epaetz | last post by:
Is there a way to decouple the linkage between a parent and a child window? Does the parent window have any sort of a collection that holds all the children that it has spawned? I want to...
0
970
by: Phil Thompson | last post by:
On Sunday 04 May 2008, Lance Gamet wrote: I think QMainWindow.setCentralWidget() is what you are looking for. The eric4 IDE probably covers most things you'll ever need. Phil
16
2363
by: Andrea Gavana | last post by:
Hi Diez & All, Do you mind explaining "why" you find it *buttugly*? I am asking just out of curiosity, obviously. I am so biased towards wxPython that I won't make any comment on this thread...
0
7094
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7173
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6839
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7305
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4863
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3066
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.