InvertRect works fine till PeekMessage, etc. put into loop
Posted: Wed Jun 07, 2006 6:01 pm
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.
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
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