qt 处理自定义的windows消息

#include "mainwindow.h"

#include "ui_mainwindow.h"

#include 

#include 



bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)

{

    if (eventType == "windows_generic_MSG")

    {

        PMSG msg = (PMSG)message;

        if (msg->message == WM_USER + 777)

        {

            qDebug() << "Hello World";

            qDebug() << msg->wParam;   // 10

            qDebug() << msg->lParam;   // 20

        }

    }

    return false;

}



MainWindow::MainWindow(QWidget *parent) :

    QMainWindow(parent),

    ui(new Ui::MainWindow)

{

    ui->setupUi(this);

}



MainWindow::~MainWindow()

{

    delete ui;

}



void MainWindow::on_pushButton_clicked()

{

    PostMessage((HWND)this->winId(), WM_USER + 777, 10, 20);

}

你可能感兴趣的:(Qt)