关于在控制台中弹出窗体的问题,可能要用到多线程

现在我已经实现了通过控制台输入来弹出一个窗体,如图所示。但是我想在控制台不关闭的情况下,继续输入并继续弹出窗体,应该如何实现呢?请大神赐教!图片说明
代码:
#include
#include
#include "windows.h"
#pragma once
#include "Duilib/UIlib.h"
using namespace DuiLib;
using namespace std;
#ifdef _DEBUG

ifdef _UNICODE

pragma comment(lib, "bin\DuiLib_ud.lib")

else

pragma comment(lib, "bin\DuiLib_d.lib")

endif

#else

ifdef _UNICODE

pragma comment(lib, "bin\DuiLib_u.lib")

else

pragma comment(lib, "bin\DuiLib.lib")

endif

#endif

//DWORD WINAPI funproc(LPVOID lpparentet);
//int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow);
//void WINAPI t1(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow);

/*DWORD WINAPI funproc(LPVOID lpparentet)
{
Sleep(1000);
cout << "子线程线程!" << endl;
return 0;
}*/
class CDuiFrameWnd : public CWindowWnd, public INotifyUI
{
public:
virtual LPCTSTR GetWindowClassName() const { return _T("DUIMainFrame"); }
virtual void Notify(TNotifyUI& msg)
{
if (msg.sType == _T("click"))
{
if (msg.pSender->GetName() == _T("button1"))
{
::MessageBox(NULL, _T("我是按钮test1"), _T("点击了test1"), NULL);
}
if (msg.pSender->GetName() == _T("button2"))
{
::MessageBox(NULL, _T("我是按钮test2"), _T("点击了test2"), NULL);
}
}

}

virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    LRESULT lRes = 0;

    if (uMsg == WM_CREATE)
    {
        m_PaintManager.Init(m_hWnd);

        CDialogBuilder builder;
        CControlUI* pRoot = builder.Create(_T("XMLFILE.xml"), (UINT)0, NULL, &m_PaintManager);   // duilib.xml需要放到exe目录下
        ASSERT(pRoot && "Failed to parse XML");

        m_PaintManager.AttachDialog(pRoot);
        m_PaintManager.AddNotifier(this);   // 添加控件等消息响应,这样消息就会传达到duilib的消息循环,我们可以在Notify函数里做消息处理
        return lRes;
    }

    if (m_PaintManager.MessageHandler(uMsg, wParam, lParam, lRes))
    {
        return lRes;
    }

    return __super::HandleMessage(uMsg, wParam, lParam);
}

protected:
CPaintManagerUI m_PaintManager;
};
int main()
{
int i;
CDuiFrameWnd duiFrame;
//HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);
cout << "输入1弹出窗体" << endl;
cin >> i;
while (i == 1) {
std::thread t1(& {
HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);
CPaintManagerUI::SetInstance(hInstance);
CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath());
duiFrame.Create(NULL, _T("cyq"), UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE);
duiFrame.CenterWindow();
duiFrame.ShowModal();
});
t1.detach();
cin >> i;
}
cout << "wrong number!";
system("pause");
return 0;
}

duiFrame.ShowModal();窗口以模态窗口显示,当你调用一个窗口用SHOWMODAL时,当这个窗口显示出来后,程序不会继续自己执行,而是根据你对这个窗口的操作来执行,只有关闭了这个窗口后才会执行。
duiFrame.Show();以一般方式显示,SHOW不同,当窗口显示后,代码一样往下执行的,即程序会继续执行。

可以考虑弹出窗体时,把控制台进行隐藏掉。。。但是要记得关闭窗体时,关闭控制台整个程序!!!

已解决,在线程里面实现就可以了

 #include <iostream>
#include<thread>
#include "windows.h"
#pragma once
#include "Duilib/UIlib.h"
using namespace DuiLib;
using namespace std;

#ifdef _DEBUG
#   ifdef _UNICODE
#       pragma comment(lib, "bin\\DuiLib_ud.lib")
#   else
#       pragma comment(lib, "bin\\DuiLib_d.lib")
#   endif
#else
#   ifdef _UNICODE
#       pragma comment(lib, "bin\\DuiLib_u.lib")
#   else
#       pragma comment(lib, "bin\\DuiLib.lib")
#   endif
#endif

//DWORD WINAPI funproc(LPVOID lpparentet);
//int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow);
//void WINAPI t1(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow);



/*DWORD WINAPI funproc(LPVOID lpparentet)
{
    Sleep(1000);
    cout << "子线程线程!" << endl;
    return 0;
}*/
class CDuiFrameWnd : public CWindowWnd, public INotifyUI
{
public:
    virtual LPCTSTR GetWindowClassName() const { return _T("DUIMainFrame"); }
    virtual void    Notify(TNotifyUI& msg)
    {
        if (msg.sType == _T("click"))
        {
            if (msg.pSender->GetName() == _T("button1"))
            {
                ::MessageBox(NULL, _T("我是按钮test1"), _T("点击了test1"), NULL);
            }
            if (msg.pSender->GetName() == _T("button2"))
            {
                ::MessageBox(NULL, _T("我是按钮test2"), _T("点击了test2"), NULL);
            }
        }

    }

    virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        LRESULT lRes = 0;

        if (uMsg == WM_CREATE)
        {
            m_PaintManager.Init(m_hWnd);

            CDialogBuilder builder;
            CControlUI* pRoot = builder.Create(_T("XMLFILE.xml"), (UINT)0, NULL, &m_PaintManager);   // duilib.xml需要放到exe目录下
            ASSERT(pRoot && "Failed to parse XML");

            m_PaintManager.AttachDialog(pRoot);
            m_PaintManager.AddNotifier(this);   // 添加控件等消息响应,这样消息就会传达到duilib的消息循环,我们可以在Notify函数里做消息处理
            return lRes;
        }

        if (m_PaintManager.MessageHandler(uMsg, wParam, lParam, lRes))
        {
            return lRes;
        }

        return __super::HandleMessage(uMsg, wParam, lParam);
    }

protected:
    CPaintManagerUI m_PaintManager;
};
/*void CreateWindows(CDuiFrameWnd duiFrame) {
    HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);
    CPaintManagerUI::SetInstance(hInstance);
    CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath());
    duiFrame.Create(NULL, _T("cyq"), UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE);
    duiFrame.CenterWindow();
    duiFrame.ShowModal();
}*/
int main()
{
    int i;
    //CDuiFrameWnd duiFrame;
    //HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);
    cout << "输入1弹出窗体" << endl;
    cin >> i;
    while (i == 1) {
        //thread t1(CreateWindows,duiFrame);
        std::thread t1([&]() {
            CDuiFrameWnd duiFrame;
            HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);
            CPaintManagerUI::SetInstance(hInstance);
            CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath());
            duiFrame.Create(NULL, _T("cyq"), UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE);
            duiFrame.CenterWindow();
            duiFrame.ShowModal();

        });
        t1.detach();
        cin >> i;

    }
    cout << "wrong number!";
    system("pause");
    return 0;
}