Pergunta

My Qt Application is to read data from external device, analyse it and then display the results on the screen. As I need to work with GUI, I selected Qt over Winforms. I didn't know that device was only working with windows messages. The device comes with static libs and predefined functions. I am able to access the device from my application (and get the status parameter). the problem comes with windows messages. I need to read buffer from the device and for that device sends BUFFER_FULL message. I have used QWidget::winevent function for that. My implementation looks like following.

in mainWindow.h

virtual bool winEvent(MSG *message, long *result);

in mainWindow.cpp

bool MainWindow::winEvent(MSG *message, long *result)
{
switch(message->message)
{
case BUFFER_DONE:
    qDebug()<<"***---BUFFER_DONE---***";
    return 0;

case WM_PAINT:
    // TODO: set error
    qDebug()<<"***---WM_PAINT---***";
    return 1;

default:
    break;
}
}

while debugging the application, it keeps on getting WM_PAINT message. I haven't implemented WM_PAINT message. The application has nothing to display and it almost 'pauses' at this point. Without this winevent implementation, it shows me clear widget. I think painting widget would be handled by Qt. Am I right with my understanding or I need to implement WM_PAINT by myself?

Foi útil?

Solução

The default handling for WM_PAINT will be fine. It will do nothing, which is what you want. However, you don't really want a visual control here. What you want, I suspect, is a message only window. That's created by passing HWND_MESSAGE to the hWndParent of CreateWindowEx. I'm not sure if Qt offers such functionality, quite possibly not.

You can carry on using QWidget but it does seem a little over-the-top to me. And if you do continue with QWidget then you ought at the very least hide it.

Note that I am assuming that your winEvent implementation is correct. You've not shown it all. Specifically you've not shown the code that returns false for the messages that you want to receive default handling.

It looks like my assumption was wrong. You were failing to return a value from your winEvent. Your compiler will warn about that provided that you enable warnings. You must do this, and then heed the warnings. Your winEvent should be:

bool MainWindow::winEvent(MSG *message, long *result)
{
    switch(message->message)
    {
    case BUFFER_DONE:
        qDebug()<<"***---BUFFER_DONE---***";
        return false;
    }
    return false;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top