netease-im / NIM_Duilib_Framework

网易云信Windows应用开发框架。
MIT License
2.04k stars 828 forks source link

Duilib如何嵌入在MFC使用 #256

Open ClearSeve opened 3 years ago

ClearSeve commented 3 years ago

看到有一个这个issues https://github.com/netease-im/NIM_Duilib_Framework/issues/116 我是刚接触这个, 上面说的解决办法不是很明白, 如果有人能有提供一个最简单的例子, 那就太好了

nmgwddj commented 3 years ago

不建议使用这种方式来开发应用程序,两种框架使用了完全不同的框架体系,虽然可以使用各种姿势融合在一起使用,但会带来各类问题,在目前桌面端应用设计的风格中,传统 MFC 应用的设计思路均可以使用类 Duilib 的 DirectUI 框架来实现。

vanehu commented 3 years ago

CWnd* pAppWnd = new CWnd(); m_pMainWnd = pAppWnd; if (!pAppWnd->CreateEx(WS_EX_TOOLWINDOW,AfxRegisterWndClass(0), "msgWnd", WS_POPUP, CRect(0,0,0,0), nullptr,0)) { return FALSE; } pAppWnd->ShowWindow(SW_HIDE);

m_pMainView = new MainWnd();
m_pMainView->RegisterWindowClass();
m_pMainView->Create(nullptr, L"mainWnd", WS_POPUP, WS_EX_APPWINDOW, false);

m_pMainView->CenterWindow();
m_pMainView->ShowWindow();

这样就可以了 退出的时候 if (m_pMainWnd != nullptr) { delete m_pMainWnd; m_pMainWnd = nullptr; }

我现在打算dui做主窗口,要用mfc的时候做子窗口 按理问题不大的

ClearSeve commented 3 years ago

啊这.... 我是想用MFC做主窗口, 里面嵌入Duilib....

vanehu commented 3 years ago

创建一个子窗口啊 这没啥吧

nmgwddj commented 3 years ago

CWnd* pAppWnd = new CWnd(); m_pMainWnd = pAppWnd; if (!pAppWnd->CreateEx(WS_EX_TOOLWINDOW,AfxRegisterWndClass(0), "msgWnd", WS_POPUP, CRect(0,0,0,0), nullptr,0)) { return FALSE; } pAppWnd->ShowWindow(SW_HIDE);

m_pMainView = new MainWnd();
m_pMainView->RegisterWindowClass();
m_pMainView->Create(nullptr, L"mainWnd", WS_POPUP, WS_EX_APPWINDOW, false);

m_pMainView->CenterWindow();
m_pMainView->ShowWindow();

这样就可以了 退出的时候 if (m_pMainWnd != nullptr) { delete m_pMainWnd; m_pMainWnd = nullptr; }

我现在打算dui做主窗口,要用mfc的时候做子窗口 按理问题不大的

很想了解一下,为什么必须使用 MFC 嵌入 Duilib,是旧业务的历史原因吗?