473,385 Members | 1,693 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,385 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 2358
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.