InvertRect works fine till PeekMessage, etc. put into loop

Windows specific forum
jonljacobi
User
User
Posts: 67
Joined: Mon Jan 16, 2006 10:12 pm

InvertRect works fine till PeekMessage, etc. put into loop

Post by jonljacobi »

I'm using the following bit of code to simulate a metronome in a playback procedure. The user can select between a midi drumstick sound and a flashing box. The playback procedure is a closed loop and I'm trying to use PeekMessage and DispatchMessage so that users can access the menu, stop playback with the keyboard and mouse, etc. As far as that goes, they work fine. Case 1 always works fine.

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

Obviously, something is being intercepted but I don't know what. This is a Windows misstep on my part as it does the same thing in other languages. Anyone know what I'm doing wrong?

Cheers, Jon :?:
jonljacobi
User
User
Posts: 67
Joined: Mon Jan 16, 2006 10:12 pm

Post by jonljacobi »

Unspeakably dumb. It was invoking the redraw which was erasing the initial invert.

Sorry, Jon
Post Reply