2013-02-24 37 views
0

我想從父進程發送系統消息到子進程。
1.我註冊父方法內的消息:需要解釋的Qt 5.0方法本地事件的句法

UINT msg = RegisterWindowMessageA("my message"); 

2.In子應用程序我重寫方法nativeEvent。
我在Qt助手中找到了該方法的語法,但提供的信息還不夠,因爲這裏沒有描述參數的用法。

bool MainWindow::nativeEvent(const QByteArray& eventType, void* message, 
     long* result) 
{ 
    UINT mssg = RegisterWindowMessage(L"my message"); 
    UINT recivedMssg = *static_cast<UINT*>(message); 
    if (recivedMssg == mssg) 
    { 
     *result = 0; 
     QMessageBox::information(this,"",QString::number(recivedMssg)); 
     return true; 
    } 
    return false; 
} 

我做了這個實現,但它沒有像我期望的那樣工作,我認爲void * message - 是消息的數量。
所以我的問題是:如何在nativeEvent我可以得到從父進程發送的消息?

回答

3

我還沒有玩Qt5,但我懷疑是否有任何區別。 對於Windows,你應該如下播消息:

MSG* msg = reinterpret_cast<MSG*>(message); 

其中味精是在一些Windows頭宣佈Windows特定結構(WINDOWS.H將是足夠的肯定)

+0

that's它。非常感謝你! – 2013-02-24 07:22:49

+0

我做了MSG * mssg = RegisterWindowMessage(L「my message」); MSG * msg = reinterpret_cast (message); if(msg == mssg)'但由於錯誤的投射而沒有得到它的工作。怎麼來的?謝謝 – chwi 2014-01-27 15:28:25