// Dlg.h
CBrush m_normal_brush, m_small_brush;
CImage m_normal_image, m_small_image, m_mem_view;
int m_radius = 10;
int m_alpha = 0;
int m_is_clicked = 0;
BOOL CMFCApplication2Dlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// μ΄ λν μμμ μμ΄μ½μ μ€μ ν©λλ€. μμ© νλ‘κ·Έλ¨μ μ£Ό μ°½μ΄ λν μμκ° μλ κ²½μ°μλ
// νλ μμν¬κ° μ΄ μμ
μ μλμΌλ‘ μνν©λλ€.
SetIcon(m_hIcon, TRUE); // ν° μμ΄μ½μ μ€μ ν©λλ€.
SetIcon(m_hIcon, FALSE); // μμ μμ΄μ½μ μ€μ ν©λλ€.
// TODO: μ¬κΈ°μ μΆκ° μ΄κΈ°ν μμ
μ μΆκ°ν©λλ€.
m_normal_image.Load(L"normal_image.png");
m_small_image.Load(L"small_image.png");
CRect win_rect, client_rect;
GetWindowRect(win_rect);
GetClientRect(client_rect);
CBitmap * p_bmp = CBitmap::FromHandle(m_normal_image);
m_normal_brush.CreatePatternBrush(p_bmp);
p_bmp = CBitmap::FromHandle(m_small_image);
m_small_brush.CreatePatternBrush(p_bmp);
int w_fix = win_rect.Width() - client_rect.Width();
int h_fix = win_rect.Height() - client_rect.Height();
SetWindowPos(NULL, 0, 0, m_small_image.GetWidth()+ w_fix, m_small_image.GetHeight()+ h_fix, SWP_NOMOVE);
SetBackgroundColor(RGB(0, 0, 0));
m_mem_view.Create(m_small_image.GetWidth(), m_small_image.GetHeight(), 32);
return TRUE; // ν¬μ»€μ€λ₯Ό 컨νΈλ‘€μ μ€μ νμ§ μμΌλ©΄ TRUEλ₯Ό λ°νν©λλ€.
}
void CMFCApplication2Dlg::OnMouseMove(UINT nFlags, CPoint point)
{
CClientDC dc(this);
CDC * p_dc = CDC::FromHandle(m_mem_view.GetDC());
p_dc->FillSolidRect(0, 0, m_small_image.GetWidth(), m_small_image.GetHeight(), RGB(0, 0, 0));
m_small_image.AlphaBlend(*p_dc, 0, 0, m_alpha);
CBrush * p_old_brush;
if (m_is_clicked) {
p_dc->SetBrushOrg(point.x * (-1), point.y * (-1));
p_old_brush = p_dc->SelectObject(&m_normal_brush);
}
else {
p_dc->SetBrushOrg(0, 0);
p_old_brush = p_dc->SelectObject(&m_small_brush);
}
p_dc->Ellipse(point.x - m_radius, point.y - m_radius, point.x + m_radius, point.y + m_radius);
p_dc->SelectObject(p_old_brush);
if (m_is_clicked) {
CPen grid_pen(PS_DOT, 1, RGB(160, 160, 160));
CPen * p_old_pen = p_dc->SelectObject(&grid_pen);
p_dc->SetBkMode(TRANSPARENT);
p_dc->MoveTo(point.x, point.y - m_radius);
p_dc->LineTo(point.x, point.y + m_radius);
p_dc->MoveTo(point.x - m_radius, point.y);
p_dc->LineTo(point.x + m_radius, point.y);
p_dc->SelectObject(p_old_pen);
}
m_mem_view.ReleaseDC();
m_mem_view.Draw(dc, 0, 0);
// CDialogEx::OnMouseMove(nFlags, point);
}
void CMFCApplication2Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
m_is_clicked = 1;
SetCapture();
OnMouseMove(nFlags, point);
CDialogEx::OnLButtonDown(nFlags, point);
}
void CMFCApplication2Dlg::OnLButtonUp(UINT nFlags, CPoint point)
{
m_is_clicked = 0;
ReleaseCapture();
OnMouseMove(nFlags, point);
CDialogEx::OnLButtonUp(nFlags, point);
}
BOOL CMFCApplication2Dlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
int old_radius = m_radius;
if (zDelta > 0) {
// ν μ λ―Έλ κ²
if(m_radius >= 20) m_radius -= 10;
if (nFlags & MK_CONTROL) {
m_alpha -= 10;
if (m_alpha <= 0) m_alpha = 0;
}
}
else {
// ν μ λΉκΈ°λ κ²
if(m_radius < 100) m_radius += 10;
if (nFlags & MK_CONTROL) {
m_alpha += 10;
if (m_alpha >= 255) m_alpha = 255;
}
}
if (old_radius != m_radius) {
POINT pos;
GetCursorPos(&pos);
ScreenToClient(&pos);
OnMouseMove(0, pos);
}
return CDialogEx::OnMouseWheel(nFlags, zDelta, pt);
}