Results 1 to 6 of 6

Thread: how create CWnd and use it in Qt

  1. #1
    Join Date
    Jun 2009
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default how create CWnd and use it in Qt

    Hi: every one
    i'm want use crystal report in qt,i find Qt/MFC Migration Framework ,and test example.
    i proble is
    i have a wrap class from crystal report control,this is deriver from CWnd
    how can i complie it with Qt Application.

    Qt Code:
    1. //////////////////////////
    2. //h
    3. #ifndef CRVIEWER1_H
    4. #define CRVIEWER1_H
    5.  
    6. #include "stdafx.h"
    7.  
    8. class CCrviewer1 : public CWnd
    9. {
    10. protected:
    11. DECLARE_DYNCREATE(CCrviewer1)
    12. public:
    13. ............
    14. //
    15.  
    16. };
    17. #endif
    18. ////////////////////////////////////////
    19. //cpp
    20.  
    21. //#include "stdafx.h"
    22. #include "crviewer1.h"
    23.  
    24. /////////////////////////////////////////////////////////////////////////////
    25. // CCrviewer1
    26.  
    27. IMPLEMENT_DYNCREATE(CCrviewer1, CWnd)
    28.  
    29. ///////////////////////////////////////////////////////
    30. //MyCtrl.h
    31. #ifndef MYCTRL_H
    32. #define MYCTRL_H
    33. #import "C:\\Program Files\\Common Files\\Crystal Decisions\\2.0\\bin\\craxddrt9.dll" no_namespace
    34. #include "crviewer1.h"
    35. #include <qwinhost.h>
    36. #include <QtGui>
    37.  
    38. class HostWindow : public QWinHost
    39. {
    40. Q_OBJECT
    41. public:
    42. HostWindow(QWidget *parent = 0, Qt::WFlags f = 0)
    43. : QWinHost(parent, f)
    44. {
    45. setFocusPolicy(Qt::StrongFocus);
    46. }
    47.  
    48. HWND createWindow(HWND parent, HINSTANCE instance)
    49. {
    50. [SIZE="6"] //how can i create CCrviewer1???[/SIZE]
    51. return 0;
    52. }
    53.  
    54. signals:
    55. void message(const QString &msg, int timeout);
    56.  
    57. public slots:
    58. void returnPressed()
    59. {
    60. QMessageBox::information(topLevelWidget(), "Message from Qt", "Return pressed in QLineEdit!");
    61. }
    62. public:
    63. CCrviewer1* m_pCRViewer1;
    64. IApplicationPtr m_Application;
    65. IReportPtr m_Report;
    66.  
    67. protected:
    68.  
    69. };
    70. #endif
    To copy to clipboard, switch view to plain text mode 

    then i compile the application,i get this info
    c:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\afxv_w32.h(16) : fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>

    i adjest include head sequece ,the complie is ok ,but i get some warning
    1>LINK : warning LNK4098: default libraries “mfc90d.lib” conflicts with other libraries;please use /NODEFAULTLIB:library
    1>LINK : warning LNK4098: default libraries “mfc90d.lib” conflicts with other libraries;please use /NODEFAULTLIB:library

    this i run the program, but the main entry is to AfxWinMain, is not my Qt Application
    main()!!



    i want to know how can i use CWnd in Qt

    thanks every much!
    Last edited by litterflybug; 15th September 2009 at 07:03.

  2. #2
    Join Date
    Jun 2009
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how create CWnd and use it in Qt

    i tried this ,it worked

    i set compiler project->property->linker->Advanced->entry
    i set entry to main (this is my Qt application's entry), then rebuild,
    it ok,and run it ok!

    but i did't understand how Qt application link to mfc

    someone can explain for this?

  3. #3
    Join Date
    Jun 2009
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how create CWnd and use it in Qt

    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 ?

  4. #4
    Join Date
    Jun 2009
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how create CWnd and use it in Qt

    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. //get m_Report
    44. //
    45. m_Report =m_Application->OpenReport ("World Sales Report.rpt");
    46. //set report title
    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 ?

  5. #5
    Join Date
    Jun 2009
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how create CWnd and use it in Qt

    i tried more, i set Ignore defualt libary,mfc90d.lib;mfcs90d.lib, then build run

    it worked ,i do not set main entry

  6. #6
    Join Date
    Jul 2013
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how create CWnd and use it in Qt

    I am facing the same problem with you,
    can you give me a detailed explain for me?
    I am also want to use CWnd as a QT QWidget without change the entrypoint from main to AfxWinMain.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.