1. 用画笔画个圆形:
#define WHITE_CIRCLE RGB(255, 255, 255)
#define PINK_CIRCLE RGB(255, 0, 255)
#define GREEN_CIRCLE RGB(0, 255, 0)
#define RED_CIRCLE RGB(255, 0, 0)
void CMFCcodeDlg::DrawCircle(int nIdc, int nColor)
{
CClientDC dc(this);
CPen pen(PS_SOLID, 3, nColor);
dc.SelectObject(&pen);
CBrush *pBrush = new CBrush(nColor);
dc.SelectObject(pBrush);
CRect rect;
((CEdit*)GetDlgItem(nIdc))->GetWindowRect(rect);
ScreenToClient(rect);
//dc.Ellipse(rect.right - 150, rect.top - 150, rect.right, rect.top);
dc.Ellipse(rect.right+10, rect.top, rect.right+10+(rect.bottom - rect.top), rect.bottom);
if (pBrush)
{
delete pBrush;
pBrush = NULL;
}
}
DrawCircle(IDC_EDIT_IMEI, WHITE_CIRCLE);
2. 有个问题需要处理,这种画笔画完后移动窗口或者最小化后,会消失,所以得再处理一下:
使用消息 WM_ACTIVATE 的 onActivate()
void CMFCcodeDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CDialogEx::OnActivate(nState, pWndOther, bMinimized);
// TODO: 在此添加消息处理程序代码和/或调用默认值
DrawCircle(IDC_EDIT_SCAN_CODE, WHITE_CIRCLE);
}