473,406 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 2360
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
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
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
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.