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. How to convert app written in native win32 to Qt5?
Forum Updated to NodeBB v4.3 + New Features

How to convert app written in native win32 to Qt5?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.8k Views
  • 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.
  • U Offline
    U Offline
    umriyaev
    wrote on 28 Sept 2016, 04:58 last edited by
    #1

    Hi,
    I'm trying to use RealVNC in my Qt project.
    I downloaded their sdk and found sample client code for win64. But it's written using native win32 apis.
    I found that I can use QWidget::winId() instead of HWND, but I'm stuck at finding an alternative to CreateDIBSection which returns direct input buffer. Sample uses it to draw the incoming framebuffer.

    void BasicViewerWindow::createBuffer(int w, int h)
    {
      destroyBuffer();
      BitmapInfo bi;
      bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
      bi.bmiHeader.biBitCount = 32;
      bi.bmiHeader.biSizeImage = w * h * 4;
      bi.bmiHeader.biPlanes = 1;
      bi.bmiHeader.biWidth = w;
      bi.bmiHeader.biHeight = -h;
      bi.bmiHeader.biCompression = BI_RGB;
      bi.bmiHeader.biClrUsed = 0;
      bi.mask.red = 255 << 16;
      bi.mask.green = 255 << 8;
      bi.mask.blue = 255 << 0;
    
      void* pixels;
      bitmap = ::CreateDIBSection(
        GetDC(hwnd), (BITMAPINFO*)&bi.bmiHeader, DIB_RGB_COLORS, &pixels, 0, 0);
      if (!bitmap)
        throw std::exception("Could not create DIB section");
    
      if(!vnc_Viewer_setViewerFb(viewer, pixels, bi.bmiHeader.biSizeImage,
                             vnc_PixelFormat_rgb888(), w, h, 0))
        std::cerr << "call to vnc_Viewer_setViewerFb failed: " << vnc_getLastError() << std::endl;
    }
    

    Here is the code I'm talking about.
    How can I convert this method so that it uses only Qt specific classes and widgets?

    1 Reply Last reply
    0
    • U Offline
      U Offline
      umriyaev
      wrote on 28 Sept 2016, 05:09 last edited by
      #2

      Basically, I want to draw on my custom QLabel for which I already implemented mouse and keyboard handlers.
      But I couldn't find direct drawing api for QLabel either.

      Am I thinking in right direction or is it totally wrong?

      How should I port win32 applications to Qt5?

      Sorry if my questions look somehow stupid, but I'm new to Qt

      T 1 Reply Last reply 28 Sept 2016, 07:41
      0
      • U umriyaev
        28 Sept 2016, 05:09

        Basically, I want to draw on my custom QLabel for which I already implemented mouse and keyboard handlers.
        But I couldn't find direct drawing api for QLabel either.

        Am I thinking in right direction or is it totally wrong?

        How should I port win32 applications to Qt5?

        Sorry if my questions look somehow stupid, but I'm new to Qt

        T Offline
        T Offline
        tham
        wrote on 28 Sept 2016, 07:41 last edited by
        #3

        @umriyaev said in How to convert app written in native win32 to Qt5?:

        But I couldn't find direct drawing api for QLabel either.

        Google paintEvent of QWidget, this will lead you to tons of example

        How should I port win32 applications to Qt5?

        I do not think there are simple mapping of win32 api to Qt5 api, this may consume you lot of times if your project are big. Maybe wrapped the old api by some wrapper is a better choice if you do not need to write cross-platform app.

        U 1 Reply Last reply 28 Sept 2016, 08:53
        1
        • T tham
          28 Sept 2016, 07:41

          @umriyaev said in How to convert app written in native win32 to Qt5?:

          But I couldn't find direct drawing api for QLabel either.

          Google paintEvent of QWidget, this will lead you to tons of example

          How should I port win32 applications to Qt5?

          I do not think there are simple mapping of win32 api to Qt5 api, this may consume you lot of times if your project are big. Maybe wrapped the old api by some wrapper is a better choice if you do not need to write cross-platform app.

          U Offline
          U Offline
          umriyaev
          wrote on 28 Sept 2016, 08:53 last edited by umriyaev
          #4

          @tham I don't need to convert huge application. This sample app has only one class. All it does is create Native Window, get address of direct input buffer (for drawing), and supplies it to vnc sdk. In other words I'm specifically interested in this part:

          void* pixels;
            bitmap = ::CreateDIBSection(
              GetDC(hwnd), (BITMAPINFO*)&bi.bmiHeader, DIB_RGB_COLORS, &pixels, 0, 0);
            if (!bitmap)
              throw std::exception("Could not create DIB section");
          
            if(!vnc_Viewer_setViewerFb(viewer, pixels, bi.bmiHeader.biSizeImage,
                                   vnc_PixelFormat_rgb888(), w, h, 0))
              std::cerr << "call to vnc_Viewer_setViewerFb failed: " << vnc_getLastError() << std::endl;
          

          Is there a way to get the address of widget's drawing area to which other objects can draw from outside?
          Can I achieve this in the following way:

          1. Create custom label inheriting from QLabel
          2. Add QBitmap
          3. Supply that QBitmap to vnc sdk
          4. Whenever vnc sdk supplies updated framebuffer QBitmap gets drawn on the QLabel

          I looked at paint event as you said, but it seems like there is no way to automatically detect changes in QBitmap and draw it on the QLabel whenever vnc sdk updates QBitmap. Cuz in terms of OOP vnc sdk doesn't have knowledge of QLabel. But their sample uses win32 which lets get drawing area of the window and supply it to clients as bitmap's address so that clients later can change its contents and those contents will be drawn on the screen. We don't need to call any methods for that. (Please correct me if I'm wrong. Cuz I've never worked with win32 api before, I usually used wpf and winforms and didn't have requirement for cross-platform. But now I need it and therefore started using Qt)

          U 2 Replies Last reply 28 Sept 2016, 09:06
          0
          • U umriyaev
            28 Sept 2016, 08:53

            @tham I don't need to convert huge application. This sample app has only one class. All it does is create Native Window, get address of direct input buffer (for drawing), and supplies it to vnc sdk. In other words I'm specifically interested in this part:

            void* pixels;
              bitmap = ::CreateDIBSection(
                GetDC(hwnd), (BITMAPINFO*)&bi.bmiHeader, DIB_RGB_COLORS, &pixels, 0, 0);
              if (!bitmap)
                throw std::exception("Could not create DIB section");
            
              if(!vnc_Viewer_setViewerFb(viewer, pixels, bi.bmiHeader.biSizeImage,
                                     vnc_PixelFormat_rgb888(), w, h, 0))
                std::cerr << "call to vnc_Viewer_setViewerFb failed: " << vnc_getLastError() << std::endl;
            

            Is there a way to get the address of widget's drawing area to which other objects can draw from outside?
            Can I achieve this in the following way:

            1. Create custom label inheriting from QLabel
            2. Add QBitmap
            3. Supply that QBitmap to vnc sdk
            4. Whenever vnc sdk supplies updated framebuffer QBitmap gets drawn on the QLabel

            I looked at paint event as you said, but it seems like there is no way to automatically detect changes in QBitmap and draw it on the QLabel whenever vnc sdk updates QBitmap. Cuz in terms of OOP vnc sdk doesn't have knowledge of QLabel. But their sample uses win32 which lets get drawing area of the window and supply it to clients as bitmap's address so that clients later can change its contents and those contents will be drawn on the screen. We don't need to call any methods for that. (Please correct me if I'm wrong. Cuz I've never worked with win32 api before, I usually used wpf and winforms and didn't have requirement for cross-platform. But now I need it and therefore started using Qt)

            U Offline
            U Offline
            umriyaev
            wrote on 28 Sept 2016, 09:06 last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • U umriyaev
              28 Sept 2016, 08:53

              @tham I don't need to convert huge application. This sample app has only one class. All it does is create Native Window, get address of direct input buffer (for drawing), and supplies it to vnc sdk. In other words I'm specifically interested in this part:

              void* pixels;
                bitmap = ::CreateDIBSection(
                  GetDC(hwnd), (BITMAPINFO*)&bi.bmiHeader, DIB_RGB_COLORS, &pixels, 0, 0);
                if (!bitmap)
                  throw std::exception("Could not create DIB section");
              
                if(!vnc_Viewer_setViewerFb(viewer, pixels, bi.bmiHeader.biSizeImage,
                                       vnc_PixelFormat_rgb888(), w, h, 0))
                  std::cerr << "call to vnc_Viewer_setViewerFb failed: " << vnc_getLastError() << std::endl;
              

              Is there a way to get the address of widget's drawing area to which other objects can draw from outside?
              Can I achieve this in the following way:

              1. Create custom label inheriting from QLabel
              2. Add QBitmap
              3. Supply that QBitmap to vnc sdk
              4. Whenever vnc sdk supplies updated framebuffer QBitmap gets drawn on the QLabel

              I looked at paint event as you said, but it seems like there is no way to automatically detect changes in QBitmap and draw it on the QLabel whenever vnc sdk updates QBitmap. Cuz in terms of OOP vnc sdk doesn't have knowledge of QLabel. But their sample uses win32 which lets get drawing area of the window and supply it to clients as bitmap's address so that clients later can change its contents and those contents will be drawn on the screen. We don't need to call any methods for that. (Please correct me if I'm wrong. Cuz I've never worked with win32 api before, I usually used wpf and winforms and didn't have requirement for cross-platform. But now I need it and therefore started using Qt)

              U Offline
              U Offline
              umriyaev
              wrote on 28 Sept 2016, 09:20 last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0

              1/6

              28 Sept 2016, 04:58

              • Login

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