Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

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!!)

Regards,

Robert
0
Excalibur81
Asked:
Excalibur81
  • 5
  • 3
1 Solution
 
DanRollinsCommented:
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
 
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!!

Cheers,
Robert

0
 
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

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
DanRollinsCommented:
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
 
Excalibur81Author Commented:
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
 
DanRollinsCommented:
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
 
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!
0
 
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!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now