I know you've had someone work out your Windows API function problem, but I wanted to make sure that you knew that, depending upon what you were doing, you might have been able to accomplish the same thing without it.
Since you didn't state what you wanted MapInfo to catch up doing, I figured I should put this out there and let people react to it. MapBasic contains an "Update Window" command which makes it process all of the Windows messages sent to a particular window before returning control to the program. The syntax is Update Window <window_id> where window_id is the integer value of an open Map, Browser, Graph, or Layout window. It can also be a variable containing such a value. Update Window is useful in handlers where you need to make the user see something in a window before the program goes ahead an does something else. Update Window does have its limitations, but you don't have to guess at a magical constant time to wait, either. Hope this helps Spencer -----Original Message----- From: Robert Crossley [mailto:[EMAIL PROTECTED] Sent: Sunday, May 16, 2004 8:29 PM To: MapInfo List Subject: 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: 11785
