ContinueModal() 에서 ASSERTION FAILED

MFC로 코딩하다.. KillFocus 부분에서 OnCancel() 나 OnOK()를 호출하였는데, 이게 왠일! 오류가 나는게 아닌가? 그것도 내가 짠 코드가 아닌 wincore.cpp 에서..

// wincore.cpp 4530 line
    // acquire and dispatch messages until the modal state is done for (;;)
    {
        ASSERT(ContinueModal()); // 여기서 오류가!
        // phase1: check to see if we can do idle work
        while (bIdle && !::PeekMessage(pMsg, NULL, NULL, NULL, PM_NOREMOVE))
        {
            ASSERT(ContinueModal()); // show the dialog when the message queue goes idle
            if (bShowIdle)
            {
                ShowWindow(SW_SHOWNORMAL);
                UpdateWindow();
                bShowIdle = FALSE;
            }
...


위에 주석으로 표시된 부분에서 ASSERT 오류가 났다. 왜? 왜? 왜? 그렇다면 ContinueModal()로 들어가보자.

// wincore.cpp 4599 line
BOOL CWnd::ContinueModal()
{
    return m_nFlags & WF_CONTINUEMODAL;
}


결과적으로 WF_CONTINUEMODAL flag가 켜져 있지 않으면 오류가 난다 이거다. 이것도 문제가 생길때가 있고 안생길때가 있어서 사람을 미치게 만드는데.. 그럼 뭐가 문제일까? 결론부터 말하자면 dialog가 없어졌는데 (= 핸들이 해제되었는데) 메시지를 보내서 문제가 되는것이며, 이는 WM_KILLFOCUS같은 메시지가 처리되면서 dialog가 해제되어 발생하는 문제로 파악되어 진다. (SendMessage는 메시지를 바로 처리하는 함수이기 때문에) 해결책은? WM_KILLFOCUS안에서 PostMessage로 Dialog를 종료한다. 그러면 WM_KILLFOCUS가 모두 호출 된 뒤 message queue에서 종료메시지를 받게 된다. 즉,

void CYourDlg::OnKillfocus()
{
    // OnClose나 OnOK 대신 PostMessage(WM_CLOSE);
}


와 같이 코딩하면 된다.
크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by 장현준

2007/10/22 11:27 2007/10/22 11:27
, , , , ,
Response
No Trackback , a comment
RSS :
http://b4you.net/blog/rss/response/142


블로그 이미지

빗소리를 먹는 사람.

- 장현준

Notices

Archives

Authors

  1. 장현준

Recent Trackbacks

  1. 듀얼클러치의 생각 rsvin28's me2DAY 2009

Calendar

«   2012/02   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29      

Site Stats

Total hits:
158009
Today:
79
Yesterday:
228