-
Oct 3rd, 2017, 04:18 AM
#1
Thread Starter
Addicted Member
[RESOLVED] is it possible to open a chm file in a mdichild window
Good day,
I have a chm file that opens as a pop up, but i would like it to open in a mdichild.
can this be done and how, i have searched everywhere but havent found anything only then how to add the chm file as a pop up
Regards
-
Oct 3rd, 2017, 04:29 PM
#2
Re: is it possible to open a chm file in a mdichild window
I don't know if that is possible, but if it is, you need to start a process with the exe that runs a chm as the filename, with the chm path as the argument.
The way to host a window, is...
Code:
<DllImport("user32")> Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
End Function
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 3rd, 2017, 04:32 PM
#3
Re: is it possible to open a chm file in a mdichild window
Microsoft Help Executable is...
C:\Windows\hh.exe
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 4th, 2017, 06:06 AM
#4
Thread Starter
Addicted Member
Re: is it possible to open a chm file in a mdichild window
Done it with this code
Code:
Private Const WM_SYSCOMMAND As Integer = 274
Private Const SC_MAXIMIZE As Integer = 61488
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 Sub Manual_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim proc As Process
proc = Process.Start("D:\Documenten\CW ISM\CW ISM.chm")
WindowState = FormWindowState.Maximized
Panel1.Width = 1910
Panel1.Height = 800
Panel2.Dock = DockStyle.Bottom
Panel2.Height = 150
Panel2.Width = 1910
proc.WaitForInputIdle()
SetParent(proc.MainWindowHandle, Me.Panel1.Handle)
SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
End Sub
only now it is a problem with resizing
-
Oct 4th, 2017, 06:22 AM
#5
Re: is it possible to open a chm file in a mdichild window
Put the SendMessage line in the Form_Resize event too
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 4th, 2017, 06:39 AM
#6
Thread Starter
Addicted Member
Re: is it possible to open a chm file in a mdichild window
the send message has proc local variable and wll not work with the resize event
-
Oct 4th, 2017, 07:02 AM
#7
Re: is it possible to open a chm file in a mdichild window
So make the variable Form level...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 4th, 2017, 10:10 AM
#8
Junior Member
Re: is it possible to open a chm file in a mdichild window
If you are still looking for code for setting the Help window as an MDI child window, see the below code. Note that I changed the window attributes of the Help window for MDI and enumerated the MDI child windows of the app to get the MDI client window for setting of the parent. You will need to change the file path of the windows help file and the Help window title.
Code:
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Int32
Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As Integer, ByVal nIndex As Integer) As Integer
Private Declare Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As IntPtr, ByVal lpClassName As System.Text.StringBuilder, ByVal nMaxCount As Integer) As Integer
Private Const GWL_EXSTYLE As Integer = -20
Private Const GWL_STYLE As Integer = -16
Private Const WS_EX_MDICHILD As Integer = 64
Private Const WS_CHILD As Integer = 1073741824
'------------------------------------------------------------
System.Diagnostics.Process.Start("<path to Help file>")
System.Threading.Thread.Sleep(500)
Dim hCHMWnd As IntPtr = FindWindow("HH Parent", "Help Window Title")
If Not hCHMWnd.Equals(IntPtr.Zero) Then
SetWindowLong(hCHMWnd, GWL_STYLE, (GetWindowLong(hCHMWnd, GWL_STYLE) Or WS_CHILD))
SetWindowLong(hCHMWnd, GWL_EXSTYLE, (GetWindowLong(hCHMWnd, GWL_EXSTYLE) Or WS_EX_MDICHILD))
Dim hMDIWnd As IntPtr = FindWindowEx(Me.Handle, 0, vbNullString, vbNullString)
Dim hMDIClientWnd As IntPtr = 0
If Not hMDIWnd.Equals(IntPtr.Zero) Then
Do Until hMDIWnd.Equals(IntPtr.Zero)
hMDIWnd = FindWindowEx(Me.Handle, hMDIWnd, vbNullString, vbNullString)
If Not hMDIWnd.Equals(IntPtr.Zero) Then
Dim className As New System.Text.StringBuilder("", 256)
Call GetClassName(hMDIWnd, className, 256)
If className.ToString.Contains("MDICLIENT") Then
hMDIClientWnd = hMDIWnd
Exit Do
End If
End If
Loop
If Not hMDIClientWnd.Equals(IntPtr.Zero) Then
SetParent(hCHMWnd, hMDIClientWnd)
End If
End If
End If
Paul ~~~~ Microsoft MVP (Visual Basic)
-
Oct 4th, 2017, 11:22 AM
#9
Thread Starter
Addicted Member
Re: is it possible to open a chm file in a mdichild window
Thank you for the reply,
I have put this in a button click event but it is not opening in a mdichild it is just opening the chm file
nb Set Parent function was declared as intptr should be integer
-
Oct 4th, 2017, 11:41 AM
#10
Junior Member
Re: is it possible to open a chm file in a mdichild window
You are running this code from an MDI form correct? Does the MDI form have any scrollbars? It may be that the child window (Help application) is simply not visible in the MDI parent form. Also make sure that in the call to FindWindow the help window title is correct.
The SetParent function returns a windows handle so IntPtr would be the correct usage, although the use of Integer should be fine.
Paul ~~~~ Microsoft MVP (Visual Basic)
-
Oct 4th, 2017, 11:46 AM
#11
Re: is it possible to open a chm file in a mdichild window
@pclement. If an API function requires an intptr, only turning off Option Strict could allow you to pass an integer...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 4th, 2017, 11:59 AM
#12
Thread Starter
Addicted Member
Re: is it possible to open a chm file in a mdichild window
MDI child dow not have scrollbars
and indeed option strict is off
Code:
System.Diagnostics.Process.Start("D:\Documenten\CW ISM\CW ISM.chm")
System.Threading.Thread.Sleep(500)
Dim hCHMWnd As IntPtr = FindWindow("HH PARENT", "Coastwise ISM Reader")
title of help window title is the title of the helpfile when chm file is opened
Last edited by zubenubie; Oct 4th, 2017 at 12:05 PM.
-
Oct 4th, 2017, 12:11 PM
#13
Re: is it possible to open a chm file in a mdichild window
That code is just for finding your mdiparent window's window handle. There are easier ways to achieve that, especially as you are probably opening the chm from a menu within your mdi form?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 4th, 2017, 12:13 PM
#14
Junior Member
Re: is it possible to open a chm file in a mdichild window
Originally Posted by .paul.
@pclement. If an API function requires an intptr, only turning off Option Strict could allow you to pass an integer...
I do not have Option Strict On, since I use late binding in some instances, but feel free to change all of the window handle Integer declarations to IntPtr so that they are compliant. The code I posted is simply a proof of concept. ;-)
Paul ~~~~ Microsoft MVP (Visual Basic)
-
Oct 4th, 2017, 12:21 PM
#15
Thread Starter
Addicted Member
Re: is it possible to open a chm file in a mdichild window
well MDIparent is frmMain and the mdichild is frManual
i have tried variations on this but i havent got the chm file not opened in the mdichild
-
Oct 4th, 2017, 12:32 PM
#16
Hyperactive Member
Re: is it possible to open a chm file in a mdichild window
Hi, i had a look on to pclement code and it works with Option Explicit OFF and with Option Explicit On you will have to change for this:
Code:
Process.Start("F:\dv_aspnetmmc.chm")
Threading.Thread.Sleep(500)
Dim hCHMWnd As IntPtr = CType(FindWindow("HH Parent", "ASP.NET Management Tools"), IntPtr)
If Not hCHMWnd.Equals(IntPtr.Zero) Then
SetWindowLong(hCHMWnd, GWL_STYLE, (GetWindowLong(CInt(hCHMWnd), GWL_STYLE) Or WS_CHILD))
SetWindowLong(hCHMWnd, GWL_EXSTYLE, (GetWindowLong(CInt(hCHMWnd), GWL_EXSTYLE) Or WS_EX_MDICHILD))
Dim hMDIWnd As IntPtr = CType(FindWindowEx(Me.Handle, CType(0, IntPtr), vbNullString, vbNullString), IntPtr)
Dim hMDIClientWnd As IntPtr = CType(0, IntPtr)
If Not hMDIWnd.Equals(IntPtr.Zero) Then
Do Until hMDIWnd.Equals(IntPtr.Zero)
hMDIWnd = CType(FindWindowEx(Me.Handle, hMDIWnd, vbNullString, vbNullString), IntPtr)
If Not hMDIWnd.Equals(IntPtr.Zero) Then
Dim className As New System.Text.StringBuilder("", 256)
Call GetClassName(hMDIWnd, className, 256)
If className.ToString.Contains("MDICLIENT") Then
hMDIClientWnd = hMDIWnd
Exit Do
End If
End If
Loop
If Not hMDIClientWnd.Equals(IntPtr.Zero) Then
SetParent(hCHMWnd, hMDIClientWnd)
End If
End If
End If
The point is that the mdichild opens far left and far to the top hiding it, and you will need to swich the mdiparent from Maximazed to Normal or from normal to maximized to see the scrool bars.
So you will need to find out a way to set the child location if you want it to be correctly displyed in the mdi parent form center.
-
Oct 4th, 2017, 12:33 PM
#17
Junior Member
Re: is it possible to open a chm file in a mdichild window
Originally Posted by zubenubie
MDI child dow not have scrollbars
and indeed option strict is off
Code:
System.Diagnostics.Process.Start("D:\Documenten\CW ISM\CW ISM.chm")
System.Threading.Thread.Sleep(500)
Dim hCHMWnd As IntPtr = FindWindow("HH PARENT", "Coastwise ISM Reader")
title of help window title is the title of the helpfile when chm file is opened
Sorry, not following. The Microsoft HTML Help application should have a caption in the title bar. You should be using that text in the call to FindWindow to fetch the main window handle. You could also use the Process Class from which you launched the app to retrieve the main window handle if you are more comfortable with that. Maybe this would be easier:
Code:
Dim htmlHelpProcess As System.Diagnostics.Process = System.Diagnostics.Process.Start("D:\Documenten\CW ISM\CW ISM.chm")
System.Threading.Thread.Sleep(500)
Dim hCHMWnd As IntPtr = htmlHelpProcess.MainWindowHandle
If Not hCHMWnd.Equals(IntPtr.Zero) Then '...
Paul ~~~~ Microsoft MVP (Visual Basic)
-
Oct 4th, 2017, 12:37 PM
#18
Junior Member
Re: is it possible to open a chm file in a mdichild window
Originally Posted by Mike Storm
Hi, i had a look on to pclement code and it works with Option Explicit OFF and with Option Explicit On you will have to change for this:
The point is that the mdichild opens far left and far to the top hiding it, and you will need to swich the mdiparent from Maximazed to Normal or from normal to maximized to see the scrool bars.
So you will need to find out a way to set the child location if you want it to be correctly displyed in the mdi parent form center.
You could also simply call
Code:
Me.LayoutMdi(MdiLayout.Cascade)
Paul ~~~~ Microsoft MVP (Visual Basic)
-
Oct 4th, 2017, 12:40 PM
#19
Hyperactive Member
Re: is it possible to open a chm file in a mdichild window
Yeap, thats another option... i wasn't making a critic, i was just alerting him that the window did open in the mdi container, he just didnt see it couse of its location.
Last edited by Mike Storm; Oct 4th, 2017 at 12:50 PM.
-
Oct 4th, 2017, 12:54 PM
#20
Re: is it possible to open a chm file in a mdichild window
This is the simplest way, using just one API function...
Code:
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("user32")> Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'directly from the mdiForm
Dim proc As Process = Process.Start("C:\Windows\Help\mui\0409\cliconf.chm")
proc.WaitForInputIdle()
SetParent(proc.MainWindowHandle, Me.Handle)
Dim frm As New Form2
frm.MdiParent = Me
frm.Show()
End Sub
End Class
Code:
Imports System.Runtime.InteropServices
Public Class Form2
<DllImport("user32")> Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'from a child form
Dim proc As Process = Process.Start("C:\Windows\Help\mui\0409\sqlsoldb.chm")
proc.WaitForInputIdle()
SetParent(proc.MainWindowHandle, Me.Parent.Handle)
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 4th, 2017, 12:59 PM
#21
Thread Starter
Addicted Member
Re: is it possible to open a chm file in a mdichild window
when i run it all the time the chm file is opening on top with all scenario's, only thing i think it can be is my mdichild is created as newMDIChild
Also the code provided by .Paul
Last edited by zubenubie; Oct 4th, 2017 at 01:27 PM.
-
Oct 4th, 2017, 01:42 PM
#22
Re: is it possible to open a chm file in a mdichild window
Originally Posted by zubenubie
when i run it all the time the chm file is opening on top with all scenario's, only thing i think it can be is my mdichild is created as newMDIChild
Also the code provided by .Paul
It's opening as any child window. Do you want to open it as the back-most window?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 4th, 2017, 01:48 PM
#23
Thread Starter
Addicted Member
Re: is it possible to open a chm file in a mdichild window
no, sorry i meant the chm file is not opening in a mdi window just on top of the application, just like when you normally attached a help file.
i am wondering maybe it is easier to create an own html file reader with a layout as help in a window form.
-
Oct 4th, 2017, 01:59 PM
#24
Re: is it possible to open a chm file in a mdichild window
My code worked when I tested it. It looks like the SetParent call isn't being executed. Can you post your exact declaration for the SetParent API?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 4th, 2017, 02:03 PM
#25
Re: is it possible to open a chm file in a mdichild window
Actually, there are other possible causes. We'll need to see the code you're using that isn't working...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 4th, 2017, 02:13 PM
#26
Thread Starter
Addicted Member
Re: is it possible to open a chm file in a mdichild window
I think that is where you are right. my MDI container is frmMain and in the set parent there is a new one made
This code is coming from the mdiChild
Code:
Public Class Manual
<DllImport("user32")> Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
End Function
Private Sub Manual_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim proc As Process = Process.Start("D:\Documenten\CW ISM\CW ISM.chm")
proc.WaitForInputIdle()
SetParent(proc.MainWindowHandle, Me.Parent.Handle)
End Sub
End Class
-
Oct 4th, 2017, 02:26 PM
#27
Junior Member
Re: is it possible to open a chm file in a mdichild window
Originally Posted by .paul.
This is the simplest way, using just one API function...
No, you need more than one API function call to do this correctly. You are setting the HTML Help window to be a child of the main window of the MDI form. That would put it on the same level as the Toolstrip, Menustrip, StatusStrip and mdiclient child windows, etc. You need to get the mdiclient child window, which is the parent of all MDI child windows, and set that to be the parent of the HTML Help window. This is how my code works.
You may want to run Spy++ to see how the MDI windows are related to one another.
Paul ~~~~ Microsoft MVP (Visual Basic)
-
Oct 4th, 2017, 02:50 PM
#28
Re: is it possible to open a chm file in a mdichild window
The only problem i can find is that the chm windows don't behave as proper MDI child forms. They open within the MDI form, but don't work properly with the zOrder of the forms. By that I mean that they don't come to the front when clicked on, and they don't fall back to the back when another child form is clicked on. My guess now is that you need to go back to hosting the chm in a form that is a child form...
As pclement said, but you don't need the FindWindow calls IMO.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 4th, 2017, 03:07 PM
#29
Thread Starter
Addicted Member
Re: is it possible to open a chm file in a mdichild window
I have done it now like this the chm file is opening full page in the MDI container
Code:
Code:
ublic Class Manual
Private Const WM_SYSCOMMAND As Integer = 274
Private Const SC_MAXIMIZE As Integer = 61488
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 Sub Manual_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim proc As Process
proc = Process.Start("D:\Documenten\CW ISM\CW ISM.chm")
WindowState = FormWindowState.Maximized
proc.WaitForInputIdle()
SetParent(proc.MainWindowHandle, frmMain.Handle)
SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
End Sub
But indeed the menu bar of the parent is covered by the chm file
-
Oct 4th, 2017, 04:21 PM
#30
Junior Member
Re: is it possible to open a chm file in a mdichild window
Originally Posted by zubenubie
I have done it now like this the chm file is opening full page in the MDI container
...
But indeed the menu bar of the parent is covered by the chm file
Yes, because you can't use the main window of the MDI form - you need to get the MDI client window, which is a child of the main MDI window. I will post my code again with comments:
Code:
Dim htmlHelpProcess As System.Diagnostics.Process = System.Diagnostics.Process.Start("C:\Users\...\Documents\Visual Studio Projects\My VB.NET Projects\Code Examples VB\packages\WiX.3.9.2.1\tools\doc\WiX.chm")
System.Threading.Thread.Sleep(500)
'Get main window handle of HTML Help process
Dim hCHMWnd As IntPtr = htmlHelpProcess.MainWindowHandle
If Not hCHMWnd.Equals(IntPtr.Zero) Then
'Change attributes of HTML Help process window to child
SetWindowLong(hCHMWnd, GWL_STYLE, (GetWindowLong(hCHMWnd, GWL_STYLE) Or WS_CHILD))
SetWindowLong(hCHMWnd, GWL_EXSTYLE, (GetWindowLong(hCHMWnd, GWL_EXSTYLE) Or WS_EX_MDICHILD))
'Get main window handle of MDI window
Dim hMDIWnd As IntPtr = FindWindowEx(Me.Handle, 0, vbNullString, vbNullString)
Dim hMDIClientWnd As IntPtr = 0
If Not hMDIWnd.Equals(IntPtr.Zero) Then
'Enumerate child windows of main MDI window to find the MDI client window
Do Until hMDIWnd.Equals(IntPtr.Zero)
hMDIWnd = FindWindowEx(Me.Handle, hMDIWnd, vbNullString, vbNullString)
If Not hMDIWnd.Equals(IntPtr.Zero) Then
'Check the window class of the child window to see if it's MDI client
Dim className As New System.Text.StringBuilder("", 256)
Call GetClassName(hMDIWnd, className, 256)
If className.ToString.Contains("MDICLIENT") Then
'OK, we've found the MDI client child window of the MDI form
hMDIClientWnd = hMDIWnd
Exit Do
End If
End If
Loop
If Not hMDIClientWnd.Equals(IntPtr.Zero) Then
'Set the parent of the HTML Help window to the MDI client window
SetParent(hCHMWnd, hMDIClientWnd)
End If
End If
End If
'Cascade the MDI windows
Me.LayoutMdi(MdiLayout.Cascade)
Here is a picture of how the MDI windows are related:
Paul ~~~~ Microsoft MVP (Visual Basic)
-
Oct 5th, 2017, 03:49 AM
#31
Thread Starter
Addicted Member
Re: is it possible to open a chm file in a mdichild window
@pclement
I have put your last code in the MDIcontainer menu item click event, and now it is working. i have done this with previous codes from everybody aswel and none were working very strange.
Thanks all for the advice and help
-
Oct 5th, 2017, 07:23 AM
#32
Junior Member
Re: is it possible to open a chm file in a mdichild window
Originally Posted by zubenubie
@pclement
I have put your last code in the MDIcontainer menu item click event, and now it is working. i have done this with previous codes from everybody aswel and none were working very strange.
Thanks all for the advice and help
Cool! Not strange if you understand how it works. :-)
Paul ~~~~ Microsoft MVP (Visual Basic)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|