I am currently developing a program (C++ Win32, Visual Studio 2012) that captures audio signals from a microphone, computes a Fourier Transformation (you know, to get the frequencies in the audio) in another thread, and finally plots the results on a screen.
Everything works fine, except for the plotting, so this is a GUI related topic.
In WndProc, I get a message when a buffer is full and ready to be processed, and I call
boost::thread t(&ComputationThread,data);
to start the computation thread.
At the end of ComputationThread I send a message to the GUI thread to plot the data, using a predefined fixed value and the data pointer as arguments:
SendMessage(hWnd, WM_PAINT, PARAM_FFT_COMPUTED, (LPARAM)data);
This works fine as well, I get the message and I can also write the computed data to a file, however, drawing on the form (e.g. using SetPixel) has no effect, while it has an effect when wParam is not PARAM_FFT_COMPUTED, for example when the form is resized.
InvalidateRecthas no effect either.
What am I doing wrong?
Thanks in advance!
You are not meant to send the
WM_PAINT. It’s a specially synthesised message. You never post it or send it. Instead you callInvalidateRector one of the related functions to get the system to generateWM_PAINT.And you are not meant to draw on a window outside of a
WM_PAINTmessage handler. Or from a thread other than the GUI thread. Perhaps you aren’t doing any of those things, but they are common mistakes so it doesn’t hurt to mention it.If
InvalidateRectdoes not work then something fundamental is wrong with your code. You need to fix that rather than try to make painting work by some other mechanism.So, the solution is to use
InvalidateRectand fix whatever is broken in yourWM_PAINThandler. Without seeing yourWM_PAINThandler I would not like to speculate as to what is wrong.