Results 1 to 8 of 8

Thread: placing a window inside of form

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    placing a window inside of form

    I am writing a program to grab information from the cmd prompt and would like the command prompt window to show inside of my form in a nice squared-away box instead of the command prompt window popping up on it's own. How is this accomplished? I've looked at MS knowledge base and don't really know what it is I need to look for. I've tried OLE but I think that's the wrong way about it.

    any suggestions?

  2. #2
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    Well im not sure, but someone posted some code here the other day to place Notepad in a form, maybe you could modify it for the command prompt. Here was the code:

    VB Code:
    1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
    2. Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
    3. Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    4. Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
    5. Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
    6. Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
    7. Private Declare Function GetDesktopWindow Lib "user32" () As Long
    8. Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
    9. Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
    10. Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
    11. Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
    12. Const GW_HWNDNEXT = 2
    13. Dim mWnd As Long
    14. Function InstanceToWnd(ByVal target_pid As Long) As Long
    15.     Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long
    16.     'Find the first window
    17.     test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
    18.     Do While test_hwnd <> 0
    19.         'Check if the window isn't a child
    20.         If GetParent(test_hwnd) = 0 Then
    21.             'Get the window's thread
    22.             test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)
    23.             If test_pid = target_pid Then
    24.                 InstanceToWnd = test_hwnd
    25.                 Exit Do
    26.             End If
    27.         End If
    28.         'retrieve the next window
    29.         test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
    30.     Loop
    31. End Function
    32. Private Sub Form_Load()
    33.     'KPD-Team 1999
    34.     'URL: [url]http://www.allapi.net/[/url]
    35.     'E-Mail: [email][email protected][/email]
    36.     Dim Pid As Long
    37.     'Lock the window update
    38.     LockWindowUpdate GetDesktopWindow
    39.     'Execute notepad.Exe
    40.     Pid = Shell("c:\windows\notepad.exe", vbNormalFocus)
    41.     If Pid = 0 Then MsgBox "Error starting the app"
    42.     'retrieve the handle of the window
    43.     mWnd = InstanceToWnd(Pid)
    44.     'Set the notepad's parent
    45.     SetParent mWnd, Me.hwnd
    46.     'Put the focus on notepad
    47.     Putfocus mWnd
    48.     'Unlock windowupdate
    49.     LockWindowUpdate False
    50. End Sub
    51. Private Sub Form_Unload(Cancel As Integer)
    52.     'Unload notepad
    53.     DestroyWindow mWnd
    54.     'End this program
    55.     TerminateProcess GetCurrentProcess, 0
    56. End Sub

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    well, that's close to what I want but in the case of notepad, I need it to be "embedded" in the form so that it will be sized to a particular dimesion and it will be part of the form so when the main form is moved, notepad moves with it.

  4. #4
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    Yeah, i also needed that. But thats the code i got

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    well, it's a start!! we'll figure it out eventually.

  6. #6
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    yeah, let me know if you get it working

  7. #7
    well to scale the notepad or what ever try this:

    VB Code:
    1. Private Sub Form_Resize()
    2. text1.Move 0,0,Me.Scalewidth,Me.Scaleheight
    3. End Sub

    as for a window in a window try using a mdi form then using mdi childs for the inside forms.
    a 17 year old kid who has nothing better to do !
    and i never said i was right !!!

  8. #8
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    BeholderOf:

    well to scale the notepad or what ever try this:
    VB Code:
    1. Private Sub Form_Resize()
    2. text1.Move 0,0,Me.Scalewidth,Me.Scaleheight
    3. End Sub

    That wont work for notepad, because you need to get hold of its handle

Posting Permissions

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



Click Here to Expand Forum to Full Width