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

Using an MFC custom control from Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 5 Posters 1.3k 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on 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

    JKSHJ 1 Reply Last reply
    0
    • PerdrixP Perdrix

      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

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on 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
      • PerdrixP Offline
        PerdrixP Offline
        Perdrix
        wrote on 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?

        JonBJ JKSHJ 2 Replies Last reply
        0
        • PerdrixP Perdrix

          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?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #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
          • PerdrixP Perdrix

            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?

            JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on 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

            PerdrixP 1 Reply Last reply
            3
            • JKSHJ JKSH

              @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.

              PerdrixP Offline
              PerdrixP Offline
              Perdrix
              wrote on 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
              • hskoglundH Offline
                hskoglundH Offline
                hskoglund
                wrote on 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 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
                  • PerdrixP Offline
                    PerdrixP Offline
                    Perdrix
                    wrote on last edited by Perdrix
                    #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 last edited by mrjj
                      #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
                      • PerdrixP Offline
                        PerdrixP Offline
                        Perdrix
                        wrote on last edited by Perdrix
                        #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
                        0
                        • PerdrixP Perdrix

                          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 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

                          • Login

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