|
-
Nov 1st, 2003, 11:48 AM
#1
Thread Starter
Frenzied Member
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?
-
Nov 1st, 2003, 12:10 PM
#2
Supreme User
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:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
Const GW_HWNDNEXT = 2
Dim mWnd As Long
Function InstanceToWnd(ByVal target_pid As Long) As Long
Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long
'Find the first window
test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
Do While test_hwnd <> 0
'Check if the window isn't a child
If GetParent(test_hwnd) = 0 Then
'Get the window's thread
test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)
If test_pid = target_pid Then
InstanceToWnd = test_hwnd
Exit Do
End If
End If
'retrieve the next window
test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
Loop
End Function
Private Sub Form_Load()
'KPD-Team 1999
'URL: [url]http://www.allapi.net/[/url]
Dim Pid As Long
'Lock the window update
LockWindowUpdate GetDesktopWindow
'Execute notepad.Exe
Pid = Shell("c:\windows\notepad.exe", vbNormalFocus)
If Pid = 0 Then MsgBox "Error starting the app"
'retrieve the handle of the window
mWnd = InstanceToWnd(Pid)
'Set the notepad's parent
SetParent mWnd, Me.hwnd
'Put the focus on notepad
Putfocus mWnd
'Unlock windowupdate
LockWindowUpdate False
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Unload notepad
DestroyWindow mWnd
'End this program
TerminateProcess GetCurrentProcess, 0
End Sub
-
Nov 2nd, 2003, 02:56 AM
#3
Thread Starter
Frenzied Member
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.
-
Nov 2nd, 2003, 06:20 AM
#4
Supreme User
Yeah, i also needed that. But thats the code i got
-
Nov 2nd, 2003, 07:18 AM
#5
Thread Starter
Frenzied Member
well, it's a start!! we'll figure it out eventually.
-
Nov 2nd, 2003, 07:21 AM
#6
Supreme User
yeah, let me know if you get it working
-
Nov 2nd, 2003, 09:40 AM
#7
Member
well to scale the notepad or what ever try this:
VB Code:
Private Sub Form_Resize()
text1.Move 0,0,Me.Scalewidth,Me.Scaleheight
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 !!!
-
Nov 2nd, 2003, 12:34 PM
#8
Supreme User
BeholderOf:
well to scale the notepad or what ever try this:
VB Code:
Private Sub Form_Resize()
text1.Move 0,0,Me.Scalewidth,Me.Scaleheight
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|