PDA

View Full Version : Draw text in the same device context with win32



mioan
15th May 2009, 14:07
Hi I have just started to use QT and I want gradually to change my win32 screensaver to use QT functions and be finally able to work on Mac.

In my win32 code, I use the windows desktop device context to draw bitmaps. The bitmaps are created by a textOut function (the win32 textout)

Can some of the graphics be drawn by QT and some other graphics by my win32 API functions? Is there a source example that by having the hDC (device context) I can use QPainter to draw things on the same window?

Thanks
Mike

wysota
15th May 2009, 22:25
Yes, although this is not trivial and only one way (you can use GDI calls to draw on Qt widgets but not QPainter to draw on non-Qt devices). Why can't you make a leap from winapi to Qt in one go?

mioan
16th May 2009, 19:05
What you propose is the oposite from what I need. I need to draw with QT on the desktop where other API calls also draw.
As you know a screensaver consists of the drawing on the desktop and the configuration dialog.
From your reply I think it would be more easy to start transfering to QT the dialog of the screensaver and leave for a later step the desktop drawing of the screensaver?

I am developing with visual studio 2005.
To create a dialog widget, do I need first to initiate a QApplication object?
How can I initiate it since all the QT examples need argc and argv
QApplication ( int & argc, char ** argv )
This main() is a "dos" version. The screensaver has a winmain function without the argc and argv arguments.
(Confused)

Is there an example of win32 and QT leaving together in the same windows application?
Thank you very much
Michael

wysota
16th May 2009, 21:30
What you propose is the oposite from what I need. I need to draw with QT on the desktop where other API calls also draw.
You can try opening a painter on QDesktopWidget.


From your reply I think it would be more easy to start transfering to QT the dialog of the screensaver and leave for a later step the desktop drawing of the screensaver?
Configuration dialog is trivial once you have all the infrastructure running so I'd suggest going for the screen saver first.


To create a dialog widget, do I need first to initiate a QApplication object?
Yes.


This main() is a "dos" version.
No, it's not. World doesn't end on Windows, neither it begins there. main() is a classic C interface and winmain() is an artificial function that is called from the real main provided by msvc.


The screensaver has a winmain function without the argc and argv arguments.
(Confused)

So make it have a main() and not winmain, that's not a problem.


Is there an example of win32 and QT leaving together in the same windows application?

Each Qt application running on Windows is a "win32" application.

Stop thinking in terms of Visual Studio and start thinking in terms of programming. Start with main(), create an application object there, do everything you want related to pure winapi calls if you want and call QApplication::exec(). Just remember the latter is an event loop that will block until your application exits.

aamer4yu
17th May 2009, 18:06
If you are concerned about the whole desktop, you can think of your application occupying the whole screen, and paint whatever u like. Simple.
You can use showFullScreen for that.

Also you can move your widget on the desktop while painting is done inside the widget. This is second approach.

Why do you think any of them wont work ?
Hint : In a screensaver, the desktop is your playground ;)