Hi Robert -
Regarding the constants:
Yes - you can add theese particular constants together instead for "or"-ing
them. Every constant is a binary "switch"
&H1 ==> sets bit 0 high, &H2 ==> sets bit 1 high ... , &H1 + &H2 = &H3 =
binary 0011 (bit 0 and 1 is set high).
None of the constants are setting more than one particular bit, so adding
and "or"-ing the constants are equivalent in this case.
Regarding the "pHandles" argument in the MsgWaitForMultipleObjects function:
It's a array of handle identifiers (A handle is an (32 bit unsigned long)
identifier for a window in MS-Windows)
You can't simply transfer af constant 0. So declare a dummy variable
Dim dummy as integer
dummy = 0
... MsgWaitForMultipleObjects(0, dummy, 0, timeRemaining, QS_ALLINPUT) > 0
A search on Google reveals that the MsgWaitForMultipleObjects function
monitors one or more MS-Windows "windows" for specified events.
What _I_ can't understand is: what's happening when you specify _no_ windows
identifiers ?? . But all the vb examples found using Google are setting
phandles = 0 (meaning no handles in the phandles array) .. strange ..
Anyway, Here is a functioning example of using the MsgWaitForMultipleObjects
function from MapBasic...
(push any key inside 5 seconds after starting the MapBasic program..)
++++++++++++++++++++++
DEFINE QS_KEY &H1
DEFINE QS_MOUSEMOVE &H2
DEFINE QS_MOUSEBUTTON &H4
DEFINE QS_POSTMESSAGE &H8
DEFINE QS_TIMER &H10
DEFINE QS_PAINT &H20
DEFINE QS_SENDMESSAGE &H40
DEFINE QS_HOTKEY &H80
DEFINE QS_MOUSE (QS_MOUSEMOVE + QS_MOUSEBUTTON)
DEFINE QS_INPUT (QS_MOUSE + QS_KEY)
DEFINE QS_ALLEVENTS (QS_INPUT + QS_POSTMESSAGE + QS_TIMER + QS_PAINT +
QS_HOTKEY)
DEFINE QS_ALLINPUT (QS_SENDMESSAGE + QS_PAINT + QS_TIMER + QS_POSTMESSAGE +
QS_MOUSEBUTTON + QS_MOUSEMOVE + QS_HOTKEY + QS_KEY)
declare Function MsgWaitForMultipleObjects Lib "user32" (ByVal nCount As
Integer, pHandles As Integer, ByVal fWaitAll As Integer, ByVal
dwMilliseconds As Integer, ByVal dwWakeMask As Integer) As Integer
declare Sub Main
declare Sub MsgWait(ByVal ms As Integer)
Sub MsgWait(ByVal ms As Integer)
Dim dummy as integer, i As Integer
Dummy = 0
i = MsgWaitForMultipleObjects (0, dummy, 0, ms, QS_KEY)
note ("return value = " + i)
END SUB
sub main
call msgwait (5000) '5 sec
end sub
regards
Bo Thomsen
GeoConsult I/S
-----Oprindelig meddelelse-----
Fra: Robert Crossley [mailto:[EMAIL PROTECTED]
Sendt: 17. maj 2004 02:29
Til: MapInfo List
Emne: MI-L Wait Function
Hi all,
Still having some trouble with a function on XP, and an associate
suggested that the problem may be helped by pausing the program to allow
?buffers to be flushed? before going onto the next operation (the exact
description of the potential problem was on the assembly code side of
where I am comfortable working).
Anyway, he suggested the sleep function does not help as there is a
problem with sleep on XP, and I don't want to pause the execution of
MapInfo, but rather just stop moving on until MapInfo had caught up. The
following VB code was given as an option, and while most of it is fairly
easy to convert (eg. Private Const -> DEFINE), I am having trouble working
out how to call the MsgWaitForMultipleObjects function. It is failing in
MapBasic as the define functions don't work with constants which use the
Or in them (understandable as it just substitutes the text). I am getting
a compile error when calling
If MsgWaitForMultipleObjects(0, 0, 0, timeRemaining, QS_ALLINPUT) > 0
Then
End If
Has anyone implemented this function in MapBasic? or is there an
alternative? I want to pause MapInfo from processing the next operation
while allowing it to finish what it was doing.
r
Original VB code
Private Const QS_KEY = &H1
Private Const QS_MOUSEMOVE = &H2
Private Const QS_MOUSEBUTTON = &H4
Private Const QS_POSTMESSAGE = &H8
Private Const QS_TIMER = &H10
Private Const QS_PAINT = &H20
Private Const QS_SENDMESSAGE = &H40
Private Const QS_HOTKEY = &H80
Private Const QS_MOUSE = (QS_MOUSEMOVE Or QS_MOUSEBUTTON)
Private Const QS_INPUT = (QS_MOUSE Or QS_KEY)
Private Const QS_ALLEVENTS = (QS_INPUT Or QS_POSTMESSAGE Or QS_TIMER Or
QS_PAINT Or QS_HOTKEY)
Private Const QS_ALLINPUT = (QS_SENDMESSAGE Or QS_PAINT Or QS_TIMER Or
QS_POSTMESSAGE Or QS_MOUSEBUTTON Or QS_MOUSEMOVE Or QS_HOTKEY Or QS_KEY)
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Declare Function MsgWaitForMultipleObjects Lib "user32" (ByVal
nCount As Long, pHandles As Long, ByVal fWaitAll As Long, ByVal
dwMilliseconds As Long, ByVal dwWakeMask As Long) As Long
' *********************************************************
' * MsgWait
' *
' * Sleeps for a specified time but allows
' * events to process immediately
' *
' * Input: ms - milliseconds to wait
' * Output: none
' *********************************************************
Public Sub MsgWait(ByVal ms As Long)
Dim start As Long, timeRemaining As Long, timeNow As Long
start = GetTickCount()
timeRemaining = ms
Do
' Sleep until timeout or event occurs
MsgWaitForMultipleObjects 0, 0, 0, timeRemaining, QS_ALLINPUT
timeNow = GetTickCount()
If timeNow - start >= timeRemaining Then
Exit Sub
ElseIf timeNow < start Then
' Handle GetTickCount 49.7 day wrap around
start = timeNow
End If
timeRemaining = timeRemaining - (timeNow - start)
start = timeNow
DoEvents
Loop
End Sub
Converted to Mapinfo
'DEFINES for the Wait function
DEFINE QS_KEY = &H1
DEFINE QS_MOUSEMOVE = &H2
DEFINE QS_MOUSEBUTTON = &H4
DEFINE QS_POSTMESSAGE = &H8
DEFINE QS_TIMER = &H10
DEFINE QS_PAINT = &H20
DEFINE QS_SENDMESSAGE = &H40
DEFINE QS_HOTKEY = &H80
DEFINE QS_MOUSE = (QS_MOUSEMOVE Or QS_MOUSEBUTTON)
DEFINE QS_INPUT = (QS_MOUSE Or QS_KEY)
DEFINE QS_ALLEVENTS = (QS_INPUT Or QS_POSTMESSAGE Or QS_TIMER Or QS_PAINT
Or QS_HOTKEY)
DEFINE QS_ALLINPUT = (QS_SENDMESSAGE Or QS_PAINT Or QS_TIMER Or
QS_POSTMESSAGE Or QS_MOUSEBUTTON Or QS_MOUSEMOVE Or QS_HOTKEY Or QS_KEY)
Sub MsgWait(ByVal ms As Integer)
'-----------------------
'Written By: RC
'-----------------------
Dim start As Integer
Dim timeRemaining As Integer
Dim timeNow As Integer
'Set up general error handler
ONERROR GOTO ErrorHandler
Print "Waiting " + ms + " milliseconds."
start = GetTickCount()
timeRemaining = ms
Do
' Sleep until timeout or event occurs
If MsgWaitForMultipleObjects(0, 0, 0, timeRemaining, QS_ALLINPUT) > 0
Then
End If
timeNow = GetTickCount()
If timeNow - start >= timeRemaining Then
Exit Sub
ElseIf timeNow < start Then
' Handle GetTickCount 49.7 day wrap around
start = timeNow
End If
timeRemaining = timeRemaining - (timeNow - start)
start = timeNow
'DoEvents
Loop
EXIT SUB
ErrorHandler:
CALL ErrorMessage("MsgWait")
END SUB 'ProForma
--
Robert Crossley
Agtrix P/L
9 Short St
PO Box 63
New Brighton 2483
Far Southern Queensland
AUSTRALIA
153.549004 E 28.517344 S
P: 02 6680 1309
F: New Connection
M: 0419 718 642
E: [EMAIL PROTECTED]
W: www.agtrix.com
W: www.wotzhere.com
---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 11772
---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 11778