把Qt 的窗口程序 嵌入到 MFC 的窗口程序

来源:互联网 发布:ubuntu搭建php开发环境 编辑:程序博客网 时间:2024/05/18 17:43

把Qt 的窗口程序 嵌入到 MFC 的窗口程序中 实现思路

2013年11月08日 ⁄ 综合 ⁄ 共 625字 ⁄ 字号 小 中 大 ⁄ 评论关闭



1.运行Qt窗口进程,查找外部窗口句柄 (FindWindow 、 FindWindowEx 等)
2.设置父窗口 SetParent
3.移动窗口 MoveWindow、SetWindowPos
4.如果需要去掉Qt窗口的标题栏,可以修改窗口样式 SetWindowLong

5.在你自己窗口的OnMove、OnSize等消息里,再次移动外部窗口

6. 代码展示:

HWND hwnd = ::FindWindow(NULL, _T("MainWindow") );

CRect  rect, rectChild;
GetClientRect(rect);

CPoint topLeft, bottomRight;

topLeft.SetPoint( rect.TopLeft().x + 5, rect.TopLeft().y + 5 );
bottomRight.SetPoint( rect.BottomRight().x + 5, rect.BottomRight().y + 5 );

rectChild.SetRect( topLeft , bottomRight );
if( hwnd )
{
childWnd = CWnd::FromHandle(hwnd);
childWnd->SetParent(this);
childWnd->MoveWindow(rectChild);
}     

    MainWindow是Qt的一个对话框,此代码在VS2010下运行的MFC的对话框,结果是MFC对话框里面嵌入着Qt的这个对话框。


阅读全文
0 0
原创粉丝点击