mfc_Dlg_Transparent - 8BitsCoding/RobotMentor GitHub Wiki

BOOL CMFCApplication2Dlg::OnInitDialog()
{
// ...
// ํน์ ์์ญ๋ง ํฌ๋ช
ํ ํด๋ณด์.
// SetLayeredWindowAttributes(RGB(255, 1, 7), 0, LWA_COLORKEY);
// ๋ค์ด์ผ๋ก๊ทธ์ RGB(255, 1, 7)๋ผ๋ ์์์ 0 (์์ ํฌ๋ช
)ํ๊ฒ ์์๊ธฐ์ค์ผ๋ก(LWA_COLORKEY) ๋ง๋ค์ด ๋ฌ๋ผ
// ๋ค์ด์ผ๋ก๊ทธ์ ๋ชจ๋ ์์ญ์ ํฌ๋ช
ํ ํด๋ณด์.
SetLayeredWindowAttributes(0, 100, LWA_ALPHA);
// ํฌ๋ช
๋ ๋ ์ธ์ง๋ 0 ~ 255 ์ฌ์ด
return TRUE; // ํฌ์ปค์ค๋ฅผ ์ปจํธ๋กค์ ์ค์ ํ์ง ์์ผ๋ฉด TRUE๋ฅผ ๋ฐํํฉ๋๋ค.
}
void CMFCApplication2Dlg::OnPaint()
{
CPaintDC dc(this); // ๊ทธ๋ฆฌ๊ธฐ๋ฅผ ์ํ ๋๋ฐ์ด์ค ์ปจํ
์คํธ์
๋๋ค.
if (IsIconic())
{
// ...
}
else
{
dc.FillSolidRect(10, 10, 200, 200, RGB(255, 1, 7));
// CDialogEx::OnPaint();
}
}
void CMFCApplication2Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
CClientDC dc(this);
dc.FillSolidRect(point.x - 10, point.y - 10, 20, 20, RGB(255, 1, 7));
CDialogEx::OnLButtonDown(nFlags, point);
}
void CMFCApplication2Dlg::OnRButtonDown(UINT nFlags, CPoint point)
{
// Layered ์์ฑ์ ์ค์๊ฐ์ผ๋ก ํ์ธ/์ ์ฉ ํ๊ณ ์ถ๋ค๋ฉด?
int wnd_style = ::GetWindowLong(m_hWnd, GWL_EXSTYLE);
if (!(wnd_style & WS_EX_LAYERED)) {
// Layered ์์ฑ์ด ์๋ผ์ด ์๋ค๋ฉด
::SetWindowLong(m_hWnd, GWL_EXSTYLE, wnd_style | WS_EX_LAYERED);
}
CDialogEx::OnRButtonDown(nFlags, point);
}