程序中有这么一段:COLORREF crfColor = ::GetSysColor( COLOR_3DFACE ) ;
.....后面,要通过这个取得的颜色来擦出所描绘出来的秒针指针。if ( smTime2.wMinute != s_nPreMinute ) //分针改变了。
{
DrawHand( hdc , 200 , 8 , s_nPreHour * 30 + s_nPreMinute * 0.5 , crfColor ) ;
}draw函数为:
void DrawHand( HDC hdc , int nLength , int nWidth , double dDegrees , COLORREF clrColor)
{
// 角度与弧度的转化 double dRadian = dDegrees * 0.0174533 ; // 计算坐标 , 这里的角度是从 12 点 向 3点方向移动的。 POINT pt[2] ; pt[0].x = (int)( nLength * sin (dRadian) ) ; // 移动方向要注意,角度是于Y轴正方向的夹角 pt[0].y = (int)( nLength * cos (dRadian ) ); pt[1].x = -pt[0].x / 5 ; // 这是后面的露出的部分
pt[1].y = -pt[0].y / 5 ; // 画笔 HPEN hpen = ::CreatePen( PS_SOLID , nWidth , clrColor ) ; // 大多为传入的参数 HPEN hOrgPen = (HPEN)::SelectObject( hdc , hpen); // 选入 // 画线 ::MoveToEx( hdc , pt[0].x , pt[0].y , NULL);
::LineTo ( hdc , pt[1].x , pt[1].y );
::SelectObject( hdc , hOrgPen) ; // 恢复
::DeleteObject( hpen) ; // 删除}这里,我调用函数后,发现还是不能实现擦出的效果。我想问题主要应该取决于取得背景颜色的函数方面。
COLORREF crfColor = ::GetSysColor( COLOR_3DFACE ) ; 这里的用法对不对呢?或者说参数传入的有问题,哪位能够解答一下。
.....后面,要通过这个取得的颜色来擦出所描绘出来的秒针指针。if ( smTime2.wMinute != s_nPreMinute ) //分针改变了。
{
DrawHand( hdc , 200 , 8 , s_nPreHour * 30 + s_nPreMinute * 0.5 , crfColor ) ;
}draw函数为:
void DrawHand( HDC hdc , int nLength , int nWidth , double dDegrees , COLORREF clrColor)
{
// 角度与弧度的转化 double dRadian = dDegrees * 0.0174533 ; // 计算坐标 , 这里的角度是从 12 点 向 3点方向移动的。 POINT pt[2] ; pt[0].x = (int)( nLength * sin (dRadian) ) ; // 移动方向要注意,角度是于Y轴正方向的夹角 pt[0].y = (int)( nLength * cos (dRadian ) ); pt[1].x = -pt[0].x / 5 ; // 这是后面的露出的部分
pt[1].y = -pt[0].y / 5 ; // 画笔 HPEN hpen = ::CreatePen( PS_SOLID , nWidth , clrColor ) ; // 大多为传入的参数 HPEN hOrgPen = (HPEN)::SelectObject( hdc , hpen); // 选入 // 画线 ::MoveToEx( hdc , pt[0].x , pt[0].y , NULL);
::LineTo ( hdc , pt[1].x , pt[1].y );
::SelectObject( hdc , hOrgPen) ; // 恢复
::DeleteObject( hpen) ; // 删除}这里,我调用函数后,发现还是不能实现擦出的效果。我想问题主要应该取决于取得背景颜色的函数方面。
COLORREF crfColor = ::GetSysColor( COLOR_3DFACE ) ; 这里的用法对不对呢?或者说参数传入的有问题,哪位能够解答一下。
{
// 对窗口的位置加以判断
if ( ::IsIconic( hwnd) ) // IsIconic , 判断是否为最小化
return 0 ;
// 取得系统时间
SYSTEMTIME smTime2;
::GetLocalTime( & smTime2 );
// 建立坐标系
HDC hdc = ::GetDC( hwnd ) ;
::SetIostropic( hdc , s_cxClient , s_cyClient ) ; // 这里的变量,其初始值在哪里呢?
// 此时,当前窗口的背景色是 COLOR_3DFACE ,如果以此色来为背景,则擦出指针
COLORREF crfColor = ::GetSysColor( COLOR_3DFACE ) ;
// 如果分针改变,就擦出时针和分针。
if ( smTime2.wMinute != s_nPreMinute ) //分针改变了。
{
DrawHand( hdc , 200 , 8 , s_nPreHour * 30 + s_nPreMinute * 0.5 , crfColor ) ;
// 分针 ,1分钟,6度
DrawHand( hdc , 350 , 5 , s_nPreMinute * 6 , crfColor ) ;
s_nPreHour = smTime2.wHour ;
s_nPreMinute = smTime2.wMinute ;
}
if ( smTime2.wSecond != s_nPreSecond ) // 秒针改变了, 重画所有。
{
// 擦出秒针
DrawHand( hdc , 400 , 3 , s_nPreSecond * 6 , crfColor ) ;
// 重绘所有
DrawHand( hdc , 400 , 3 , smTime2.wSecond * 6 , RGB (16 , 90 , 245) ) ;
DrawHand( hdc , 200 , 8 , smTime2.wHour * 30 + smTime2.wMinute * 0.5 , RGB ( 255, 35 ,0) ) ;
DrawHand( hdc , 350 , 5 , smTime2.wMinute * 6 , RGB( 0 , 200 , 5) ) ;
s_nPreSecond = smTime2.wSecond ; // 只把秒改变
}
return 0 ;
}这里是擦除代码,大家审审。顺便问一下:你们发代码的时候那种很标准的格式是怎么弄出来的?