473,549 Members | 2,543 Online
Bytes | Software Development & Data Engineering Community
+ 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("user 32.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 2372
Colin,
[DllImport("user 32.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("user 32.dll")]
static extern IntPtr SetParent(IntPt r 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
2305
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 frames, where the two lower ones are within a Frameset within the master Frameset: 1111111111111111111
4
22175
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 description and a class_id (stored in the value attribute of each option). The user will then select a class from the drop-down list. What I want...
2
23481
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 window to open a child window thru javascript window.open 2) I have some functionality in the child window that changes the data
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 like "Show Printable Version". Other than taking out all of the gui stuff and making a simple clean page for printing, is there any other design...
1
11545
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 http://weblogs.asp.net/asmith/archive/2003/09/15/27684.aspx but it was far more complex then I needed. (I got lost trying to figure it all...
7
2840
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 to be set to null after the main page has excuted a postback. Can anyone explain this or at show that I'm wrong ? Is this a bug in IE ?
4
9665
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 // NOTE THAT IF YOU SET days TO -1 THE COOKIE WILL BE SET TO YESTERDAY
2
2739
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 break that connection from the parent side or the child side, it doesn't matter as long as the communication link is completely broken. I don't want...
0
980
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
2374
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 in particular, but I am curious to know why some people find it "ugly" or "bad" or whatever. It has its own bugs and missing features, of course, but...
1
7491
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6055
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5381
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5101
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3509
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3491
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1956
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 we have to send another system
1
1068
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.