[Qt-interest] How to use Windows Message System in Qt/Win Application?

Carsten Breuer CarstenBreuerQt at textwork.de
Sat Jun 12 00:46:18 CEST 2010


Hi Mathias,
hi all,

>> The code you have posted is not enaugh.
>> Is this Stemmer Imaging / Dalsa stuff?
> No it is from uEye Camera.

Ah, ok.

> #define IS_UEYE_MESSAGE                     (WM_USER + 0x0100)
>  #define IS_FRAME                          0x0000
>  #define IS_SEQUENCE                       0x0001

Yep..ok. That is excatly what we are looking for.
Some backgrounds:
Windows use a messaging system that is send with
two optional parameters (wparam and lparam). This
params are misused for nearly everything, even pointers.

If Windows want to send an application an request to draw,
it send a WM_PAINT message.

Refer to:
http://msdn.microsoft.com/en-us/library/ms644950%28VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/dd145213%28VS.85%29.aspx

The message ids beginning with WM_USER defines the free area that
is not used by windows, though applications can use it to send
custom messages system wide. This is excactly what the lib does.
It defines an own message and use wparam and lparam to transmit
data (pointers, enums, ...). The lib has to know your windows
handle to be able to send messages to your window.

>But that indicates that the whole message stuff is handled by the dll
>of the camera.As I posted in the first post, the message handling is
>enabled with

We deal with two things here:

1. You have to start the camera and give it your windows handle.
2. The camera use the windows message system
   to communicate with you.

Let us begin with :

1.)
> is_EnableMessage(m_hCam, IS_FRAME, GetSafeHwnd());

This is a function the library offers to start the capturing.
Parameters are:

- m_hCam        : Handle to the camera instance
- IS_FRAME      : Type of capturing (i assume).
- GetSafeHwnd() : Window handle.

In QT you have to call the function with:

is_EnableMessage(m_hCam, IS_FRAME, reinterpret_cast<HWND>(winId());

Now your cam should capture the image and show it in the
widget defined with winId.

2. I assume the camera send additional information
   with the windows message system.

To use this, you have to install a native message filter
like Robert suggest. I work with QT now for 6 month so i
never did this in QT. But with the information you have
it should be easy.

The problem is to find out which information the
camera packs in the wparam and lparam.

Example:

If you would like to share a QWidget
with another application and you only
have poor windows, you could do it this way:

SendMessage( id_of_other_window,
             WM_USER+100,
             42,
             (unsigned long)&my_widget);

The other application will receive in lparam a number.
This number is really a pointer to a QWidget.
Of course, the other application have to know the use of
the values in wparam and lparam  to use them.
That's exactly the problem you have now and
you will find the answer only in the docs/code
of uEye.


> However I do not know if the 'IS_FRAME' is really a message id or if it
> only a constant used by the dll

It's a constant.

> But that indicates that the whole message stuff is handled by the dll of
> the camera.

No. the dll of the camera use SendMessage of PostMessage to send
a message to the window that you have given with winId.

> which I can not do since I do not have 'GetSafeHwnd()'
> and is retrieved in the function

See above. Of cource you have. It's called winId :-).

> Still I do not see how to integrate this into a Qt App.

I hope things become clearer now.



Best Regards,



Carsten



More information about the Qt-interest-old mailing list