PDA

View Full Version : VB Help!



Leebo
11-12-2004, 03:06 PM
Hi all. I'm currently using VB 6.0 to make a GUI and I need to bring an external DOS Command prompt into focus after clicking a button on my form.

Basically, I have Form1 which has a Receive button and a stop button. The Recieve button opens up a command prompt with a certain parameter. I need to Stop button to bring the command prompt into focus, and then send a <ctrl> + C + y + <enter>. I have no problem with the sendkey function but i have problems getting the cmd prompt into focus.

Help is much apprecited :)

BS
11-15-2004, 05:38 AM
You'll need to declare the findWindow and setForegroundWindow api calls:

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long

Then in your command button click:

Dim lHandel As Long
lHandle = FindWindow("ConsoleWindowClass", vbNullString)
lHandle = SetForegroundWindow(lHandle)