How to convert app written in native win32 to Qt5?
-
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? -
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
-
@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.
-
@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:- Create custom label inheriting from QLabel
- Add QBitmap
- Supply that QBitmap to vnc sdk
- 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)