say I have shelled an instance of the command prompt and I want that to show on my form. Another programmer told me that I need to use a picture box on the form, get the handle of the shelled program, then place the program in the picture box.
Not sure how to do this. I can't find how to get the handle of a particular window with .net and I'm unclear on how to "place" said window in the picture box. I've looked all over my msdn and here at this forum and couldn't find anything helpful. could someone give me a hand?
Declare Function SetParent Lib "user32.dll" (ByVal hWndChild As Integer, ByVal hWndNewParent As IntPtr) As Integer
SetParent (" the other app's hwnd " , " your form's hwnd ")
you dont have to use a picturebox btw.
~ if a post is resolved, please mark it as [Resolved] protected string get_Signature(){return Censored;} [vbcode][php] please use code tags when posting any code [/php][/vbcode]
thats great! now, about getting the hwnd of the shelled app? do I need a loop to search all open windows running and search somehow for the string (for example) "cmd"?
Console.WriteLine(pr.ProcessName & " it's handle is: " & pr.MainWindowHandle.ToInt32)
[color=blue]Next[/color]
~ if a post is resolved, please mark it as [Resolved] protected string get_Signature(){return Censored;} [vbcode][php] please use code tags when posting any code [/php][/vbcode]
' Console.WriteLine(pr.ProcessName & " it's handle is: " & pr.MainWindowHandle.ToInt32)
'Next
End Sub
ok, so far, so good. the one thing that's stumping me is the setparentf() the last argument is of type system.intptr and there's not a lot of info on that. (I put '0' just to have something there)
if you put the process's window handle with .ToInt32() and your form's handle like this .. Me.Handle
for example , once you have your window's handle...
VB Code:
Dim hwnd As Integer = " your process's handle .ToInt32()
SetParent(hwnd , Me.Handle)
~ if a post is resolved, please mark it as [Resolved] protected string get_Signature(){return Censored;} [vbcode][php] please use code tags when posting any code [/php][/vbcode]
~ if a post is resolved, please mark it as [Resolved] protected string get_Signature(){return Censored;} [vbcode][php] please use code tags when posting any code [/php][/vbcode]
I'd like to thank dynamic_sysop for his help on this project I've been working on. I've run up on anothe problem though. I've got the extra window to dock within a picture box (so I could seperate it from other things) and I would like to be able to maximize the window so It's nice and pretty. I'm attaching a picture so what I'm trying to get across is easier. Does anyone know where I should start looking in the msdn to solve this problem?
i've got the shell command edited to do the maximize ,(winappstyle.maximizefocus) and it does maximize it but it's not exactly staying put. I'd like the shelled window to take up the entire allocated space and make it so the user can't move it. If anyone has any information as to where in the msdn I could look, that would be greate.
Not exactly the easiest thing to do.. I tried something similar before when i was trying to make a bittorrent download manager... You could look for an api to remove the titlebar from the window or something like that, but I've found all this messing around with setparent, and other api's is kind of an unreliable way of making things...
instead, maybe try looking at this from a different perspective? How about emulating your own console? by this i mean, just put a textbox down and run the commands in a console behind the scenes, and put the results in the textbox..
I don't know exactly how to, but i believe there is some way to get into a command line window and get the contents in there... you may want to look around for that...
alternatively i think there is some way to 'bounce' the results from a command line that you shell into a text file... IO Redirect i think it may be referred to as... Basically it consists of adding an extra parameter to the command line... so you could shell this:
"netstat -n > C:\NetstatResults.txt"
That should print out the results into the specified file.. it works here, just tested when i'm in the cmd... so you should be able to get it working as shelling a new process...
that's exactly how this project started I thought it would be neat to have the command prompt available to the user for familiarity plus, if there are commands they want to use, they can simply use the prompt. I know a guy who has done something similar but did it in vb6. I may have to resort to either older commands or doing what you suggested. This is only a "for fun" project. Something to learn by, ya know? I'll post my code when I finally figure it out though!!!