Your approach to drawing this clock looks a bit haphazard. I assume your infinite 'while' loop where you're drawing the clock hand is nested in a WM_PAINT message block, yeah? If so, you need to get away from that; when you enter that while loop, no other Windows messages will be processed, which will give you much heartache later on.
An ideal approach for your situation might involve implementing something like the SetTimer function, which is detailed very nicely in the MSDN article located
here. There are probably more accurate ways of tracking the time, but this may suit your purposes just right.
If you do implement the above approach, the general idea would be to trigger a repaint message every second which updates the clock, and in your WM_PAINT message block you would place the paint methods that you have and just simply paint the clock (with no 'while' loop). You only need to paint once per second (or however frequently your clock updates), as the paint buffer will maintain what was painted last until something else gets painted atop what you already have. If you need more help with this, let me know.
Finally, to specify line color and width, you will need to implement pens. HPENs, actually. Here's a quick demonstration of how to use a pen, with an explanation just below:
// create the pen, during some initialization process somewhere;// the following will create a solid-stroke pen, width 5, colored redHPEN myPen = ::CreatePen(PS_SOLID, 5, RGB(255, 0, 0));// later, during your painting...// select new pen and store the old penHGDIOBJ oldPen = ::SelectObject(hdc, myPen);// here, you would draw some lines, with LineTo and MoveToEx...// restore the old pen::SelectObject(hdc, oldPen);oldPen = NULL;
The code that directly answers your question involves the
CreatePen method. With it, you can set a pen's style, width, and color.
The bit about storing the old pen and then restoring it after you're done painting is more of a good coding habit to get into, rather than some necessity. By storing the old pen and restoring it afterwards, you're maintaining what the previous pen is, which may need to be used later on by some process. If you don't restore the default pen in Windows applications, for instance, some odd painting consequences can arise. Something to consider in your programming journeys.
Also, when posting large amounts of code, it's helpful to the readers if you enclose your code within source tags, like so: [ source ] _code_here_ [ /source ] (except without any spaces between the brackets).
[Edited by - Omega147 on May 24, 2007 4:24:35 PM]