none
how to open word document within form in VB RRS feed

  • Question

  • Hi All

    how can i open word document within form , like this photo


    office 2007 

    Visual Studio 2013

    Thanks in advance

    Monday, September 22, 2014 6:02 AM

Answers

  • You need to use the Windows API to set the Form (Panel control) as the parent window of the app:

    Imports System.Runtime.InteropServices
    
    Public Class Form4
    
        <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
        Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInt32, ByVal wParam As Integer, ByVal lParam As Integer) As IntPtr
        End Function
    
        <DllImport("user32.dll", SetLastError:=True)> _
        Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
        End Function
    
        Private Const WM_SYSCOMMAND As Integer = &H112
        Private Const SC_MINIMIZE As Integer = &HF020
        Private Const SC_MAXIMIZE As Integer = &HF030
    
        Private Sub Form4_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    
            Dim p As Process = Process.Start(New ProcessStartInfo() With {.FileName = String.Concat(Application.StartupPath, "\ReadMe.docx"), .WindowStyle = ProcessWindowStyle.Minimized})
            System.Threading.Thread.Sleep(500)
            Dim value As IntPtr = SetParent(p.MainWindowHandle, ExcelPanel.Handle)
            SendMessage(p.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
    
        End Sub
    End Class


    Paul ~~~~ Microsoft MVP (Visual Basic)

    • Marked as answer by samehshams Tuesday, September 23, 2014 6:01 AM
    Monday, September 22, 2014 6:03 PM

All replies

  • how can i open word document within form , like this photo

    The procedure is documented here:
    http://support.microsoft.com/default.aspx?scid=kb;[LN];Q304643

    but i don't know whether that is different with newer versions, or creates the exact format you have posted. But worth trying.

    Monday, September 22, 2014 7:44 AM
  • Thanks Acamar 

    but the office button not appear , here is the result :

    Monday, September 22, 2014 8:20 AM
  • You need to use the Windows API to set the Form (Panel control) as the parent window of the app:

    Imports System.Runtime.InteropServices
    
    Public Class Form4
    
        <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
        Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInt32, ByVal wParam As Integer, ByVal lParam As Integer) As IntPtr
        End Function
    
        <DllImport("user32.dll", SetLastError:=True)> _
        Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
        End Function
    
        Private Const WM_SYSCOMMAND As Integer = &H112
        Private Const SC_MINIMIZE As Integer = &HF020
        Private Const SC_MAXIMIZE As Integer = &HF030
    
        Private Sub Form4_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    
            Dim p As Process = Process.Start(New ProcessStartInfo() With {.FileName = String.Concat(Application.StartupPath, "\ReadMe.docx"), .WindowStyle = ProcessWindowStyle.Minimized})
            System.Threading.Thread.Sleep(500)
            Dim value As IntPtr = SetParent(p.MainWindowHandle, ExcelPanel.Handle)
            SendMessage(p.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
    
        End Sub
    End Class


    Paul ~~~~ Microsoft MVP (Visual Basic)

    • Marked as answer by samehshams Tuesday, September 23, 2014 6:01 AM
    Monday, September 22, 2014 6:03 PM
  • Thanks Paul 


    Tuesday, September 23, 2014 6:02 AM
  • YOU SAVED MY LIFE<g class="gr_ gr_17 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation multiReplace" data-gr-id="17" id="17">....</g>THANK-YOU
    Saturday, June 23, 2018 5:42 PM