Drawing wavepattern to window

Hi all,
Im using the LineTo() method to draw the wave pattern of a wave file to my window, and ive come across a few problems....

First of all, i want it in a scrollable groupbox, or something similar...

Second, i need the lines to stay if i minimize the app (right now, they dissapear when it minimizes!!)


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

For the first, you will need to implement a scrollable window.  Are you using MFC?

For the Second, you probably need to change the way you are dong things.  I'd guess that right now you simply get a DC of the window and start using LineTo as the data comes it.   But what you need to do is record all of those x,y coordinates so that you can draw the lines later.

Then you need to implement a WM_PAINT procedure for the window.  Whenever called, it needs to draw all of the lines.

This is a funcamental facet of Windows programs -- it is how it is possible to drag windows around without messing up the windows that are partly covered.  Each of those windows is repeatedly drawing itself -- in its entirety.  And you will need to do the same thing.

When you get the WM_PAINT message, the DC passed to you will have a "clipping region" set.  So imagine that some other app's window is covering part of your wave window... you will draw the whole thing, but all of the commands to draw where the other window is covering you will be ignored ("clipped").

Finally, you're scollable wave window might be able to show just a few seconds of a five-minute wave file.  So, you will need to keep track of what portion of the wave is currently visible and when asked, via WM_PAINT, to display it, you will need to start at a certain location in the wave and draw all of the lines up until you know that a line will not be visible.

-- Dan

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Excalibur81Author Commented:
ok that helps heaps!!

so i would make an array of points, and use the PolylineTo() method to draw the array?
i guess this would be the sensible way to do it...

regarding the clipping region stuff...
im creating my groupbox, and giving its handle the name hGroupbox..
i then call HDC dc = GetDC(hGroupbox);
but the wave draws past the groupbox onto the main window..
i guess this has somthing to do with clipping regions right>? so how do i tell the app to only draw in the groupbox?

regarding the last comment,
would i use ScrollWindowEx to say scroll a groupbox, and perhaps have a trackbar below the groupbox to adjust the postion of 'scroll'? So effectivly, im not actually drawing the entire wave, but just the part that the trackbar says to view...

hope you can understand this gibberish!!


Excalibur81Author Commented:
oh, and btw, im not sure if im using mfc or not...

sorry, i only started c++ programming 2 weeks ago...

im using a 3rd party compiler called devc++ , and it doesnt have any gui to add buttons etc to the prog, i have to do it all in code...

this probably means nothing...... :P

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

A GroupBox control is actually just a type of STATIC control.  Like most controls, its window class includes the style bit CS_PARENTDC.  What that means is that when you request its DC, you actually get the DC of the Window in which it resides.  That's why ypu can draw outside of it.  You need to limit where you draw, or create a clipping region and use SelectClipRgn (or use GetDcEx and pass in a clipping region) if you want the GDI system to automatically clip your output.

There is a lot to learn and, alas!, I can't teach it all to you.  You need to get your hands on a good book.  The best is Charles Petzold's "Programming Windows"

-- Dan
Excalibur81Author Commented:
Hey thanks youve been heaps of help!!

Just one more q...

im using the following :
     HRGN region = CreateRectRgn(20, 250, 600, 250);

but when i test for dc == NULL, it always comes up true, and so my drawing isnt working anymore...

hwnd is the handle of my parent window...

if i pass '0' as the first param , the drawing goes to the desktop, (proving the rest of my method works ok...) and if i pass hGroupbox (handle of my Group box), it comes up null as well....

so whats going on???
I don't kniow why you get an error.  Most common reason is that the hwnd parameter is wrong.  If you're sure that's ok, try it with different or no flag parameters.

As with all errors, you can call GetLastError to obtain additional info.  You can use the VC++ menu command Tools/Error Lookup and type in the error value to get some info.

-- Dan
Excalibur81Author Commented:
hmm, well i already tried it with no flags, and im sure hwnd is right cause its passed straight from the wndProc!!

ok, ill have a fiddle anyways, but the points go to you!
Excalibur81Author Commented:
i found out why, its cause i needed to set the style of my winclass to either CS_CLASSDC, CS_OWNDC or CS_PARENTDC

thanx for the help!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.