?
Solved

Drawing wavepattern to window

Posted on 2003-02-27
8
Medium Priority
?
239 Views
Last Modified: 2010-04-01
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!!)

Regards,

Robert
0
Comment
Question by:Excalibur81
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 600 total points
ID: 8038858
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
0
 

Author Comment

by:Excalibur81
ID: 8039615
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!!

Cheers,
Robert

0
 

Author Comment

by:Excalibur81
ID: 8039622
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

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 49

Expert Comment

by:DanRollins
ID: 8040253
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
0
 

Author Comment

by:Excalibur81
ID: 8041024
Hey thanks youve been heaps of help!!

Just one more q...

im using the following :
     HRGN region = CreateRectRgn(20, 250, 600, 250);
     dc = GetDCEx(hwnd, region, DCX_LOCKWINDOWUPDATE | DCX_CLIPCHILDREN);


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???
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8043429
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
0
 

Author Comment

by:Excalibur81
ID: 8045192
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!
0
 

Author Comment

by:Excalibur81
ID: 8045221
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!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question