Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Can a timer run while another application is running under VB?

Posted on 1998-08-06
4
Medium Priority
?
202 Views
Last Modified: 2010-05-03
I have a single word speech-recognizer running under Visual Basic 5.0. The word to be recognized should be spoken within a 3 seconds interval. By means of a timer, I would like to tell the user that the speech recognizer is recording and waiting for a word. How can the speech recognizer and the timer run in the same time? Can I use any ActiveX timer control?
0
Comment
Question by:jpf080698
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Expert Comment

by:alamo
ID: 1468091
Is there a reason you can't use the standard timer control built into VB5? That timer utilizes the standard Windows timer messages, which should be independent of what is happening in your speech recognition. When the timer expires your timer event will get triggered even if an ActiveX control or another program has the focus.

Hope this helps!
0
 

Author Comment

by:jpf080698
ID: 1468092
I could use the VB-timer as you said, but there is still a problem to solve:

the progression bar of the timer can't progress as long as the speech recognizer has the focus. How could I get the speech recognition and the progression bar run simultaneously?
0
 
LVL 9

Accepted Solution

by:
cymbolic earned 400 total points
ID: 1468093
You can create a separate task that will report to you when it is complete.  I don't believe you really need the timer control, since you want to continually update a progress bar.  It would probably be better to set an ending time when you start the process, periodically check current time and use that interval to update your progress meter, using doevents in between to pass control back to the operating system.  Here's how you'd spawn another task that gives control back to your original app, so you can continue to run other tings, yet still be notified when the spawned app completes:

Option Explicit
Private Const SYNCHRONIZE = &H100000
Private Const INFINITE = &HFFFF           '  Infinite timeout
Private Const DEBUG_PROCESS = &H1
Private Const DEBUG_ONLY_THIS_PROCESS = &H2

Private Const CREATE_SUSPENDED = &H4

Private Const DETACHED_PROCESS = &H8

Private Const CREATE_NEW_CONSOLE = &H10

Private Const NORMAL_PRIORITY_CLASS = &H20
Private Const IDLE_PRIORITY_CLASS = &H40
Private Const HIGH_PRIORITY_CLASS = &H80
Private Const REALTIME_PRIORITY_CLASS = &H100

Private Const CREATE_NEW_PROCESS_GROUP = &H200

Private Const CREATE_NO_WINDOW = &H8000000

Private Const WAIT_FAILED = -1&
Private Const WAIT_OBJECT_0 = 0
Private Const WAIT_ABANDONED = &H80&
Private Const WAIT_ABANDONED_0 = &H80&
Private Const WAIT_TIMEOUT = &H102&

Private Const SW_SHOW = 5

Private Type PROCESS_INFORMATION
        hProcess As Long
        hThread As Long
        dwProcessId As Long
        dwThreadId As Long
End Type

Private Const STARTF_USEPOSITION = &H4
Private Const STARTF_USESIZE = &H2

Private Type STARTUPINFO
        cb As Long
        lpReserved As String
        lpDesktop As String
        lpTitle As String
        dwX As Long
        dwY As Long
        dwXSize As Long
        dwYSize As Long
        dwXCountChars As Long
        dwYCountChars As Long
        dwFillAttribute As Long
        dwFlags As Long
        wShowWindow As Integer
        cbReserved2 As Integer
        lpReserved2 As Long
        hStdInput As Long
        hStdOutput As Long
        hStdError As Long
End Type

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CreateProcessBynum Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDirectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function WaitForInputIdle Lib "user32" (ByVal hProcess As Long, ByVal dwMilliseconds As Long) As Long
Public Sub CreateProcess(prc$)
    Dim res&, ShellPgm$
    Dim sinfo As STARTUPINFO
    Dim pinfo As PROCESS_INFORMATION
    On Error GoTo prcerr
    sinfo.cb = Len(sinfo)
    sinfo.lpReserved = vbNullString
    sinfo.lpDesktop = vbNullString
    sinfo.lpTitle = vbNullString
    sinfo.dwFlags = 0
    ShellPgm$ = prc$ + Chr$(0)
    sinfo.dwFlags = STARTF_USEPOSITION + STARTF_USESIZE
    sinfo.dwX = 20 + FMigWiz.Left \ 14
    sinfo.dwY = 150 + FMigWiz.Top \ 14
    sinfo.dwXSize = FMigWiz.Width \ 14
    sinfo.dwYSize = (FMigWiz.Height \ 14) - 100
    res = CreateProcessBynum(vbNullString, ShellPgm$, 0, 0, True, NORMAL_PRIORITY_CLASS, ByVal 0&, vbNullString, sinfo, pinfo)
    If res Then
     ' Let the process initialize
     Call WaitForInputIdle(pinfo.hProcess, INFINITE)
     ' We don't need the thread handle
     Call CloseHandle(pinfo.hThread)
     Do
        res = WaitForSingleObject(pinfo.hProcess, 0)
        If res <> WAIT_TIMEOUT Then
            ' No timeout, app is terminated
            Exit Do
        End If
        DoEvents
     Loop While True
     ' Kill the last handle of the process
     Call CloseHandle(pinfo.hProcess)
    End If
Exit Sub

prcerr:
 errit "Error Starting " + prc$
End Sub

0
 
LVL 6

Expert Comment

by:alamo
ID: 1468094
Why can't the progression bar of the timer progress as long as the speech recognizer has the focus? Lots of VB apps work this way, whether a separate process or not.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question