Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.

I use VB.NET and I try to find a way to embed the window of an application in the window of my own application, determining myself its display area. I know that OLE exists but in the case that interests me, there is no OLE.

May it pass by create a master/slave link, or else... anyway. May VB.net doesn't help.

Short. I think it's achievable, even if it's not widespread. Can you help me ?

What I have tried:

i'm still searching for solution
Posted
Updated 5-Jun-17 23:12pm
Comments
[no name] 2-Jun-17 12:15pm    
I don't like to post this as a solution because it is a very dirty way:
The key point is to get the window handle of "the application". If you have it (either by enum processes and get the mainwindow handle or in worst case by Windows title) you can use "SetParent" to set the the parent....
Take care, this it is not a way to solve it for production code ;)

And yes of course, I did it also _one time_ for production, because it was the only solution and works now for more than 10 years *lol*
ZurdoDev 2-Jun-17 14:27pm    
Sounds like a solution to me.
[no name] 2-Jun-17 14:38pm    
But it is less than ideal. And I think lot of downvotes will be foreseeable ;) ok, I risk it :-) And thanks for pushing me on this.

Less than ideal, but in worst case... my comment as a solution.

The key point is to get the window handle of "the application". If you have it (either by enum processes and get the main window handle or in worst case by Windows title) you can use "Win API SetParent" to set the the parent of the app's window to one of your choice....

Among others with the Win API SetWindowPos and ShowWindow you can "control" it. "Control", because it very depends on what the app reacts on this.

Take care, this it is not a way to solve it for production code ;)

And yes of course, I did it also _one time_ for production, because it was the only solution and works now for more than 10 years.
 
Share this answer
 
Comments
Frederic GIRARDIN 6-Jun-17 3:46am    
i tryed it like http://www.pinvoke.net/default.aspx/user32.setparent said. A winform (MDI or not) with a button to launch setParent... but didn't work...
Frederic GIRARDIN 6-Jun-17 3:48am    
i'm looking to Win32 API SetForegroundWindow or LockSetForegroundWindow, but still unable to download sample.
VB
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Declare Auto Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Const WM_SYSCOMMAND As Integer = 274
Private Const SC_MAXIMIZE As Integer = 61488

Private hWnd As Long = 0

Private Sub SimpleButton1_Click(sender As Object, e As EventArgs) Handles SimpleButton1.Click
   'May i'm not needing to run a process for exemple
   'Dim proc As Process

   'proc = Process.Start(Environment.GetEnvironmentVariable("windir") + "\notepad.exe") 

If hWnd = 0 Then
   'in my program context, Tfrm_ifc_view, was my classname
   hWnd = FindWindow("Tfrm_ifc_view", Nothing)
   If hWnd <> 0 Then
      SetParent(hWnd, Me.Panel1.Handle)
      SendMessage(hWnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
   End If
else
   SetParent(hWnd, nothing)
   hWnd = 0
end if
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900