how to open external SW (like notepad) inside VB??-VBForums
Results 1 to 4 of 4

Thread: how to open external SW (like notepad) inside VB??

  1. #1

    Thread Starter
    Member stingran's Avatar
    Join Date
    Dec 2004
    Posts
    58

    Red face how to open external SW (like notepad) inside VB??

    Hi

    i have a frame on the form, and with a click on a button i would like to
    open the notepad (or wordpad) INTO this frame.
    i know how to open an external SW, but not to "merge" it in VB.

    thanks

  2. #2
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,363

    Re: how to open external SW (like notepad) inside VB??

    If you are just playing with Text Files...just use a TextBox..??

    You can read textFiles into them easily...

    (Why mess with notepad if you dont need to)
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,135

    Re: how to open external SW (like notepad) inside VB??

    You'd have to use few api functions such SetParent and others:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
    4.                 (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
    5. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    6.                 (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
    7. Private Declare Function GetParent Lib "user32" _
    8.                 (ByVal hwnd As Long) As Long
    9. Private Declare Function SetParent Lib "user32" _
    10.                 (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    11. Private Declare Function GetWindowThreadProcessId Lib "user32" _
    12.                 (ByVal hwnd As Long, lpdwProcessId As Long) As Long
    13. Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
    14. Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
    15. Private Declare Function GetDesktopWindow Lib "user32" () As Long
    16. Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
    17. Private Declare Function TerminateProcess Lib "kernel32" _
    18.                 (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
    19. Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
    20. Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
    21.  
    22. Const GW_HWNDNEXT = 2
    23. Dim mWnd As Long
    24.  
    25. Public Sub OpenTextFile(strFile As String)
    26. '==========================================
    27. Dim Ret As Long
    28. Dim lngHWnd As Long
    29. Dim strBuffer As String
    30.  
    31.     'you may need to maximize your form and adjust frame's size as well
    32.     'Me.WindowState = vbMaximized
    33.     'Frame1.Move 0, 0, ...
    34.    
    35.     LockWindowUpdate GetDesktopWindow
    36.     strBuffer = Space(260)
    37.     Ret = FindExecutable(strFile, vbNullString, strBuffer)
    38.     If Ret > 32 Then
    39.         lngHWnd = Shell(Left$(strBuffer, InStr(strBuffer, Chr$(0)) - 1) & " " & strFile, vbNormalFocus)
    40.         mWnd = InstanceToWnd(lngHWnd)
    41.         SetParent mWnd, Frame1.hwnd
    42.     End If
    43.     LockWindowUpdate False
    44.  
    45. End Sub
    46.  
    47. Private Sub Command1_Click()
    48.     OpenTextFile "C:\Temp\test1.txt"
    49. End Sub

  4. #4
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,402

    Re: how to open external SW (like notepad) inside VB??

    Quote Originally Posted by stingran
    open the notepad (or wordpad) INTO this frame.
    You can 'embed' WordPad (amonst other things) into an OLE control.
    Add the OLE control (from the ToolBox) as you would, say, a TextBox.

    Note: Do your research, as the OLE control can be flakey at times as highlited by some users (posts on this forum).




    Bruce.
    Handy References:
    MSDN Library
    ADO Tutorial Excel Tutorial MZTools (VB6)

    • Please pull down the Thread Tools menu and click the 'Mark Thread Resolved' button, or alternately edit your original post and add "Resolved" or place a in the subject when your question(s) have been answered.
    • Please use code tags [highlight=vb] your code goes here between the tags [/highlight] when posting code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.