Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using an MFC custom control from Qt
Forum Updated to NodeBB v4.3 + New Features

Using an MFC custom control from Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 5 Posters 892 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Perdrix
    wrote on 12 Aug 2020, 03:28 last edited by
    #1

    Until I can re-implement a complex MFC custom control in native Qt, I need to be able to continue to use it.

    The usage of the control is to either take over a CStatic control in a dialog by invoking it's

    BOOL CreateFromStatic(CWnd * static)

    member function,

    or as is probably more appropriate here to invoke this mf:

    BOOL Create(RECT const & r, CWnd * parent, UINT id,
    DWORD dwStyle = WS_CHILD | WS_VISIBLE);

    I can extract a RECT from the widget that I wish to take over (a QLabel), but I'm not clear how I can create a CWND that I can use to refer to the "this" QWidget as its parent. I can readily extract my own hwnd by calling winId() but can I use CWND::Attach() against a just created CWND to do create a useable CWND for this purpose?

    Thanks
    David

    J 1 Reply Last reply 12 Aug 2020, 04:45
    0
    • P Perdrix
      12 Aug 2020, 03:28

      Until I can re-implement a complex MFC custom control in native Qt, I need to be able to continue to use it.

      The usage of the control is to either take over a CStatic control in a dialog by invoking it's

      BOOL CreateFromStatic(CWnd * static)

      member function,

      or as is probably more appropriate here to invoke this mf:

      BOOL Create(RECT const & r, CWnd * parent, UINT id,
      DWORD dwStyle = WS_CHILD | WS_VISIBLE);

      I can extract a RECT from the widget that I wish to take over (a QLabel), but I'm not clear how I can create a CWND that I can use to refer to the "this" QWidget as its parent. I can readily extract my own hwnd by calling winId() but can I use CWND::Attach() against a just created CWND to do create a useable CWND for this purpose?

      Thanks
      David

      J Offline
      J Offline
      JKSH
      Moderators
      wrote on 12 Aug 2020, 04:45 last edited by
      #2

      @Perdrix said in Using an MFC custom control from Qt:

      can I use CWND::Attach() against a just created CWND to do create a useable CWND for this purpose?

      What happens if you try it?

      Note: This is not officially supported by Qt, so I won't be surprised if you encounter strange behaviours.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      1
      • P Offline
        P Offline
        Perdrix
        wrote on 12 Aug 2020, 09:20 last edited by
        #3

        Well I didn't want to "just try it" as that could be the "wrong" way to proceed.

        What's the recommended approach for hosting an MFC CWND derived window with a QWidget? Surely this must have come up before?

        J J 2 Replies Last reply 12 Aug 2020, 12:36
        0
        • P Perdrix
          12 Aug 2020, 09:20

          Well I didn't want to "just try it" as that could be the "wrong" way to proceed.

          What's the recommended approach for hosting an MFC CWND derived window with a QWidget? Surely this must have come up before?

          J Online
          J Online
          JonB
          wrote on 12 Aug 2020, 12:36 last edited by JonB 8 Dec 2020, 12:47
          #4

          @Perdrix
          https://forum.qt.io/topic/76525/cwnd-to-qwidget

          Separately, I don't know whether it's relevant but you may wish to look through https://docs.huihoo.com/qt/solutions/4/qtwinmigrate/winmigrate-walkthrough.html

          1 Reply Last reply
          3
          • P Perdrix
            12 Aug 2020, 09:20

            Well I didn't want to "just try it" as that could be the "wrong" way to proceed.

            What's the recommended approach for hosting an MFC CWND derived window with a QWidget? Surely this must have come up before?

            J Offline
            J Offline
            JKSH
            Moderators
            wrote on 12 Aug 2020, 12:52 last edited by
            #5

            @Perdrix said in Using an MFC custom control from Qt:

            What's the recommended approach for hosting an MFC CWND derived window with a QWidget? Surely this must have come up before?

            MFC and Qt are quite different frameworks and combining them is challenging. I don't have the experience to do it "correctly"; I'm not sure if anyone in this forum has that experience.

            Thank you @JonB for providing links to what others have tried before. The source code for the Qt/MFC Migration Framework used by the walkthrough can be found at https://github.com/qtproject/qt-solutions/tree/master/qtwinmigrate . Unfortunately, it is no longer maintained so there is currently no officially-supported way to merge CWND and QWidget.

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            P 1 Reply Last reply 12 Aug 2020, 16:03
            3
            • J JKSH
              12 Aug 2020, 12:52

              @Perdrix said in Using an MFC custom control from Qt:

              What's the recommended approach for hosting an MFC CWND derived window with a QWidget? Surely this must have come up before?

              MFC and Qt are quite different frameworks and combining them is challenging. I don't have the experience to do it "correctly"; I'm not sure if anyone in this forum has that experience.

              Thank you @JonB for providing links to what others have tried before. The source code for the Qt/MFC Migration Framework used by the walkthrough can be found at https://github.com/qtproject/qt-solutions/tree/master/qtwinmigrate . Unfortunately, it is no longer maintained so there is currently no officially-supported way to merge CWND and QWidget.

              P Offline
              P Offline
              Perdrix
              wrote on 12 Aug 2020, 16:03 last edited by
              #6

              I'm using qmfcapp and qwinwidget as they seem to be the only way to go.

              I'm frankly quite shocked that you don't support those anymore - this must be a very common requirement for everyone who's converting their code to Qt!

              I'm also a bit surprised that there's no expertise on porting to Qt here either ...

              David

              1 Reply Last reply
              0
              • H Online
                H Online
                hskoglund
                wrote on 12 Aug 2020, 16:45 last edited by
                #7

                Just want to add to what @JKSH said above (.. they are quite different frameworks):

                I used MFC and Visual C++ for almost 20 years before waking up to Qt and initially tried to port some code over, however all the MFC macros like message maps etc I could just toss and same for MVC stuff, so the only type of code that I did port was CString juggling (CString and QString are probably the most similar in vein parts of their respective frameworks).

                1 Reply Last reply
                2
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 12 Aug 2020, 16:54 last edited by
                  #8

                  Hi
                  What does this complex MFC custom control do ?
                  Mixing MFC and Qt might end up being a bigger job than to recreate
                  this control in Qt.

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Perdrix
                    wrote on 12 Aug 2020, 18:02 last edited by Perdrix 8 Dec 2020, 18:06
                    #9

                    One of them is a class derived from this: https://www.codeproject.com/articles/555/wndimage-control.

                    It adds mouse tracking, hit-testing, wheel zooming and "4-corners" mode that zooms into the four corners of the image.

                    With four corners not enabled:

                    25777e28-a69b-4585-a594-61b3ee6a7f33-image.png https://www.codeproject.com/articles/555/wndimage-control

                    With four corners enabled:

                    565df5d6-e28e-4098-88e3-f5a2f38d05bd-image.png

                    The image is populated from an internally calculated windows bitmap (BITMAPINFO) derived from a 32bit floating point representation of an image. We'd obviously need to have a non-Windows in storage bitmap representation (maybe a Pixmap?) that could be built dynamically from our internal representation.

                    David

                    1 Reply Last reply
                    0
                    • mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 12 Aug 2020, 18:24 last edited by mrjj 8 Dec 2020, 18:24
                      #10

                      Hi
                      The https://doc.qt.io/qt-5/graphicsview.html
                      would give panning / zooming and and mouse tracking for (almost) free.

                      is the 4 zoom area like a lens effect that zoom the area while you can pan the image around or is it more static ?

                      1 Reply Last reply
                      2
                      • P Offline
                        P Offline
                        Perdrix
                        wrote on 12 Aug 2020, 20:36 last edited by Perdrix 8 Dec 2020, 20:38
                        #11

                        The four corner stuff is static ...

                        I'll take another look at the graphicsview control. I thought that was for managing lots of items within a scene, not for handling a single image.

                        Thanks
                        David

                        mrjjM 1 Reply Last reply 13 Aug 2020, 05:18
                        0
                        • P Perdrix
                          12 Aug 2020, 20:36

                          The four corner stuff is static ...

                          I'll take another look at the graphicsview control. I thought that was for managing lots of items within a scene, not for handling a single image.

                          Thanks
                          David

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 13 Aug 2020, 05:18 last edited by
                          #12

                          @Perdrix
                          Hi
                          Well its also good to have many items but can also be
                          used for a single item like an image

                          https://doc.qt.io/qt-5/qgraphicspixmapitem.html

                          1 Reply Last reply
                          0

                          1/12

                          12 Aug 2020, 03:28

                          • Login

                          • Login or register to search.
                          1 out of 12
                          • First post
                            1/12
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved