Hi Dominic & Peter
We use a dialog box with OK button like thus
Sub BAT_CONTROL
dim CLICK_OK1 as logical
dialog title "Running Batch File"
width 150 height 50
calling RUN_BATCH 'Used for program control
control listbox
position 5, 15 width 65 height 35
title ""
value 1
id 1
control OKbutton
title "OK"
position 100, 15
control Cancelbutton
title "Cancel"
position 100, 35
CLICK_OK1 = commandinfo(cmd_info_dlg_ok) 'Used for program control
if CLICK_OK1 then
end if
end sub 'BAT_CONTROL
' ***** and ****
Sub RUN_BATCH
' We have several statements that write input file used by the DOS
program here
run program _MODEL_PATH+"runbat.bat" 'runbat.bat runs a DOS program
alter control 1 title "Binary Files Made"
end sub 'RUN_BATCH
We have DOS window positioned so that it covers the dialog window so
when the dialog appears user clicks Ok
And our MAPBASIC code continues to run
We figured this out in version 3 or 4 and so far nothing has come along
that has made worth while to recode
I watched cpu percentage in the process window of Task Manager and
couldn't detect any cpu cycles going to MAPINFO process until the ok was
clicked
HTH
Harold
-----Original Message-----
From: Dominic Lowe [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 16, 2004 2:26 AM
To: 'Doyle, Peter W'
Cc: [EMAIL PROTECTED]
Subject: RE: MI-L Mapbasic & Windows API question
Hi Peter,
I have a method using the FindWindow API that works for a batch file but
with anything more complicated (e.g a VB program with events etc) it's
not that good due to the two applications demanding processing power.
However if you are just running a batch file it might work for you.
The code works by looking for a handle on the cmd window. Unfortunately
this means that the Mapinfo thread repeatedly calls the API call, which
has a performance hit. However it might be okay for what you need.
Note the code loops twice - first loop looks for the cmd window. 2nd
window keeps looping till the cmd window has closed (batch file has run)
'the api declaration is:
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Integer
'the code is:
Dim intAppRunning as integer
Dim ClassName, Title, Batch as string
Batch = 'path to your .bat file here
ClassName = "ConsoleWindowClass"
Title = "C:\WINNT\System32\cmd.exe" ' NT/2000 version
'or use ' XP version...: Title = "C:\WINDOWS\System32\cmd.exe" 'you
can probably search your system for these values if you prefer
' first run your batch program - called by path/filename
Run Program Batch
'Calls Win32 API: Waits for Batch to finish running
Do
intAppRunning = FindWindow(ClassName, Title)
' handle is 0 till it is found
Print "Getting Window Handle ..."
Loop While intAppRunning = 0
Do
intAppRunning = FindWindow(ClassName, Title)
' handle is > 0 till batch stops running
Print "Running Batch..."
Loop While intAppRunning > 0
Print "Batch finished"
Note to list: Does anyone have a better (less looping..??) method that
doesn't rely on making repeated API calls?
Cheers,
Dominic
-----Original Message-----
From: Doyle, Peter W [mailto:[EMAIL PROTECTED]
Sent: 16 March 2004 04:52
To: [EMAIL PROTECTED]
Subject: MI-L Mapbasic & Windows API question
Greetings List,
I am running a windows batch file from within Mapbasic.
Does anybody know of a Windows API call that will return an error level
code when a batch file has finished running in the command window.
What I am trying to do is have the Mapbasic code wait till the batch
file has finished running and then continue on, as it is relies on the
output of the batch file to exist before continuing.
I remember seeing something about a Tick timer somewhere, but this is
probably not the solution as the time the batch file takes to run can
vary considerably fom toime to time.
Any help appreciated as allways
Regards
Peter Doyle
Geographical Analysis & Data
Telstra, Mobile Network Services
Service Management
ph: 07 38871128
fax: 07 32364383
Level 4
171 Roma Street Brisbane 4000
[EMAIL PROTECTED]
---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 10881
---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 10887
---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 10948