C++实现仿Office风格的颜色选取框代码(5)
void CColorPicker::OnLButtonDown(long x, long y)
{
//POINT pt;
RECT rc;
//pt.x = x; pt.y = y;
//ClientToScreen(m_hwnd, &pt);
GetClientRect(m_hwnd, &rc);
//if (!PtInRect(&rc, pt))
if (x
PostMessage(m_hwnd, WM_CLOSE, 0, 0);
else
{
m_bMouseDown = true;
ReDraw(m_HotRow, m_HotCol, true);
}
}
void CColorPicker::OnLButtonUp(long x, long y)
{
m_bMouseDown = false;
ReDraw(m_HotRow, m_HotCol, true);
if (y>=5*18+10 && m_HotRow==5)
{
ShowWindow(m_hwnd, SW_HIDE);
CColorDialog * crDlg = new CColorDialog(m_Color, CC_FULLOPEN | CC_ANYCOLOR);
int nResult = crDlg->DoModal();
m_Color = crDlg->GetColor();
PostMessage(m_hwnd, WM_CLOSE, 0, 0);
}
else if (m_HotRow<5 && m_HotCol<8)
{
m_Color = ColorMap[m_HotRow][m_HotCol];
PostMessage(m_hwnd, WM_CLOSE, 0, 0);
}
}
void CColorPicker::OnMouseMove(long x, long y)
{
RECT rc;
GetClientRect(m_hwnd, &rc);
InflateRect(&rc, -2, -2);
if (x
{
if (m_HotRow != 255)
{
ReDraw(m_HotRow, m_HotCol, false);
m_HotRow = 255;
}
}
else
{
if (y>=5*18+10)
{
if (m_HotRow != 5)
{
ReDraw(m_HotRow, m_HotCol, false);
m_HotRow = 5;
ReDraw(5, 0, true);
}
}
else if (((byte)(y-2) / 18)!=m_HotRow || ((byte)(x-2) / 18)!=m_HotCol)
{
ReDraw(m_HotRow, m_HotCol, false);
m_HotRow = (byte)(y-2) / 18;
m_HotCol = (byte)(x-2) / 18;
ReDraw(m_HotRow, m_HotCol, true);
}
}
}





