//------------------------------------------------------------------------------------------------------ // ProcessMessages.pkg written by Christian Berkhout & originally posted in the VDF Open Source NG Sept. 14, 2004 // Usage: // Send ProcessMessages //Often put in DoAdvance of a ProgressBar (see below) // ProcessMessageKey Function added 05/30/2007 by Garret Mott - to get a Keypress. // When used in a tight loop, this allows the user to press a key to stop the process // Most of what I did was unabashedly stolen from Christian's code! // Example of use (taken from a ProgressBar): //Procedure DoAdvance // Integer iAnswer // Boolean bInput // Forward Send DoAdvance // Get ProcessMessageKey to bInput // If (bInput) Begin // Move (YesNo_Box("Stop Now?")) to iAnswer // If (iAnswer=MBR_Yes) Set pbStopNow to True // Else Set pbStopNow to False // End // Send ProcessMessages //optional - but always put it AFTER the above, as this empties the message queue! //End_Procedure //------------------------------------------------------------------------------------------------------ Define PM_REMOVE for 1 //Below added by GM for use in ProcessMessageKey Function Define PM_NOREMOVE for 0 TYPE tMsg Field tMsg.hwnd as HANDLE Field tMsg.message as INTEGER Field tMsg.wParam as INTEGER Field tMsg.lParam as INTEGER Field tMsg.time as DWORD Field tMsg.pt as POINTER END_TYPE // The PeekMessage function dispatches incoming sent messages, checks the thread message queue for a posted message, and retrieves the message (if any exist). External_Function PeekMessage "PeekMessageA" user32.dll ; Handle lpMsg Handle hWnd Integer wMsgFilterMin Integer wMsgFilterMax Integer wRemoveMsg ; Returns Integer // The TranslateMessage function translates virtual-key messages into character messages. The character messages are posted to the calling thread's message queue, to be read the next time the thread calls the GetMessage or PeekMessage function. External_Function TranslateMessage "TranslateMessage" user32.dll ; Handle lpMsg ; Returns Integer // The DispatchMessage function dispatches a message to a window procedure. It is typically used to dispatch a message retrieved by the GetMessage function. External_Function DispatchMessage "DispatchMessageA" user32.dll ; Handle lpMsg ; Returns Integer //Gets type of Message (Key or Mouse) used in ProcessMessageKey External_Function GetInputState "GetInputState" user32.dll Returns Integer Function ProcessMessage Returns Boolean Boolean bMessageFound bTemp Pointer lpMsg Integer iPendingMessage String sMsg ZeroType tMsg To sMsg GetAddress of sMsg To lpMsg Move (FALSE) To bMessageFound If (PeekMessage(lpMsg, 0, 0, 0, PM_REMOVE)) Begin GetBuff From sMsg at tMsg.message To iPendingMessage If (iPendingMessage = WM_PAINT) Begin Move (TRUE) To bMessageFound Move (TranslateMessage(lpMsg)) To bTemp Move (DispatchMessage(lpMsg)) To bTemp End End Function_Return bMessageFound End_Function Procedure ProcessMessages Boolean bMessageProcessed Move (TRUE) To bMessageProcessed While (bMessageProcessed) Get ProcessMessage To bMessageProcessed Loop End_Procedure // Added 05/30/2007 Garret Mott - Returns True if a key was pressed (but not if mouse was moved) // Change the 256 & 264 to zeroes if you wish to capture mouse movement as well. // Note that thiscaptures movement - not clicks! Function ProcessMessageKey Returns Boolean Boolean bMessageFound bTemp Pointer lpMsg Integer iPendingMessage iState String sMsg ZeroType tMsg To sMsg GetAddress of sMsg To lpMsg Move (FALSE) To bMessageFound If (PeekMessage(lpMsg, 0, 256, 264, PM_NOREMOVE)) Begin GetBuff From sMsg at tMsg.message To iPendingMessage If (iPendingMessage <> WM_PAINT) Begin Move (TRUE) To bMessageFound Move (TranslateMessage(lpMsg)) To bTemp Move (DispatchMessage(lpMsg)) To bTemp End End Function_Return bMessageFound End_Function