개발은 하는건가..

VC++ 윈도우가 Resize 될때 다시 그려야할 영역 얻기 본문

C, C++, MFC

VC++ 윈도우가 Resize 될때 다시 그려야할 영역 얻기

수동애비 2018. 10. 31. 16:38
반응형

MFC 프로그램을 만들때, 프로그램의 성능을 최적화 하기 위해서 화면의 전체를 그리지 않고, 그려야 하는 부분만 계산하여 다시 그리도록 하는 방법을 사용하고 있습니다. 이경우 일반적으로 CView 클래스의 onDraw() 함수안에서 GetClipBox() 함수를 사용하는데, 아시는지 모르겠지만, GetClipBox() 는 항상 윈도우의 전체 영역을 리턴하도록 되어 있습니다. 

왜냐하면 MFC로 만들어진 SDI의 경우 CView와 CFrameWnd가 CS_VREDRAW  CS_HREDRAW 속성을 가지고 있는 윈도우 클래스를 사용하기 때문입니다. 따라서, 윈도우가 리사이징 될때마다 항상 자신의 영역 전체를 다시 그리도록 되어 있는 것입니다. 따라서, 이 문제점을 해결하기 위해서는 CS_VREDRAW 와 CS_HREDRAW 속성을 가지고 있는 않는 윈도우 클래스를 정의하여야 합니다. 

방법은 다음과 같이 InitApplication() 함수안에서 새로운 클래스를 등록하고 PreCreateWindow() 함수에서 클래스의 이름을 사용하시면 됩니다. 


예제) 


class CTestApp : public CWinApp 
{ 
public: 
    CString m_strMyClassName; 
    ... 
} 


BOOL CTestApp::InitApplication() 
{ 
    // Register our own class with the same attributes as AfxFrameOrView" 
    // refer to MFC Tech Note 1: Window Class Registration for more 
    // information. 
    m_strMyClassName = AfxRegisterWndClass (0, ::LoadCursor (NULL, 
        IDC_ARROW), (HBRUSH)(COLOR_WINDOW+1), 
        LoadIcon(AFX_IDI_STD_FRAME)); 
     
    return CWinApp::InitApplication(); 
} 



BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) 
{ 
    CTestApp* pApp = (CTestApp*)AfxGetApp (); 
    //  Change the class name to our own name. 
    cs.lpszClass = (const char *)(pApp->m_strMyClassName); 
     
    return CFrameWnd::PreCreateWindow(cs); 
} 


BOOL CTestView::PreCreateWindow(CREATESTRUCT& cs) 
{ 
    CTestApp* pApp = (CTestApp*)AfxGetApp (); 
    //  Change the class name to our own name. 
    cs.lpszClass = (const char *)(pApp->m_strMyClassName); 
     
    return CView::PreCreateWindow(cs); 
}


 

Comments