[MFC] Menu(2)
“Picture” 프로그램 수정
1. Doc에 enum 형의 멤버변수 m_Type 추가
초기치 - 가운데 보기
2. Menu 추가
화면 설정 - 가운데 보기/전체 보기/타일 보기
3. 각 menu 항목에 command handler 추가
4. 타일 보기 구현
OnDraw 수정
for(int y=0; y <= rect.bottom; y += bm.bmHeight)
for(int x=0; x <= rect.right; x += bm.bmWidth)
pDC->BitBlt(x,y,bm.bmWidth,bm.bmHeight,&memDC,
0,0,SRCCOPY);
5. 전체보기 구현
OnDraw 수정
pDC->StretchBlt(0,0,rect.right,rect.bottom,&memDC,
0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
class CPictureDoc : public CDocument
{
……
public:
enum type{CENTER,TILE,FULL};
type m_Type;
};
void CPictureDoc::OnScreenCenter()
{
if(m_Type != CENTER)
{
m_Type=CENTER;
UpdateAllViews(NULL);
}
}
void CPictureDoc::OnScreenFull()
{
if(m_Type != FULL)
{
m_Type=FULL;
UpdateAllViews(NULL);
}
}
void CPictureDoc::OnScreenTile()
{
if(m_Type != TILE)
{
m_Type=TILE;
UpdateAllViews(NULL);
}
}
void CPictureView::OnDraw(CDC* pDC)
{
CPictureDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CDC memDC;
CBitmap MyBit,*pOldBit;
BITMAP bm;
MyBit.LoadBitmap(IDB_TOTO);
MyBit.GetObject(sizeof(BITMAP),&bm);
memDC.CreateCompatibleDC(pDC);
pOldBit=memDC.SelectObject(&MyBit);
CRect rect;
GetClientRect(rect);
switch(pDoc->m_Type)
{
case CPictureDoc::CENTER :
{ int x=(rect.right-bm.bmWidth)/2;
int y=(rect.bottom-bm.bmHeight)/2;
pDC->BitBlt(x,y,bm.bmWidth,bm.bmHeight,&memDC,0,0,SRCCOPY);
}
break;
case CPictureDoc::TILE :
{
for(int y=0; y <= rect.bottom; y += bm.bmHeight)
for(int x=0; x <= rect.right; x += bm.bmWidth)
pDC->BitBlt(x,y,bm.bmWidth,bm.bmHeight,&memDC,0,0,SRCCOPY);
}
break;
case CPictureDoc::FULL :
pDC->StretchBlt(0,0,rect.right,rect.bottom,&memDC,0,0,
bm.bmWidth,bm.bmHeight,SRCCOPY);
break;
}
memDC.SelectObject(pOldBit);
}
'IT Note > 기타언어' 카테고리의 다른 글
[C#] 1. C#의 개요 (0) | 2008.12.13 |
---|---|
[MFC] Menu(1) (0) | 2008.11.24 |
[MFC] Font (0) | 2008.11.24 |