Windows/MFC

GetColor 현재 위치에 색상 가져오기

aucd29 2013. 10. 2. 18:04
[code]void CPixelDlg::OnMouseMove(UINT nFlags, CPoint point)
{
    CClientDC dc(this);
    COLORREF color;
    color = dc.GetPixel(point);

    SetDlgItemInt(IDC_CORD_X, point.x);
    SetDlgItemInt(IDC_CORD_Y, point.y);

    SetDlgItemInt(IDC_RED_VALUE, GetRValue(color));
    SetDlgItemInt(IDC_GREEN_VALUE, GetGValue(color));
    SetDlgItemInt(IDC_BLUE_VALUE, GetBValue(color));

    CurrentPixelColor(color); // 현재 픽셀의 색상을 표시
    SendCurrentColor(color); // 폼 뷰에 현재 색상을 전달
    CDialog::OnMouseMove(nFlags, point);
}

void CPixelDlg::CurrentPixelColor(COLORREF color)
{
    CRect rc;
    CStatic* pFrame = (CStatic*)GetDlgItem(IDC_STATIC_COLOR);
    pFrame->GetClientRect(rc);

    CClientDC dc(pFrame);

    CBrush br(color);
    CBrush* pOld = dc.SelectObject(&br);
    dc.FillRect(rc, &br);
    dc.SelectObject(pOld);
}

void CPixelDlg::SendCurrentColor(COLORREF color)
{
    CRect rc;
    CStatic* pFrame =
        (CStatic*)(GetParentFrame()->GetActiveView()->GetDlgItem(IDC_FORM_COLOR));

    pFrame->GetClientRect(rc);
    CClientDC dc(pFrame);

    CBrush br(color);
    CBrush* pOld = dc.SelectObject(&br);
    dc.FillRect(rc, &br);
    dc.SelectObject(pOld);
}
[/code]