zoukankan      html  css  js  c++  java
  • 分析MFC中CDialog的子类对象如何知道自己是model还是modeless的

    DoModal源代码关键部分如下
     1if (CreateDlgIndirect(lpDialogTemplate,
     2                        CWnd::FromHandle(hWndParent), hInst))
     3        {
     4            if (m_nFlags & WF_CONTINUEMODAL)
     5            {
     6                // enter modal loop
     7                DWORD dwFlags = MLF_SHOWONIDLE;
     8                if (GetStyle() & DS_NOIDLEMSG)
     9                    dwFlags |= MLF_NOIDLEMSG;
    10                VERIFY(RunModalLoop(dwFlags) == m_nModalResult);
    11            }

    相对于CDialog的Create,DoModal多了一个RunModalLoop()这么一个消息循环(当然也有一些别的,比如在创建窗口之前disable父窗口)。因此关键在这个函数里,看进去,在文件VC\atlmfc\src\mfc\wincore.cpp里
     1int CWnd::RunModalLoop(DWORD dwFlags)
     2{
     3    ASSERT(::IsWindow(m_hWnd)); // window must be created
     4    ASSERT(!(m_nFlags & WF_MODALLOOP)); // window must not already be in modal state
     5
     6    // for tracking the idle time state
     7    BOOL bIdle = TRUE;
     8    LONG lIdleCount = 0;
     9    BOOL bShowIdle = (dwFlags & MLF_SHOWONIDLE) && !(GetStyle() & WS_VISIBLE);
    10    HWND hWndParent = ::GetParent(m_hWnd);
    11    m_nFlags |= (WF_MODALLOOP|WF_CONTINUEMODAL);
    12    MSG *pMsg = AfxGetCurrentMessage();
    13
    14    // acquire and dispatch messages until the modal state is done
    15    for (;;)
    16。。。。。。for内的消息之类的略掉。。。。
    17ExitModal:
    18    m_nFlags &= ~(WF_MODALLOOP|WF_CONTINUEMODAL);
    19    return m_nModalResult;
    20}

    看到了吧,
    m_nFlags & WF_MODALLOOP就是用来判断本dialog是用DoModal还是直接Create创建的。
    如果为true表示为model否则为modeless
    注意:以上仅为现在MFC中CDialog中可用,其他lib,如WTL并不通用
  • 相关阅读:
    Tiddlywiki 维基程序使用手册
    Codeigniter 3.0 相关文档 part two
    css hack
    sql入门基础
    nodejs如何储存一个GBK编码的文件
    PHP 代码片段记录
    javascript 数字进制转换
    子网掩码计算题
    Trace文件过量生成问题解决
    PHP Header下载文件在IE文件名中文乱码问题
  • 原文地址:https://www.cnblogs.com/cutepig/p/1418106.html
Copyright © 2011-2022 走看看