Visual studio 2019年Visual Studio中的m_msgCur

Visual studio 2019年Visual Studio中的m_msgCur,visual-studio,visual-c++,mfc,Visual Studio,Visual C++,Mfc,我目前正在将旧的源代码传输到VisualStudio2019 原始代码来自VC++6或更早版本 在Windows MFC中,有一个名为CWinThread的类,根据旧的源代码,该类中存在m_msgCur。然而,在VS2019中,它说m_msgCur不存在。然后我发现m_msgCur很久以前就存在了(,MFC 4.2),它在VS2019中被删除。MSGm_msgCur包含线程的当前消息,但VS2019中是否有其他变量 // message pump for Run MSG m_msgCur;

我目前正在将旧的源代码传输到VisualStudio2019

原始代码来自VC++6或更早版本

在Windows MFC中,有一个名为
CWinThread
的类,根据旧的源代码,该类中存在
m_msgCur
。然而,在VS2019中,它说
m_msgCur
不存在。然后我发现
m_msgCur
很久以前就存在了(,MFC 4.2),它在VS2019中被删除。MSG
m_msgCur
包含线程的当前消息,但VS2019中是否有其他变量

// message pump for Run
MSG m_msgCur;                   // current message
编辑:

项目链接:

cserverCtrlDg
(继承自
CDialog
)在
serverCtrlDg.h
中声明
ServerCtrlDlg.cpp
包含它的工作原理
ServerCtrlClg.cpp
包括
,而
包含
afxwin.h
,其中包含
CWinThread

使用m_msgCur的ServerCtldLG的一部分

int CServerCtrlDlg::RunModalLoop(DWORD dwFlags)
{
    ASSERT(::IsWindow(m_hWnd)); // window must be created
    ASSERT(!(m_nFlags & WF_MODALLOOP)); // window must not already be in modal state

    // for tracking the idle time state
    BOOL bIdle = TRUE;
    LONG lIdleCount = 0;
    BOOL bShowIdle = (dwFlags & MLF_SHOWONIDLE) && !(GetStyle() & WS_VISIBLE);
    HWND hWndParent = ::GetParent(m_hWnd);
    m_nFlags |= (WF_MODALLOOP|WF_CONTINUEMODAL);
    MSG* pMsg = &AfxGetThread()->m_msgCur;

    // acquire and dispatch messages until the modal state is done
    for (;;)
    {
        ASSERT(ContinueModal());

        int iRet = RMLPreIdle();

        if (iRet < 0)
            goto ExitModal;
        else if (iRet > 0)
            continue;

        // 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;
            }

            // call OnIdle while in bIdle state
            if (!(dwFlags & MLF_NOIDLEMSG) && hWndParent != NULL && lIdleCount == 0)
            {
                // send WM_ENTERIDLE to the parent
                ::SendMessage(hWndParent, WM_ENTERIDLE, MSGF_DIALOGBOX, (LPARAM)m_hWnd);
            }
            if ((dwFlags & MLF_NOKICKIDLE) ||
                !SendMessage(WM_KICKIDLE, MSGF_DIALOGBOX, lIdleCount++))
            {
                // stop idle processing next time
                bIdle = FALSE;
            }
        }

        // phase2: pump messages while available
        do
        {
            BOOL ShouldPump = TRUE;

            ASSERT(ContinueModal());

            // See if we are requiring messages to be in queue?
            if ( m_bOnlyPumpIfMessageInQueue )
            {
                // If there isn't a message, don't turn over control to PumpMessage
                //  since it will block
                if ( !::PeekMessage( pMsg, NULL, NULL, NULL, PM_NOREMOVE ) )
                {
                    ShouldPump = FALSE;
                }
            }

            // pump message, but quit on WM_QUIT
            if ( ShouldPump )
            {
                if (!AfxGetThread()->PumpMessage())
                {
                    AfxPostQuitMessage(0);
                    return -1;
                }

                // show the window when certain special messages rec'd
                if (bShowIdle &&
                    (pMsg->message == 0x118 || pMsg->message == WM_SYSKEYDOWN))
                {
                    ShowWindow(SW_SHOWNORMAL);
                    UpdateWindow();
                    bShowIdle = FALSE;
                }

                if (!ContinueModal())
                    goto ExitModal;

                // reset "no idle" state after pumping "normal" message
                if (AfxGetThread()->IsIdleMessage(pMsg))
                {
                    bIdle = TRUE;
                    lIdleCount = 0;
                }
            }

        } while (::PeekMessage(pMsg, NULL, NULL, NULL, PM_NOREMOVE));
    }
ExitModal:
    m_nFlags &= ~(WF_MODALLOOP|WF_CONTINUEMODAL);
    return m_nModalResult;
}
int-cserverctrldg::RunModalLoop(DWORD dwFlags)
{
断言(::IsWindow(m_hWnd));//必须创建窗口
ASSERT(!(m_nFlags&WF_MODALLOOP));//窗口不能已经处于模态状态
//用于跟踪空闲时间状态
布尔-比德尔=真;
长lIdleCount=0;
boolbshowidle=(dwFlags和MLF_SHOWONIDLE)和&!(GetStyle()&WS_可见);
HWND hWndParent=::GetParent(m_HWND);
m|nFlags |=(WF|u MODALLOOP | WF|u CONTINUEMODAL);
MSG*pMsg=&AfxGetThread()->m_msgCur;
//获取和分派消息,直到模态状态完成
对于(;;)
{
断言(ContinueModal());
int-iRet=RMLPreIdle();
如果(iRet<0)
goto ExitModal;
否则如果(iRet>0)
继续;
//第一阶段:检查我们是否可以做空闲工作
while(bIdle)&&
!::peek消息(pMsg,NULL,NULL,PM\u NOREMOVE))
{
断言(ContinueModal());
//当消息队列空闲时显示对话框
如果(b显示空闲)
{
显示窗口(SW_显示正常);
UpdateWindow();
bShowIdle=FALSE;
}
//在bIdle状态下调用OnIdle
如果(!(dwFlags和MLF_NOIDLEMSG)和&hWndParent!=NULL和&lIdleCount==0)
{
//将WM_ENTERIDLE发送给父级
::发送消息(hWndParent、WM_ENTERIDLE、MSGF_对话框、(LPARAM)m_hWnd);
}
如果((dwFlags和MLF_NOKICKIDLE)||
!SendMessage(WM_KICKIDLE,MSGF_对话框,lIdleCount++)
{
//下次停止空闲处理
bIdle=假;
}
}
//阶段2:可用时的泵信息
做
{
BOOL ShouldPump=TRUE;
断言(ContinueModal());
//查看我们是否要求消息在队列中?
如果(m_bOnlyPumpIfMessageInQueue)
{
//如果没有消息,不要将控制权转到PumpMessage
//因为它会阻塞
if(!::peek消息(pMsg,NULL,NULL,NULL,PM_NOREMOVE))
{
ShouldPump=FALSE;
}
}
//泵送消息,但在WM_退出时退出
如果(应泵)
{
如果(!AfxGetThread()->PumpMessage())
{
AfxPostQuitMessage(0);
返回-1;
}
//接收某些特殊消息时显示窗口
如果(b)显示空闲&&
(pMsg->message==0x118 | | pMsg->message==WM|u SYSKEYDOWN))
{
显示窗口(SW_显示正常);
UpdateWindow();
bShowIdle=FALSE;
}
如果(!ContinueModal())
goto ExitModal;
//泵送“正常”信息后重置“无空闲”状态
if(AfxGetThread()->IsIdleMessage(pMsg))
{
比德尔=真;
lIdleCount=0;
}
}
}while(::peek消息(pMsg,NULL,NULL,NULL,PM_NOREMOVE));
}
出口模式:
m_nFlags&=~(WF_MODALLOOP | WF_CONTINUEMODAL);
返回m_nModalResult;
}

简短的回答是替换:

    MSG* pMsg = &AfxGetThread()->m_msgCur;  // vc++ 6
