However, Case 2 which inverts a rectangle and is called from within the loop, while it works fine without PeekMessage/DispatchMessage. misfires on the first call when Peek/Dispatch are inserted into the loop. Instead of turning black when I call ClickOn, it turns black the first time I call ClickOff then black when I call ClickOn--which is backwards.
Code: Select all
Procedure Playback() ;Not the real procedure
  Repeat
      DoLotsOfStuff()
      MidiSendClickOn()
      MidiSendClickOff()
      PeekMessage_(@structMsg, hwndMain, 0, 0, #PM_REMOVE)
      DispatchMessage_(@structMsg)
      
      DoMoreStuff()
  Until FinishedPlaying
Endprocedure
Procedure MidiSendClickOn()
  Protected hndDC
  
  Select gTypeOfClick
  Case 1 ; works fine
    midiOutShortMsg_(hmidiOut, ClickOnMsg)
  Case 2 ; Works fine without Peek/Dispatch, misfires the first time with Peek/Dispatch inserted into the playback loop.
    hndDC = GetDC_(hbtnPressure)
    InvertRect_(hndDC, @rctPressure)
    ReleaseDC_(hbtnPressure, hndDC)
  EndSelect
EndProcedure
Procedure MidiSendClickOff()
  Protected hndDC
  Select gTypeOfClick
  Case 1
    midiOutShortMsg_(hmidiOut, ClickOffMsg)
  Case 2
    hndDC = GetDC_(hbtnPressure)
    InvertRect_(hndDC, @rctPressure)
    ReleaseDC_(hbtnPressure, hndDC)
    
  EndSelect
EndProcedure
Cheers, Jon
