VISUAL C++ 2008 MFC 윈도우 프로그래밍 247p 3번
Programming/MFC 2012. 2. 16. 11:13 |
void CFontTestView::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect Rect(m_BtnRect);
CPen xpPen(PS_SOLID,1,RGB(0,0,0));
CPen nullPen(PS_NULL,0,RGB(0,0,0));
CPen* pOldPen = dc.SelectObject(&xpPen);
CBrush xpBrush(RGB(245,245,245));
CBrush xpBrush2(RGB(210,210,210));
CBrush xpBrush_UP(RGB(70,200,255));
CBrush xpBrush_DOWN(RGB(255,180,100));
CBrush xpBrush_SHD(RGB(250,250,250));
CBrush* pOldBrush = dc.SelectObject(&xpBrush);
dc.SelectObject(&xpBrush_SHD);
dc.Rectangle(Rect);
if(m_bOn) {
if(m_bClicked) {
dc.SelectObject(&xpBrush_DOWN);
dc.RoundRect(&m_BtnRect,CPoint(5,5));
dc.SelectObject(&nullPen);
dc.SelectObject(&xpBrush2);
Rect += CRect(-3, -3, -2, -2);
dc.Rectangle(Rect);
}
else {
dc.SelectObject(&xpBrush_UP);
dc.RoundRect(&m_BtnRect,CPoint(5,5));
dc.SelectObject(&nullPen);
dc.SelectObject(&xpBrush);
Rect += CRect(-3, -3, -2, -2);
dc.Rectangle(Rect);
}
}
else {
dc.RoundRect(&Rect,CPoint(5,5));
}
//반환
dc.SelectObject(pOldPen);
dc.SelectObject(pOldBrush);
}
{
if(m_BtnRect.PtInRect(point))
{
// 플래그를 토글하고 윈도우를 다시 그림
m_bClicked = !m_bClicked;
RedrawWindow(&m_BtnRect);
}
CView::OnLButtonDown(nFlags, point);
}
void CFontTestView::OnLButtonUp(UINT nFlags, CPoint point)
{
if(m_bClicked)
{
// 플래그를 토글하고 윈도우를 다시 그림
m_bClicked = !m_bClicked;
RedrawWindow(&m_BtnRect);
}
CView::OnLButtonUp(nFlags, point);
}
void CFontTestView::OnMouseMove(UINT nFlags, CPoint point)
{
if(m_BtnRect.PtInRect(point))
{
m_bOn = TRUE;
RedrawWindow(&m_BtnRect);
}
else
{
m_bOn = FALSE;
RedrawWindow(&m_BtnRect);
}
CView::OnMouseMove(nFlags, point);
}
그라디언트도 못했고 코드도 댑따 길어졌지만, 어쨌든 버튼 완성.
'Programming > MFC' 카테고리의 다른 글
CString를 char*로 바꾸기 (0) | 2012.04.25 |
---|---|
자식윈도우 Z-order 문제 (2) | 2012.03.30 |
RedrawWindow() (0) | 2012.02.13 |
OnPaint() (0) | 2012.02.13 |
0x8000 (0) | 2012.02.10 |