与:

然而,一个更好的答案是,如果你必须破解
CWnd::RunModalLoop
,那么你应该正确地操作,并更新
cserverCtldLG::RunModalLoop
,以当前的
CWnd::RunModalLoop
代码为基础,而不是从VC++6借用的旧代码

cserverCtldg::RunModalLoop
mfc\src\wincore.cpp中的
CWnd::RunModalLoop
在VC++6中的实现进行比较,会显示以下已添加的标有
/++
的行

int CServerCtrlDlg::RunModalLoop(DWORD dwFlags)
{
//...
    // acquire and dispatch messages until the modal state is done
    for (;;)
    {
        ASSERT(ContinueModal());

        int iRet = RMLPreIdle();                                                    //++
                                                                                    //++
        if (iRet < 0)                                                               //++
            goto ExitModal;                                                         //++
        else if (iRet > 0)                                                          //++
            continue;                                                               //++

        // phase1: check to see if we can do idle work
        while (bIdle &&
            !::PeekMessage(pMsg, NULL, NULL, NULL, PM_NOREMOVE))
        {
            ASSERT(ContinueModal());
//...
//...
        // phase2: pump messages while available
        do
        {
            ASSERT(ContinueModal());

            BOOL ShouldPump = TRUE;                                                 //++
                                                                                    //++
            // See if we are requiring messages to be in queue?                     //++
            if ( m_bOnlyPumpIfMessageInQueue )                                      //++
            {                                                                       //++
                // If there isn't a message, don't turn over control to PumpMessage //++
                //  since it will block                                             //++
                if ( !::PeekMessage( pMsg, NULL, NULL, NULL, PM_NOREMOVE ) )        //++
                {                                                                   //++
                    ShouldPump = FALSE;                                             //++
                }                                                                   //++
            }                                                                       //++

            if ( ShouldPump )                                                       //++
            {
                /* mfc code executed conditionally */
            }
//...
}
int-cserverctrldg::RunModalLoop(DWORD dwFlags)
{
//...
//获取和分派消息,直到模态状态完成
对于(;;)
{
断言(ContinueModal());
int-iRet=RMLPreIdle()//++
//++
如果(iRet<0)//++
goto ExitModal//++
否则如果(iRet>0)//++
继续//++
//第一阶段:检查我们是否可以做空闲工作
while(bIdle)&&
!::peek消息(pMsg,NULL,NULL,PM\u NOREMOVE))
{
断言(ContinueModal());
//...
//...
//阶段2:可用时的泵信息
做
{
断言(ContinueModal());
int CServerCtrlDlg::RunModalLoop(DWORD dwFlags)
{
//...
    // acquire and dispatch messages until the modal state is done
    for (;;)
    {
        ASSERT(ContinueModal());

        int iRet = RMLPreIdle();                                                    //++
                                                                                    //++
        if (iRet < 0)                                                               //++
            goto ExitModal;                                                         //++
        else if (iRet > 0)                                                          //++
            continue;                                                               //++

        // phase1: check to see if we can do idle work
        while (bIdle &&
            !::PeekMessage(pMsg, NULL, NULL, NULL, PM_NOREMOVE))
        {
            ASSERT(ContinueModal());
//...
//...
        // phase2: pump messages while available
        do
        {
            ASSERT(ContinueModal());

            BOOL ShouldPump = TRUE;                                                 //++
                                                                                    //++
            // See if we are requiring messages to be in queue?                     //++
            if ( m_bOnlyPumpIfMessageInQueue )                                      //++
            {                                                                       //++
                // If there isn't a message, don't turn over control to PumpMessage //++
                //  since it will block                                             //++
                if ( !::PeekMessage( pMsg, NULL, NULL, NULL, PM_NOREMOVE ) )        //++
                {                                                                   //++
                    ShouldPump = FALSE;                                             //++
                }                                                                   //++
            }                                                                       //++

            if ( ShouldPump )                                                       //++
            {
                /* mfc code executed conditionally */
            }
//...
}