PDA

View Full Version : Using MFC CDC in QT Application



SKolaMunn
25th April 2012, 16:38
I have an MFC application that I am rewriting in QT. I am redesigning the GUI and not asking about any sort of auto-migration of code or anything like that. I just have one (big) problem, my application (formerly in MFC) sends a CDC pointer (MFC Device context) to a DLL (which I do not have access to) so that the DLL can draw on this. I want the DLL to draw on my new QLabel instead. Is there any way I can achieve this without touching the DLL (which, again, I don't have access to)? By either using a CDC in my QT GUI (yuck) or by "converting" my QLabel to a CDC? In my searches, I've seen a lot of referencing to this "MFC migration library" QT Add-on, which might be of use to me but I can not seem to find it to download it (I've found links from http://qt.nokia.com/products/qt-addons/solutions-archive/index) but they seem to all lead to dead ends.

Any suggestions would be greatly appreciated. Thank you!

I just noticed this function:
Qt::HANDLE QPixmap::handle () const

Could this be of use to me?

I think my biggest problem is that I can't seem to #include "windows.h" (or anything that includes it, like afxwin.h) and therefore can't "recognize" the CDC type (which is declared in afxwin.h).

d_stranz
26th April 2012, 17:31
I think my biggest problem is that I can't seem to #include "windows.h"

You should be able to do this. Have you tried? I recently posted code here in response to another question about loading a Windows-based DLL at runtime, where some definitions found in windows.h were required. There were no problems with that, either in compilation or linking.

It's been so long since I used MFC (and I am glad it is long past breakfast, because just thinking about it makes me nauseous). However, QWidget::winId() will return you the windowing system's internal handle (in this case the HANDLE used in Windows) for your QLabel instance.

I think you can use CWnd::FromHandle() or CWnd::FromHandlePermanent() to construct a CWnd instance, then CWnd::GetDC() to get your CDC pointer. However, this is just guessing on my part, since I've never tried to do this.