Home > Software engineering >  VB.NET form embedded
VB.NET form embedded

Time:09-17

VB.NET parent form embedded MDI child form

On the first of all, is really no matter use, still outside, and embed third-party application form to
Pay attention to my compiler: VisualStudio2017 and language VB.NET
/
 
Declare the Function SetParent Lib "user32" Alias "SetParent (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As an Integer
Declare the Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr


Private Sub Button1_Click (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles for. Click
System. Diagnostics. Process. The Start (" c: \ Windows \ system32 \ CMD exe ")
System. The Threading. Thread.sleep (50), 'I have found that it is not rest, FindWindow below may can't find the form
Dim h As IntPtr
H=FindWindow (vbNullString, "c: \ Windows \ system32 \ CMD exe")

SetParent (h, Me. Panel1. Handle) 'nested inside Panel1

'SetParent (h, Me. Handle)' or nested directly in the form
End Sub


 
Declare the Function SetParent Lib "user32" Alias "SetParent (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As an Integer
Declare the Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Function SendMessage Lib "user32. DLL" Alias "SendMessageA" (ByVal HWND As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
Private Declare Function ShellExecute Lib "shell32. DLL" Alias "ShellExecuteA" (ByVal HWND As Int32, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Int32) As Int32

Private Const WM_SYSCOMMAND As Int32=& amp; H112
Private Const SC_MAXIMIZE As Int32=& amp; HF030
Private Const SC_MINIMIZE As Int32=& amp; HF020
Private Const SC_RESTORE As Int32=& amp; HF120
Public Const SW_HIDE=0
Public Const SW_SHOW=5

Private Declare Function ShowWindow Lib "user32. DLL" (ByVal HWND As Int32, ByVal nCmdShow As Int32) As Int32


Private Sub Button1_Click (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles for. Click
ShellExecute (Me. Panel1. Handle, "open", "c: \ Windows \ system32 \ CMD exe", Nothing, "", SW_HIDE)
System. The Threading. Thread.sleep (50), 'I have found that it is not rest, FindWindow below may can't find the form
Dim h As IntPtr=FindWindow (Nothing, "c: \ Windows \ system32 \ CMD exe")
ShowWindow (h, SW_HIDE)
SetParent (h, Me. Panel1. Handle) 'nested inside Panel1
SendMessage (h, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
End Sub

Have the ability to help me solve the below these problems
Also, if the parent form support scale, but in the lower left corner after the child form minimize into strips, but, at this moment if the screen resolution to small, can't see
Is there any way to minimize it and in my automatically create a new button on the toolbar and search a child form title is replaced by name, shut down automatically after removing the button

When the parent program is closed, all external exe form closed

CodePudding user response:

You said "really doesn't work," is most likely your FindWindow () found no window!

Your code 1:
h=FindWindow (vbNullString, "c: \ Windows \ system32 \ CMD exe")
The second parameter, the requirement is "window title";
But the CMD. Exe window title, to use its "absolute path" as the title!!!!
Basic are: "command prompt", "administrator: command prompt" and such!!!!!!!!!
Or just say that two plus "- XXXXXX" (XXXX is executing commands or external program name),

If nothing else, the first "window handle" didn't you get right, everything is "nonsense" behind...
Suggest you FindWindow (), to investigate whether to find a handle!
Don't "no matter whether the execution of the success, I when it is successful" to deal with...

CodePudding user response:

As the upstairs said
In addition, suggest you use spy programs such as touching it with the mouse form, you want to see catch handle how much, and then look findwindow again to find how much is the window handle, are consistent

CodePudding user response:

But what if this form without handle, I use VB is without borders, so the title natural all have no, so that how to grasp the handle?

CodePudding user response:

1. Any one form handle!!!!!!

2. If "no border form", "window title"!
The window title, with "window title bar" are two different things...

3. If it is the same kind of "window", and "the window title is the same,"
So there is no guarantee that FindWindow () find the details of which...
But you can use FindWindowEx () to the enumeration "all conform to find conditions" window,
Only to "confirm" which is you are looking for, can you try to judge yourself!
It is impossible for others "help you guess" in what way can judge...

CodePudding user response:

Words, really can find findwindows?

CodePudding user response:

In 2017, BBS, go to vb.net. Net development here, don't VB here again,

CodePudding user response:

With findwindow find the window first, reoccupy setparent Settings, call again when the window size changes movewindow change size
  • Related