DUI-模态对话框的实现

模态对话框要求自己实现自己的消息循环,当然,建议它还是处于主线程中,所以最好是由它再调用主线程的消息循环函数,此时主线程自身的消息循环函数被阻塞,等待模板对话框的消息循环函数退出

参考代码如下:

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
INT_PTR XX::DoModal(LPCWSTR lpszXmlId, HWND hParent/*=NULL*/bool bShadow/*=false*/, DM::CRect rect/* = NULL*/)
{
    BOOL bEnableParent = FALSE;
    if(NULL == hParent)
    {
        hParent = GetActiveWnd();
    }
     
    if (hParent && hParent != ::GetDesktopWindow() && ::IsWindowEnabled(hParent))
    {
        ::EnableWindow(hParent, FALSE);
        bEnableParent = TRUE;
    }
 
    if(!DM_CreateWindow(lpszXmlId, rect.left,rect.top,rect.Width(),rect.Height(), hParent, bShadow))
    {
        ::EnableWindow(hParent, TRUE);
        return 0; // 此处失败了
    }
 
    GetClientRect(rect);
    if (!rect.IsRectEmpty())
    {
        CenterWindow();
    }
 
    SendMessage(WM_INITDIALOG);//发送init消息
 
    if(GetExStyle()&WS_EX_TOOLWINDOW)
    {
        ::ShowWindow(m_hWnd,SW_SHOWNOACTIVATE);
    }
    else
    {
        ::ShowWindow(m_hWnd,SW_SHOWNORMAL);
    }
 
     
    ::SetWindowPos(m_hWnd, /*HWND_TOP*/HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
         Run(m_hWnd,true);// 消息循环
 
    if (bEnableParent)
    {
        ::EnableWindow(hParent, TRUE);
    }
 
    return m_nRetCode;
}
 
void  XX::EndDialog( INT_PTR nResult )
{
    m_nRetCode = nResult;
    PostMessage(WM_QUIT);
}

 

http://hgy413.com/1635.html

posted @ 2017-01-11 00:37  findumars  Views(742)  Comments(0Edit  收藏  举报