Qt Code:
  1. #ifndef MYCTRL_H
  2. #define MYCTRL_H
  3. #include "crviewer1.h"
  4. #import "C:\\Program Files\\Common Files\\Crystal Decisions\\2.0\\bin\\craxddrt9.dll" no_namespace
  5.  
  6. #include <qwinhost.h>
  7. #include <QtGui>
  8.  
  9.  
  10.  
  11. class HostWindow : public QWinHost
  12. {
  13. Q_OBJECT
  14. public:
  15. HostWindow(QWidget *parent = 0, Qt::WFlags f = 0)
  16. : QWinHost(parent, f)
  17. {
  18. setFocusPolicy(Qt::StrongFocus);
  19. }
  20. ~HostWindow()
  21. {
  22. if(m_pCRViewer1)
  23. {
  24. m_pCRViewer1->DestroyWindow();
  25. delete m_pCRViewer1;
  26. }
  27. }
  28.  
  29. HWND createWindow(HWND parent, HINSTANCE instance)
  30. {
  31. CString nn("hello");
  32.  
  33. CWnd* cwnd=CWnd::FromHandle(parent);
  34. CRect rect;
  35. cwnd->GetClientRect(&rect);
  36.  
  37. DWORD nStyle=cwnd->GetStyle();
  38.  
  39. AfxEnableControlContainer();
  40. m_pCRViewer1=new CCrviewer1();
  41. m_pCRViewer1->Create((LPCTSTR)nn, WS_CHILD | WS_VISIBLE , rect, cwnd, 10001 );
  42. m_Application.CreateInstance (__uuidof(Application));
  43. //获取m_Report变量
  44. //staff.rpt为通过向导建立的报表文件,数据库采用SQL Server 7.0
  45. m_Report =m_Application->OpenReport ("World Sales Report.rpt");
  46. //设置报表标题
  47. m_Report->put_ReportTitle (_bstr_t("Title"));
  48.  
  49. m_pCRViewer1->put_ReportSource(m_Report);
  50. m_pCRViewer1->put_DisplayToolbar (TRUE);
  51. m_pCRViewer1->put_DisplayGroupTree (FALSE);
  52. m_pCRViewer1->put_DisplayBorder (FALSE);
  53. //刷新数据
  54. m_pCRViewer1->Refresh ();
  55. //显示报表内容
  56. m_pCRViewer1->ViewReport();
  57. return m_pCRViewer1->m_hWnd;
  58. }
  59.  
  60. signals:
  61. void message(const QString &msg, int timeout);
  62.  
  63. public slots:
  64. void returnPressed()
  65. {
  66. QMessageBox::information(topLevelWidget(), "Message from Qt", "Return pressed in QLineEdit!");
  67. }
  68. public:
  69. CCrviewer1* m_pCRViewer1;
  70. IApplicationPtr m_Application;
  71. IReportPtr m_Report;
  72.  
  73. protected:
  74. /*void resizeEvent(QResizeEvent *e)
  75. {
  76. QWinHost::resizeEvent(e);
  77.  
  78. if (m_pCRViewer1)
  79. m_pCRViewer1->MoveWindow(0,0,width(),height());
  80. }*/
  81.  
  82. };
  83.  
  84. #endif
To copy to clipboard, switch view to plain text mode 

this is lastest code,it worked !
but i have other problem , How can i use MFC class dirct in Qt, and do not to reset main enty? and My Usage is correct ?