VC 显示红绿灯

void CTest_AllDlg::state(int xID, int color)
{
CRect conRect;
CWnd *pWnd=GetDlgItem(xID);//在图象控件中设圆形状态指示灯
CDC *pDC=pWnd->GetDC();
::GetClientRect(pWnd->m_hWnd,conRect);
CBrush NewBrush((COLORREF)color);//指示灯为color色
CBrush *pOldBrush=pDC->SelectObject(&NewBrush);
pDC->SetViewportOrg(conRect.right/2,conRect.bottom/2);
pDC->Ellipse(-22,-22,22,22);
pDC->SelectObject(pOldBrush); 
pWnd->ReleaseDC(pDC);

}

void CTest_AllDlg::OnButton1() 
{
state(IDC_G1,0x000FF0);//red
state(IDC_G2,0x00FF00);//green
}

VC 显示红绿灯_第1张图片

出自《案例解说VC++典型控制应用》


你可能感兴趣的:(VC 显示红绿灯)